/usr/bin/statgrab-make-mrtg-config is in statgrab 0.91-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | #!/usr/bin/perl -w
# i-scream libstatgrab
# http://www.i-scream.org
# Copyright (C) 2000-2013 i-scream
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# $Id$
use strict;
use Getopt::Long;
my $progname = "statgrab-make-mrtg-config";
my $statgrab = "statgrab";
my $workdir = undef;
my $kib = 1024;
my $mib = $kib * $kib;
# Type 0 is plain integers.
my $KIBIBYTES = 1;
my $PERCENT = 2;
my $FLOAT = 3;
# Print an entry in the MRTG config file.
sub entry ($$$$$$$$$$) {
my ($title, $vali, $valo, $max, $ylegend, $yunit, $legendi, $legendo, $gauge, $type) = @_;
my $name = $vali;
my $options = "";
$options .= " noo" unless defined $valo;
$options .= " gauge" if $gauge;
my $sgoptions = "";
$sgoptions .= " -o -p" if $type == $PERCENT;
$sgoptions .= " -f 1000" if $type == $FLOAT;
print "\n";
print "Title[$name]: $title\n";
print "PageTop[$name]: $title\n";
print "MaxBytes[$name]: $max\n";
print "YLegend[$name]: $ylegend\n";
print "ShortLegend[$name]: $yunit\n";
print "LegendI[$name]: $legendi\n";
print "LegendO[$name]: $legendo\n" if defined $valo;
if ($type == $KIBIBYTES) {
print "kMG[$name]: Ki,Mi,Gi,Ti\n";
$sgoptions .= " -K";
}
$valo = "const.0" unless defined $valo;
print "Options[$name]:$options\n" if $options ne "";
print "Target[$name]: `$statgrab$sgoptions -m $vali $valo`\n";
}
my $package_version = '0.91';
my $package_bugreport = 'https://github.com/i-scream/libstatgrab/issues';
my $help_text = <<EOF;
Usage: $progname [OPTION]...
Generate MRTG configuration from statgrab output and write it to stdout.
--no-header Don't print MRTG global options; useful if you
want to include the output of this script in
another MRTG config file
--workdir PATH Use PATH for MRTG's WorkDir option
--statgrab PATH Specify location of statgrab binary
(default "statgrab")
--help Display this help and exit
Version $package_version - report bugs to $package_bugreport.
EOF
sub fatal ($) {
my ($message) = @_;
die "$progname: $message\n";
}
sub main () {
GetOptions('statgrab=s' => \$statgrab,
'workdir=s' => \$workdir,
'no-header' => \my $no_header,
'help' => \my $help) or die $help_text;
if ($help) {
print "$help_text";
exit 0;
}
unless ($no_header or defined $workdir) {
fatal "must specify --workdir or --no-header"
}
my %stats = ();
my %toplevel = ();
my %disks = ();
my %fss = ();
my %nets = ();
open STATGRAB, "$statgrab|" or fatal "can't run statgrab";
while (<STATGRAB>) {
chomp;
/^([^=]*) = (.*)$/ or fatal "bad line in statgrab output";
$stats{$1} = $2;
my @parts = split /\./, $1;
$toplevel{$parts[0]} = 1;
$disks{$parts[1]} = 1 if $parts[0] eq "disk";
$fss{$parts[1]} = 1 if $parts[0] eq "fs";
$nets{$parts[1]} = 1 if $parts[0] eq "net";
}
close STATGRAB;
unless ($no_header) {
print "WorkDir: $workdir\n";
print "Options[^]: growright\n";
print "WriteExpires: Yes\n";
}
if (exists $toplevel{"cpu"}) {
entry("CPU idle", "cpu.idle", undef, "100", "Idle", "%", "idle", undef, 1, $PERCENT);
entry("CPU iowait", "cpu.iowait", undef, "100", "iowait", "%", "iowait", undef, 1, $PERCENT);
entry("CPU kernel", "cpu.kernel", undef, "100", "Kernel", "%", "kernel", undef, 1, $PERCENT);
entry("CPU nice", "cpu.nice", undef, "100", "Nice", "%", "nice", undef, 1, $PERCENT);
entry("CPU swap", "cpu.swap", undef, "100", "Swap", "%", "swap", undef, 1, $PERCENT);
entry("CPU user", "cpu.user", undef, "100", "User", "%", "user", undef, 1, $PERCENT);
}
foreach my $disk (sort keys %disks) {
my $name = $stats{"disk.$disk.disk_name"};
entry("Disk $name IO", "disk.$disk.read_bytes", "disk.$disk.write_bytes", 100*$mib, "IO rate", "KiB/s", "read", "write", 0, $KIBIBYTES);
}
foreach my $fs (sort keys %fss) {
my $name = $stats{"fs.$fs.mnt_point"};
my $size = $stats{"fs.$fs.size"};
my $inodes = $stats{"fs.$fs.total_inodes"};
entry("Filesystem $name space usage", "fs.$fs.used", undef, $size, "Space used", "KiB", "used", undef, 1, $KIBIBYTES);
entry("Filesystem $name inode usage", "fs.$fs.used_inodes", undef, $inodes, "Inodes used", "inodes", "used", undef, 1, 0);
}
if (exists $toplevel{"load"}) {
entry("Load average over 1 minute", "load.min1", undef, 100, "Load average", "running * 1000", "load", undef, 1, $FLOAT);
entry("Load average over 5 minutes", "load.min5", undef, 100, "Load average", "running * 1000", "load", undef, 1, $FLOAT);
entry("Load average over 15 minutes", "load.min15", undef, 100, "Load average", "running * 1000", "load", undef, 1, $FLOAT);
}
if (exists $toplevel{"mem"}) {
my $total = $stats{"mem.total"};
entry("Memory usage", "mem.used", "mem.cache", $total, "Memory usage", "KiB", "total", "cache", 1, $KIBIBYTES);
}
foreach my $net (sort keys %nets) {
my $name = $stats{"net.$net.interface_name"};
my $speed = int($stats{"net.$net.speed"});
$speed = 100 if $speed == 0;
# The speed is reported in Mbit/s; we want KiB/s.
$speed = int(($speed * 1000000) / (8 * $kib));
entry("Network interface $name IO", "net.$net.rx", "net.$net.tx", $speed, "Network IO", "KiB/s", "rx", "tx", 0, $KIBIBYTES);
}
if (exists $toplevel{"page"}) {
# FIXME what's a sensible maximum?
entry("Paging IO", "page.in", "page.out", 1000, "Paging IO", "pages", "in", "out", 0, 0);
}
if (exists $toplevel{"proc"}) {
# FIXME mildly silly assumption
my $maxproc = 65536;
entry("Processes running", "proc.running", undef, $maxproc, "Running", "procs", "running", undef, 1, 0);
entry("Processes sleeping", "proc.sleeping", undef, $maxproc, "Sleeping", "procs", "running", undef, 1, 0);
entry("Processes stopped", "proc.stopped", undef, $maxproc, "Stopped", "procs", "running", undef, 1, 0);
entry("Processes", "proc.total", undef, $maxproc, "Total", "procs", "running", undef, 1, 0);
entry("Processes zombie", "proc.zombie", undef, $maxproc, "Zombie", "procs", "running", undef, 1, 0);
}
if (exists $toplevel{"swap"}) {
my $swapsize = $stats{"swap.total"};
if ($swapsize ne "0") {
entry("Swap usage", "swap.used", undef, $swapsize, "Swap usage", "KiB", "used", undef, 1, $KIBIBYTES);
}
}
if (exists $toplevel{"user"}) {
entry("Users", "user.num", undef, 1000, "Users", "users", "users", undef, 1, 0);
}
}
main();
|