#! @PREFIX@/bin/perl # $NetBSD: sys2mrtg,v 1.3 2001/06/19 12:32:18 hubertf Exp $ if (@ARGV < 1) { goto usage; } $cmd = @ARGV[0]; if ($cmd eq phys) { &vmstat("pages active", "pages free", "bytes per page"); } if ($cmd eq swap) { &vmstat("swap pages in use", "", "bytes per page"); } if ($cmd eq pages) { &vmstat("pagein requests", "pageout requests"); } if ($cmd eq forks) { &vmstat("forks total"); } if ($cmd eq disks) { if (@ARGV < 2) { $diskname = "Total" } else { $diskname = @ARGV[1]; } $total = 0; open(CMDOUT, "iostat -xI|"); while () { chop $_; if (m|^(\w+)[\t\s]+[\d\.]+[\t\s]+[\d\.]+[\t\s]+[\d\.]+[\t\s]+([\d\.]+)|) { if ($1 eq $diskname) { $val = $2 * 1000; print "$val\n"; print "0\n"; &uptime; print "$diskname\n"; exit(0); } $total = $total + $2 * 1000; } } print "$total\n"; print "0\n"; &end; } if ($cmd eq irq) { if (@ARGV < 2) { $irqname = "Total" } else { $irqname = @ARGV[1]; } open(CMDOUT, "vmstat -i|"); while () { chop $_; if (m|^(\w+)[\t\s]+(-?\d+)|) { $val = $2; if ($val < 0) { $val = 0; } if ($1 eq $irqname) { print "$val\n"; } } } print "0\n"; if (@ARGV < 2) { &end; } else { &uptime; print "$irqname\n"; } } if ($cmd eq load) { open(UP, "uptime|"); while($line = ) { chop $line; if ($line =~ m|^.*up\s+(.+),\s+\d+\suser.*load averages:[\s\t]+([\d\.]+),[\s\t]+[\d\.]+,[\s\t]+[\d\.]+$|) { printf("%d\n", $2 * 100); print "0\n"; print "$1\n"; } } close(UP); open(HOST, "hostname -s|"); while () { print $_; } close(HOST); exit(0); } &usage(); sub usage { print STDERR "usage: sys2mrtg (phys|swap|pages|irq [name]|forks|disks[name])|load\n"; exit(1); } sub vmstat { local($f1, $f2,$fmult) = @_; $mult=1; $val1=0; $val2=0; open(CMDOUT, "vmstat -s|"); while () { chop $_; if (m|(\d+)[\t\s]+(.+)|) { $val = $1; $field = $2; if ($field eq $fmult) { $mult = $val; } if ($field eq $f1) { $val1 = $val * $mult; } if ($field eq $f2) { $val2 = $val * $mult; } } } print "$val1\n"; print "$val2\n"; &end; } sub uptime { open(UP, "uptime|"); while($line = ) { chop $line; if ($line =~ m|^.*up\s+(.+),\s+\d+\suser.*|) { print "$1\n"; } } close(UP); } sub end { &uptime; open(HOST, "hostname -s|"); while () { print $_; } exit(0); }