FreeBSD Monitoring
Moderators: Developers, Moderators
alternative way to get meminfo
Just installed Cacti,
-----------------------------------------------------
#!/usr/bin/perl
@top = `top`;
$line = 3;
$line = 4 if ($ARGV[0] =~ s/Swap//);
$top[$line] =~ /(\d+)\w $ARGV[0]/;
print $1;
------------------------------------------------------
seems to work ok for the meminfo, need to change the 'grep' params in cacti config.
Could probably do it better but I didn't redirect std err in the cron job so it was emailing me every 5 minutes :)
-----------------------------------------------------
#!/usr/bin/perl
@top = `top`;
$line = 3;
$line = 4 if ($ARGV[0] =~ s/Swap//);
$top[$line] =~ /(\d+)\w $ARGV[0]/;
print $1;
------------------------------------------------------
seems to work ok for the meminfo, need to change the 'grep' params in cacti config.
Could probably do it better but I didn't redirect std err in the cron job so it was emailing me every 5 minutes :)
Seems ping needs -c arg before IP address in BSD.. swap the args in the code or the config.. to swap in the code (which seems to be the logical 0,1 progression)
<cacti>/scripts/ping.pl
------------------------------------------------------
#!/usr/bin/perl
if ($ARGV[0]=="x") {
$db = ":0";
$ARGV[0] = 2;
}
$response = `ping -c $ARGV[0] $ARGV[1] |grep round-trip| awk '\{print \$4 \}' | aw
k -F / '\{print \$1 \}' | grep -v "Warning"`;
chomp $response;
$response = $response;
print "$response$db";
------------------------------------------------------
Had to change the webhits access log path in the DB as well. There is a default value in webhits.pl if eq "", which you can change as well.
HTH
-=Chainey
<cacti>/scripts/ping.pl
------------------------------------------------------
#!/usr/bin/perl
if ($ARGV[0]=="x") {
$db = ":0";
$ARGV[0] = 2;
}
$response = `ping -c $ARGV[0] $ARGV[1] |grep round-trip| awk '\{print \$4 \}' | aw
k -F / '\{print \$1 \}' | grep -v "Warning"`;
chomp $response;
$response = $response;
print "$response$db";
------------------------------------------------------
Had to change the webhits access log path in the DB as well. There is a default value in webhits.pl if eq "", which you can change as well.
HTH
-=Chainey
here is my FreeBSD script i wrote. It does req Linux emulation. (Just install the linux_base, i beleave linux_base-7.1_2 is the latest. Then just add "linprocfs /compat/linux/proc linprocfs rw 0 0" to your /etc/fstab file)
here is the script, i tried to make it editable as much as possible to work across most platforms. So it should be easy for any avg joe to set up.
http://www.degodehjelperne.no/~ross/fbsd-stats.txt
Yo rex shoot me a mail at evilk@ozline.net and i'll give yea an account on my box.
ross
here is the script, i tried to make it editable as much as possible to work across most platforms. So it should be easy for any avg joe to set up.
http://www.degodehjelperne.no/~ross/fbsd-stats.txt
Yo rex shoot me a mail at evilk@ozline.net and i'll give yea an account on my box.
ross
-
- Posts: 35
- Joined: Sat Apr 13, 2002 5:16 pm
- Location: Santa Barbara, CA
Here's a few more:raX wrote:Oooh very nice scripts being accumulated here. I will have to include them in a future cacti release along with the other scripts I have been receiving lately (thanks!).
-Ian
my rewrite of loadavg.pl (only need the one script, not _multi also), and all perl except for uptime call...)
Code: Select all
#!/usr/bin/perl
# get load uptimes for 1;5;15 min
# usage: loadavg.pl 1|5|15|all|debug
chomp($uptime = qx(uptime));
$uptime_raw = $uptime;
$uptime =~ s/.*:\s+|,//g;
@uptime = split(/\s+/,$uptime);
for ($ARGV[0]) {
/^1$/ && print $uptime[0];
/^5/ && print $uptime[1];
/^15/ && print $uptime[2];
/all/ && print $uptime;
/debug/ && do { print "UPTIME: $uptime_raw\n",
"5MIN: $uptime[0]\n",
"15MIN: $uptime[1]\n",
"30MIN: $uptime[2]\n"; };
}
exit 0;
Code: Select all
#!/usr/bin/perl
# reads in apache (or any) logfile and returns either 0 or number of lines
$lines = 0;
unless ($ARGV[0]) {
$log_path = '/var/log/httpd/access_log';
} else {
$log_path = $ARGV[0];
}
if (-r $log_path) {
open(LOG_PATH,$log_path);
while (<LOG_PATH>) {
$lines++;
}
close(LOG_PATH);
}
print $lines;
Code: Select all
#!/usr/bin/perl
# returns number of open processes from 'ps' output
open(PROCS,'/bin/ps ax |');
while (<PROCS>) {
$procs++;
}
close(PROCS);
$procs--;
print $procs;
Code: Select all
#!/usr/bin/perl
if (-r '/proc/meminfo') {
$procfile = '/proc/meminfo';
} elsif (-r '/compat/linux/proc/meminfo') {
# FreeBSD Linux emulation
$procfile = '/compat/linux/proc/meminfo';
} else {
# this only works for Linux or FreeBSD (with linux emulation)
exit(1);
}
open(PROCFILE,$procfile);
while (<PROCFILE>) {
chomp();
if (/^$ARGV[0]/) {
s/^$ARGV[0]:?\s+(\d+).*/$1/g;
print;
last;
}
}
close(PROCINFO);
I'll have more soon. Just returning some of the love...
-gwynnebaer
Who is online
Users browsing this forum: No registered users and 0 guests