Memory / swap usage

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply

Is this useful or not?

yes
3
50%
no
3
50%
 
Total votes: 6

Spider.007
Posts: 1
Joined: Sun Sep 28, 2003 7:48 am

Memory / swap usage

Post by Spider.007 »

Normally the Linux memory script uses /proc/meminfo to display free memory. I think this sucks ;) since the information might better be retrieved from the command "free". Therefore I've learned perl and wrote this:

Code: Select all

#!/usr/bin/perl

# Script by Spider.007 to display used memory (from `free`) instead of free memory (from meminfo)
# Change \$3 into \$4 to display free instead of used memory

if ($ARGV[0] eq "swap"){ $c = "tail"; }
if ($ARGV[0] eq "mem"){ $c = "head"; }

$mem = `free |tail -n 2 | $c -n 1| awk '{print \$3}'`;
$mem =~ s/(.*[0-9])//;

print $1;
To use it you have to update your datatemplates:

Linux - Memory - Free; change Grep String from MemFree: to mem
Linux - Memory - Free Swap; change Grep String from SwapFree: to swap
yid
Cacti User
Posts: 83
Joined: Sat Apr 20, 2002 8:26 pm

Post by yid »

Why do you think using free is better than reading the info from /proc? free just reads and parses the information in /proc the same way vmstat, top, and ps do.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests