summaryrefslogtreecommitdiff
path: root/net/mrtg/files/sys2mrtg
diff options
context:
space:
mode:
Diffstat (limited to 'net/mrtg/files/sys2mrtg')
-rw-r--r--net/mrtg/files/sys2mrtg185
1 files changed, 185 insertions, 0 deletions
diff --git a/net/mrtg/files/sys2mrtg b/net/mrtg/files/sys2mrtg
new file mode 100644
index 00000000000..46776492f56
--- /dev/null
+++ b/net/mrtg/files/sys2mrtg
@@ -0,0 +1,185 @@
+#! @PREFIX@/bin/perl
+
+
+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 (<CMDOUT>)
+ {
+ 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 (<CMDOUT>)
+ {
+ chop $_;
+ if (m|^(\w+)[\t\s]+(\d+)|)
+ {
+ if ($1 eq $irqname)
+ {
+ print "$2\n";
+ }
+ }
+ }
+ print "0\n";
+ if (@ARGV < 2)
+ {
+ &end;
+ }
+ else
+ {
+ &uptime;
+ print "$irqname\n";
+ }
+}
+
+if ($cmd eq load)
+{
+ open(UP, "uptime|");
+ while($line = <UP>)
+ {
+ 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 (<HOST>)
+ {
+ 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 (<CMDOUT>)
+ {
+ 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 = <UP>)
+ {
+ chop $line;
+ if ($line =~ m|^.*up\s+(.+),\s+\d+\suser.*|)
+ {
+ print "$1\n";
+ }
+ }
+ close(UP);
+}
+
+
+sub end
+{
+ &uptime;
+ open(HOST, "hostname -s|");
+ while (<HOST>)
+ {
+ print $_;
+ }
+ exit(0);
+}