summaryrefslogtreecommitdiff
path: root/net/mrtg/files/sys2mrtg
diff options
context:
space:
mode:
authorbouyer <bouyer@pkgsrc.org>1999-05-18 14:16:53 +0000
committerbouyer <bouyer@pkgsrc.org>1999-05-18 14:16:53 +0000
commit147ae6dd80e19bbb1c246ab801b385d560877754 (patch)
treec750f54e0c3a2944a4c284b7990752e5f807b0a3 /net/mrtg/files/sys2mrtg
parent27933be85cc0adfa2fd072e15ce4de74c771fe0c (diff)
downloadpkgsrc-147ae6dd80e19bbb1c246ab801b385d560877754.tar.gz
Add 2 perl scripts to collect datas on a NetBSD 1.4 system from netstat,
iostat, systat and a sample config file to use these. Also update the MESSAGE to stats there is a sample config file. Result can be seen at http://www.antioche.eu.org/mrtg/.
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);
+}