Initial commit

This commit is contained in:
Olaf Rempel 2006-02-04 16:04:08 +01:00
commit 82a0f938d4
5 changed files with 1448 additions and 0 deletions

110
monitoring.php Executable file
View File

@ -0,0 +1,110 @@
#!/usr/bin/php
<?php
define('RRDTOOL', '/usr/bin/rrdtool');
define('RRDPATH', '/home/httpd/rrd');
define('RRDMOD', 0640);
define('RRDGRP', 'httpd');
require_once("/etc/rrdtool/stat.class.php");
require_once("/etc/rrdtool/rrd.class.php");
function get_all() {
$arr['cpu'] = stat::get_cpu();
$arr['sys'] = stat::get_sys();
$arr['load'] = stat::get_load();
$arr['mem'] = stat::get_mem();
$arr['up'] = stat::get_uptime();
$arr['iface'] = stat::get_interfaces();
$arr['disks'] = stat::get_disks();
$arr['mysql'] = stat::get_mysql('localhost', 'status', '');
$arr['httpd'] = stat::get_httpd('http://127.0.0.1/server-status?auto');
$arr['named'] = stat::get_named('/var/lib/named/chroot/var/run/named/named.stats');
$arr['squid'] = stat::get_squid('localhost:3401', 'public');
$arr['conntrack'] = stat::get_conntrack();
$arr['rtstat'] = stat::get_netstat('/proc/net/stat/rt_cache');
$arr['ctstat'] = stat::get_netstat('/proc/net/stat/ip_conntrack');
return $arr;
}
function parse_all($arr) {
foreach ($arr['cpu'] as $name => $cpu)
if ($name != 'cpu')
CpuRRD::update($name, $cpu);
ProcRRD::update("proc", $arr['sys']);
LavgRRD::update("load", $arr['load']);
MemRRD::update("mem", $arr['mem'][0]);
SwapRRD::update("swap", $arr['mem'][1]);
UpRRD::update('uptime', $arr['up']);
foreach ($arr['iface'] as $name => $iface)
IfaceRRD::update("if_".$name, $iface[0], $iface[1]);
foreach ($arr['disks'] as $name => $disk) {
FsRRD::update('fs_'.$name, $disk);
DiskRRD::update('disk_'.$name, $disk[3]);
}
if (isset($arr['mysql']))
MysqlRRD::update("mysql", $arr['mysql']);
if (isset($arr['httpd']))
HttpdRRD::update("httpd", $arr['httpd']);
if (isset($arr['named']))
NamedRRD::update("named", $arr['named']);
if (isset($arr['squid']))
SquidRRD::update("squid", $arr['squid']);
if (isset($arr['conntrack'])) {
ConntrackRRD::update("conntrack", $arr['conntrack']);
TcpRRD::update("tcp", $arr['conntrack']['stat']);
}
if (isset($arr['rtstat']))
RtStatRRD::update("rtstat", $arr['rtstat']);
if (isset($arr['ctstat']))
CtStatRRD::update("ctstat", $arr['ctstat']);
}
function request_all($host, $port) {
$handle = fsockopen($host, $port, $errno, $errstr, 10);
if (!$handle) {
echo "$errstr ($errno)";
die();
}
$buffer = "";
while (!feof($handle))
$buffer .= fgets($handle, 4096);
fclose($handle);
return unserialize(trim($buffer));
}
if (!isset($_SERVER['argv'][1]))
$_SERVER['argv'][1] = "local";
switch ($_SERVER['argv'][1]) {
case 'local': parse_all(get_all());
break;
case 'server': echo serialize(get_all())."\n";
break;
case 'client': if (!isset($_SERVER['argv'][2]) || !isset($_SERVER['argv'][3]))
break;
parse_all(request_all($_SERVER['argv'][2], $_SERVER['argv'][3]));
break;
case 'test': print_r(get_all());
break;
}
?>

848
rrd.class.php Normal file
View File

@ -0,0 +1,848 @@
<?php
// 6h(1min), 2d(5min), 2w(30min), 2m(2h), 2Y(24h)
define('RRAAVG', 'RRA:AVERAGE:0.5:1:360 RRA:AVERAGE:0.5:5:288 RRA:AVERAGE:0.5:30:336 RRA:AVERAGE:0.5:120:336 RRA:AVERAGE:0.5:576:365 ');
define('RRAMAX', 'RRA:MAX:0.5:1:360 RRA:MAX:0.5:5:288 RRA:MAX:0.5:30:336 RRA:MAX:0.5:120:336 RRA:MAX:0.5:576:365 ');
define('RRAMIN', 'RRA:MIN:0.5:1:360 RRA:MIN:0.5:5:288 RRA:MIN:0.5:30:336 RRA:MIN:0.5:120:336 RRA:MIN:0.5:576:365 ');
class CpuRRD {
function update($name, $data) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:user:DERIVE:120:0:U ".
"DS:nice:DERIVE:120:0:U ".
"DS:system:DERIVE:120:0:U ".
"DS:idle:DERIVE:120:0:U ".
"DS:iowait:DERIVE:120:0:U ".
"DS:irq:DERIVE:120:0:U ".
"DS:softirq:DERIVE:120:0:U ".
"DS:overall:DERIVE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$data[0]}:{$data[1]}:{$data[2]}:{$data[3]}:{$data[4]}:{$data[5]}:{$data[6]}:".
($data[0]+$data[1]+$data[2]+$data[4]+$data[5]+$data[6]));
}
function graph($name, $start, $mode, $title) {
header('Content-type: image/x-png');
if ($mode) {
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max --lower-limit=0 '.
'--vertical-label="percent" '.
"DEF:a=".RRDPATH."/{$name}.rrd:user:AVERAGE ".
"DEF:b=".RRDPATH."/{$name}.rrd:nice:AVERAGE ".
"DEF:c=".RRDPATH."/{$name}.rrd:system:AVERAGE ".
"DEF:d=".RRDPATH."/{$name}.rrd:idle:AVERAGE ".
"DEF:e=".RRDPATH."/{$name}.rrd:iowait:AVERAGE ".
"DEF:f=".RRDPATH."/{$name}.rrd:irq:AVERAGE ".
"DEF:g=".RRDPATH."/{$name}.rrd:softirq:AVERAGE ".
'AREA:c#FF0000:"System " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:f#EA8F00:"IRQ " GPRINT:f:LAST:"Current\:%8.2lf %s" GPRINT:f:AVERAGE:"Average\:%8.2lf %s" GPRINT:f:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:g#FFFF00:"Soft-IRQ" GPRINT:g:LAST:"Current\:%8.2lf %s" GPRINT:g:AVERAGE:"Average\:%8.2lf %s" GPRINT:g:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:e#0000FF:"IO-Wait " GPRINT:e:LAST:"Current\:%8.2lf %s" GPRINT:e:AVERAGE:"Average\:%8.2lf %s" GPRINT:e:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:a#00CFCF:"User " GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:b#00CF00:"Nice " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" '.
'');
} else {
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max --lower-limit=0 '.
'--vertical-label="percent" '.
"DEF:xmin=".RRDPATH."/{$name}.rrd:overall:MIN ".
"DEF:xavg=".RRDPATH."/{$name}.rrd:overall:AVERAGE ".
"DEF:xmax=".RRDPATH."/{$name}.rrd:overall:MAX ".
'CDEF:xmid=xmax,xmin,- '.
'AREA:xmin STACK:xmid#C0C0FF:"min/max CPU" GPRINT:xmin:MIN:"%6.2lf%s" GPRINT:xmax:MAX:"%6.2lf%s" '.
'LINE1:xmin#a0a0a0 LINE1:xmax#a0a0a0 LINE1:xavg#000080:"avg CPU" '.
'GPRINT:xavg:MIN:"min\: %6.2lf%s" GPRINT:xavg:AVERAGE:"avg\: %6.2lf%s" GPRINT:xavg:MAX:"max\: %6.2lf%s\n" ');
}
}
}
class ProcRRD {
function update($name, $proc) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:intr:DERIVE:120:0:U ".
"DS:ctxt:DERIVE:120:0:U ".
"DS:pgfaults:DERIVE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$proc[0]}:{$proc[1]}:{$proc[2]}");
}
function graph($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=120 --width=800 --alt-autoscale-max --lower-limit=0 '.
'--vertical-label="per second" '.
"DEF:a=".RRDPATH."/{$name}.rrd:intr:AVERAGE ".
"DEF:b=".RRDPATH."/{$name}.rrd:ctxt:AVERAGE ".
"DEF:c=".RRDPATH."/{$name}.rrd:pgfaults:AVERAGE ".
'AREA:b#00AF00:"Context " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:a#FF0000:"Interrupts" GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:c#0000FF:"Pagefaults" GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'');
}
}
class LavgRRD {
function update($name, $load) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:1min:GAUGE:120:0:U ".
"DS:5min:GAUGE:120:0:U ".
"DS:15min:GAUGE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$load[0]}:{$load[1]}:{$load[2]}");
}
function graph($name, $start, $mode, $title) {
header('Content-type: image/x-png');
if ($mode) {
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=120 --width=800 --alt-autoscale-max --lower-limit=0 '.
'--vertical-label="load" '.
"DEF:a=".RRDPATH."/{$name}.rrd:1min:AVERAGE ".
"DEF:b=".RRDPATH."/{$name}.rrd:5min:AVERAGE ".
"DEF:c=".RRDPATH."/{$name}.rrd:15min:AVERAGE ".
'CDEF:x=a,b,c,MAX,MAX '.
'AREA:a#EACC00:"1 Minute Average " GPRINT:a:LAST:"Current\:%8.2lf %s\n" '.
'AREA:b#EA8F00:"5 Minute Average " GPRINT:b:LAST:"Current\:%8.2lf %s\n" '.
'AREA:c#FF0000:"15 Minute Average" GPRINT:c:LAST:"Current\:%8.2lf %s\n" '.
'LINE1:x#000000:"Total"');
} else {
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=120 --width=800 --alt-autoscale-max --lower-limit=0 '.
'--vertical-label="load" '.
"DEF:lmin=".RRDPATH."/{$name}.rrd:1min:MIN ".
"DEF:lavg=".RRDPATH."/{$name}.rrd:1min:AVERAGE ".
"DEF:lmax=".RRDPATH."/{$name}.rrd:1min:MAX ".
'CDEF:lmid=lmax,lmin,- '.
'AREA:lmin STACK:lmid#FFA0A0:"min/max Load " GPRINT:lmin:MIN:"%6.2lf%s" GPRINT:lmax:MAX:"%6.2lf%s" '.
'LINE1:lmin#a0a0a0 LINE1:lmax#a0a0a0 LINE1:lavg#FF0000:"avg Load " '.
'GPRINT:lavg:MIN:"min\: %6.2lf%s" GPRINT:lavg:AVERAGE:"avg\: %6.2lf%s" GPRINT:lavg:MAX:"max\: %6.2lf%s\n" '.
'');
}
}
}
class MemRRD {
function update($name, $mem) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:total:GAUGE:120:0:U ".
"DS:free:GAUGE:120:0:U ".
"DS:buffer:GAUGE:120:0:U ".
"DS:cache:GAUGE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$mem[0]}:{$mem[1]}:{$mem[2]}:{$mem[3]}");
}
function graph($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1024 --height=120 --width=800 --alt-autoscale-max --lower-limit=0 '.
'--vertical-label="kB" '.
"DEF:aa=".RRDPATH."/{$name}.rrd:total:AVERAGE ".
"DEF:bb=".RRDPATH."/{$name}.rrd:free:AVERAGE ".
"DEF:cc=".RRDPATH."/{$name}.rrd:buffer:AVERAGE ".
"DEF:dd=".RRDPATH."/{$name}.rrd:cache:AVERAGE ".
'CDEF:a=aa,1024,* '.
'CDEF:b=bb,1024,* '.
'CDEF:c=cc,1024,* '.
'CDEF:d=dd,1024,* '.
'CDEF:x=aa,bb,cc,dd,+,+,-,1024,* '.
'LINE1:a#000000:"Total Memory " GPRINT:a:LAST:"Current\:%8.2lf %s\n" '.
'AREA:x#FF0000:"Used Memory " GPRINT:x:LAST:"Current\:%8.2lf %s" GPRINT:x:AVERAGE:"Average\:%8.2lf %s" GPRINT:x:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:c#FF7D00:"Buffer Memory " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:d#FFC73B:"Cache Memory " GPRINT:d:LAST:"Current\:%8.2lf %s" GPRINT:d:AVERAGE:"Average\:%8.2lf %s" GPRINT:d:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:b#00CF00:"Free Memory " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" ');
}
}
class SwapRRD {
function update($name, $swap) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:total:GAUGE:120:0:U ".
"DS:free:GAUGE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$swap[0]}:{$swap[1]}");
}
function graph($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1024 --height=120 --width=800 --alt-autoscale-max --lower-limit=0 '.
'--vertical-label="kB" '.
"DEF:aa=".RRDPATH."/{$name}.rrd:total:AVERAGE ".
"DEF:bb=".RRDPATH."/{$name}.rrd:free:AVERAGE ".
'CDEF:a=aa,1024,* '.
'CDEF:b=bb,1024,* '.
'CDEF:x=aa,bb,-,1024,* '.
'LINE1:a#000000:"Total Swap " GPRINT:a:LAST:"Current\:%8.2lf %s\n" '.
'AREA:x#FF0000:"Used Swap " GPRINT:x:LAST:"Current\:%8.2lf %s" GPRINT:x:AVERAGE:"Average\:%8.2lf %s" GPRINT:x:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:b#00CF00:"Free Swap " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" ');
}
}
class IfaceRRD {
function update($name, $rx, $tx) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:traffic-in:DERIVE:120:0:U ".
"DS:traffic-out:DERIVE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$rx}:{$tx}");
}
function graph($name, $start, $mode, $title) {
header('Content-type: image/x-png');
// "normal mode"
if ($mode) {
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="bytes per second" '.
"DEF:iavg=".RRDPATH."/{$name}.rrd:traffic-in:AVERAGE ".
"DEF:oavg=".RRDPATH."/{$name}.rrd:traffic-out:AVERAGE ".
'CDEF:oavgn=oavg,-1,* '.
'HRULE:0#FF0000 '.
'AREA:iavg#A0FFA0 LINE1:iavg#008000:"Inbound " '.
'GPRINT:iavg:LAST:"Current\:%8.2lf%s" GPRINT:iavg:AVERAGE:"Average\:%8.2lf%s" GPRINT:iavg:MAX:"Maximum\:%8.2lf%s\n" '.
'AREA:oavgn#C0C0FF LINE1:oavgn#000080:"Outbound" '.
'GPRINT:oavg:LAST:"Current\:%8.2lf%s" GPRINT:oavg:AVERAGE:"Average\:%8.2lf%s" GPRINT:oavg:MAX:"Maximum\:%8.2lf%s\n" ');
} else {
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="bytes per second" '.
"DEF:imax=".RRDPATH."/{$name}.rrd:traffic-in:MAX ".
"DEF:iavg=".RRDPATH."/{$name}.rrd:traffic-in:AVERAGE ".
"DEF:imin=".RRDPATH."/{$name}.rrd:traffic-in:MIN ".
"DEF:omax=".RRDPATH."/{$name}.rrd:traffic-out:MAX ".
"DEF:oavg=".RRDPATH."/{$name}.rrd:traffic-out:AVERAGE ".
"DEF:omin=".RRDPATH."/{$name}.rrd:traffic-out:MIN ".
'CDEF:omaxn=omax,-1,* CDEF:oavgn=oavg,-1,* CDEF:ominn=omin,-1,* '.
'CDEF:imid=imax,imin,- CDEF:omid=omaxn,ominn,- '.
'HRULE:0#FF0000 '.
'AREA:imin STACK:imid#A0FFA0:"min/max Inbound " GPRINT:imin:MIN:"%6.2lf%s" GPRINT:imax:MAX:"%6.2lf%s" '.
'LINE1:imin#a0a0a0 LINE1:imax#a0a0a0 LINE1:iavg#008000:"avg Inbound " '.
'GPRINT:iavg:MIN:"min\: %6.2lf%s" GPRINT:iavg:AVERAGE:"avg\: %6.2lf%s" GPRINT:iavg:MAX:"max\: %6.2lf%s\n" '.
'AREA:ominn STACK:omid#C0C0FF:"min/max Outbound" GPRINT:omin:MIN:"%6.2lf%s" GPRINT:omax:MAX:"%6.2lf%s" '.
'LINE1:ominn#a0a0a0 LINE1:omaxn#a0a0a0 LINE1:oavgn#000080:"avg Outbound" '.
'GPRINT:oavg:MIN:"min\: %6.2lf%s" GPRINT:oavg:AVERAGE:"avg\: %6.2lf%s" GPRINT:oavg:MAX:"max\: %6.2lf%s\n" ');
}
}
}
class FsRRD {
function update($name, $fs) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:total:GAUGE:120:0:U ".
"DS:used:GAUGE:120:0:U ".
"DS:free:GAUGE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$fs[0]}:{$fs[1]}:{$fs[2]}");
}
function graph($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1024 --height=120 --width=800 --alt-autoscale-max --lower-limit=0 '.
'--vertical-label="kB" '.
"DEF:aa=".RRDPATH."/{$name}.rrd:total:AVERAGE ".
"DEF:bb=".RRDPATH."/{$name}.rrd:used:AVERAGE ".
"DEF:cc=".RRDPATH."/{$name}.rrd:free:AVERAGE ".
'CDEF:a=aa,1024,* '.
'CDEF:b=bb,1024,* '.
'CDEF:c=cc,1024,* '.
'LINE1:a#000000:"Total " GPRINT:a:LAST:"Current\:%8.2lf %s\n" '.
'AREA:b#FF0000:"Used " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:c#00CF00:"Free " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" ');
}
}
class MysqlRRD {
function update($name, $mysql) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:querys:DERIVE:120:0:U ".
"DS:connections:GAUGE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$mysql[0]}:{$mysql[1]}");
}
function graph($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=120 --width=800 --alt-autoscale-max --lower-limit=0 '.
'--vertical-label="querys per second" '.
"DEF:a=".RRDPATH."/{$name}.rrd:querys:AVERAGE ".
"DEF:b=".RRDPATH."/{$name}.rrd:connections:AVERAGE ".
'AREA:b#00CF00:"Connections " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:a#002A97:"Querys " GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" ');
}
}
class HttpdRRD {
function update($name, $httpd) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:requests:DERIVE:120:0:U ".
"DS:traffic:DERIVE:120:0:U ".
"DS:busyworkers:GAUGE:120:0:U ".
"DS:idleworkers:GAUGE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$httpd[0]}:{$httpd[1]}:{$httpd[2]}:{$httpd[3]}");
}
function graph($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=120 --width=800 --alt-autoscale-max --lower-limit=0 '.
'--vertical-label="querys per second" '.
"DEF:a=".RRDPATH."/{$name}.rrd:requests:AVERAGE ".
"DEF:b=".RRDPATH."/{$name}.rrd:traffic:AVERAGE ".
"DEF:c=".RRDPATH."/{$name}.rrd:busyworkers:AVERAGE ".
"DEF:d=".RRDPATH."/{$name}.rrd:idleworkers:AVERAGE ".
'AREA:d#00CF00:"Idle Workers " GPRINT:d:LAST:"Current\:%8.2lf %s" GPRINT:d:AVERAGE:"Average\:%8.2lf %s" GPRINT:d:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:c#FF0000:"Busy Workers " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:a#002A97:"Requests " GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" ');
}
}
class NamedRRD {
function update($name, $named) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:success:DERIVE:120:0:U ".
"DS:referral:DERIVE:120:0:U ".
"DS:nxrrset:DERIVE:120:0:U ".
"DS:nxdomain:DERIVE:120:0:U ".
"DS:recursion:DERIVE:120:0:U ".
"DS:failure:DERIVE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$named[0]}:{$named[1]}:{$named[2]}:{$named[3]}:{$named[4]}:{$named[5]}");
}
function graph($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="querys per minute" '.
"DEF:a=".RRDPATH."/{$name}.rrd:success:AVERAGE ".
"DEF:b=".RRDPATH."/{$name}.rrd:referral:AVERAGE ".
"DEF:c=".RRDPATH."/{$name}.rrd:nxrrset:AVERAGE ".
"DEF:d=".RRDPATH."/{$name}.rrd:nxdomain:AVERAGE ".
"DEF:e=".RRDPATH."/{$name}.rrd:recursion:AVERAGE ".
"DEF:f=".RRDPATH."/{$name}.rrd:failure:AVERAGE ".
'CDEF:nc=c,-1,* '.
'CDEF:nd=d,-1,* '.
'CDEF:nf=f,-1,* '.
'AREA:a#00CF00:"success " GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" '.
'AREA:b#00FFFF:"referral " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:e#0000FF:"recursion " GPRINT:e:LAST:"Current\:%8.2lf %s" GPRINT:e:AVERAGE:"Average\:%8.2lf %s" GPRINT:e:MAX:"Maximum\:%8.2lf %s\n" '.
'HRULE:0#000000 '.
'AREA:nf#000000:"failure " GPRINT:f:LAST:"Current\:%8.2lf %s" GPRINT:f:AVERAGE:"Average\:%8.2lf %s" GPRINT:f:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:nd#FF0000:"nxdomain " GPRINT:d:LAST:"Current\:%8.2lf %s" GPRINT:d:AVERAGE:"Average\:%8.2lf %s" GPRINT:d:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:nc#EA8F00:"nxrrset " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'');
}
}
class DiskRRD {
function update($name, $disk) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:read:DERIVE:120:0:U ".
"DS:sec_rd:DERIVE:120:0:U ".
"DS:write:DERIVE:120:0:U ".
"DS:sec_wr:DERIVE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$disk[0]}:{$disk[1]}:{$disk[2]}:{$disk[3]}");
}
function graph($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="Sektors read/write" '.
"DEF:r=".RRDPATH."/{$name}.rrd:read:AVERAGE ".
"DEF:rs=".RRDPATH."/{$name}.rrd:sec_rd:AVERAGE ".
"DEF:nw=".RRDPATH."/{$name}.rrd:write:AVERAGE ".
"DEF:nws=".RRDPATH."/{$name}.rrd:sec_wr:AVERAGE ".
'CDEF:w=nw,-1,* '.
'CDEF:ws=nws,-1,* '.
'HRULE:0#FF0000 '.
'AREA:rs#A0FFA0 LINE1:rs#008000:"Read " LINE1:r#000000 '.
'GPRINT:rs:LAST:"Current\:%8.2lf%s" GPRINT:rs:AVERAGE:"Average\:%8.2lf%s" GPRINT:rs:MAX:"Maximum\:%8.2lf%s\n" '.
'AREA:ws#C0C0FF LINE1:ws#000080:"Write" LINE1:w#000000 '.
'GPRINT:nws:LAST:"Current\:%8.2lf%s" GPRINT:nws:AVERAGE:"Average\:%8.2lf%s" GPRINT:nws:MAX:"Maximum\:%8.2lf%s\n" '.
'');
}
}
class UpRRD {
function update($name, $uptime) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:uptime:GAUGE:120:0:U ".
"DS:idletime:GAUGE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$uptime[0]}:{$uptime[1]}");
}
function graph($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=120 --width=800 --alt-autoscale-max --lower-limit 0 '.
'--vertical-label="days" '.
"DEF:ups=".RRDPATH."/{$name}.rrd:uptime:AVERAGE ".
"DEF:idles=".RRDPATH."/{$name}.rrd:idletime:AVERAGE ".
'CDEF:up=ups,86400,/ '.
'CDEF:idle=idles,86400,/ '.
'AREA:up#00CF00:"Uptime " '.
'LINE1:idle#002A97:"Idletime " '.
'');
}
}
class SquidRRD {
function update($name, $sq) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:requests:DERIVE:120:0:U ".
"DS:httphits:DERIVE:120:0:U ".
"DS:httperr:DERIVE:120:0:U ".
"DS:httpin:DERIVE:120:0:U ".
"DS:httpout:DERIVE:120:0:U ".
"DS:srvreq:DERIVE:120:0:U ".
"DS:srverr:DERIVE:120:0:U ".
"DS:srvin:DERIVE:120:0:U ".
"DS:srvout:DERIVE:120:0:U ".
"DS:cachesize:GAUGE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$sq[0]}:{$sq[1]}:{$sq[2]}:{$sq[3]}:{$sq[4]}:{$sq[5]}:{$sq[6]}:{$sq[7]}:{$sq[8]}:{$sq[9]}");
}
function graph1($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="Bytes/s" '.
"DEF:dd=".RRDPATH."/{$name}.rrd:httpin:AVERAGE ".
"DEF:ee=".RRDPATH."/{$name}.rrd:httpout:AVERAGE ".
"DEF:hh=".RRDPATH."/{$name}.rrd:srvin:AVERAGE ".
"DEF:ii=".RRDPATH."/{$name}.rrd:srvout:AVERAGE ".
"DEF:jj=".RRDPATH."/{$name}.rrd:cachesize:AVERAGE ".
'CDEF:nd=dd,-1024,* '.
'CDEF:ne=ee,-1024,* '.
'CDEF:d=dd,1024,* '.
'CDEF:e=ee,1024,* '.
'CDEF:h=hh,1024,* '.
'CDEF:i=ii,1024,* '.
'CDEF:j=jj,1024,* '.
'AREA:h#A0FFA0 LINE1:h#008000:"Server IN " '.
'GPRINT:h:LAST:"Current\:%8.2lf%s" GPRINT:h:AVERAGE:"Average\:%8.2lf%s" GPRINT:h:MAX:"Maximum\:%8.2lf%s\n" '.
'AREA:i#C0C0FF LINE1:i#000080:"Server OUT" '.
'GPRINT:i:LAST:"Current\:%8.2lf%s" GPRINT:i:AVERAGE:"Average\:%8.2lf%s" GPRINT:i:MAX:"Maximum\:%8.2lf%s\n" '.
'HRULE:0#FF0000:"-\n" '.
'AREA:ne#A0FFA0 LINE1:ne#008000:"Client OUT" '.
'GPRINT:e:LAST:"Current\:%8.2lf%s" GPRINT:e:AVERAGE:"Average\:%8.2lf%s" GPRINT:e:MAX:"Maximum\:%8.2lf%s\n" '.
'AREA:nd#C0C0FF LINE1:nd#000080:"Client IN " '.
'GPRINT:d:LAST:"Current\:%8.2lf%s" GPRINT:d:AVERAGE:"Average\:%8.2lf%s" GPRINT:d:MAX:"Maximum\:%8.2lf%s\n" '.
'GPRINT:j:LAST:"Current Cache Size\:%8.2lf%s" '.
'');
}
function graph2($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="kb/s" '.
"DEF:a=".RRDPATH."/{$name}.rrd:requests:AVERAGE ".
"DEF:b=".RRDPATH."/{$name}.rrd:httphits:AVERAGE ".
"DEF:f=".RRDPATH."/{$name}.rrd:srvreq:AVERAGE ".
'CDEF:na=a,-1,* '.
'AREA:f#C0C0FF LINE1:f#000080:"Server Requests " '.
'GPRINT:f:LAST:"Current\:%8.2lf%s" GPRINT:f:AVERAGE:"Average\:%8.2lf%s" GPRINT:f:MAX:"Maximum\:%8.2lf%s\n" '.
'HRULE:0#FF0000 '.
'AREA:na#A0FFA0 LINE1:na#008000:"Client Requests " '.
'GPRINT:a:LAST:"Current\:%8.2lf%s" GPRINT:a:AVERAGE:"Average\:%8.2lf%s" GPRINT:a:MAX:"Maximum\:%8.2lf%s\n" '.
'LINE1:b#FF0000:"Cache Hits " '.
'GPRINT:b:LAST:"Current\:%8.2lf%s" GPRINT:b:AVERAGE:"Average\:%8.2lf%s" GPRINT:b:MAX:"Maximum\:%8.2lf%s\n" '.
'');
}
}
class ConntrackRRD {
function update($name, $ct) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:total:GAUGE:120:0:U ".
"DS:max:GAUGE:120:0:U ".
"DS:assured:GAUGE:120:0:U ".
"DS:unreplied:GAUGE:120:0:U ".
"DS:tcp:GAUGE:120:0:U ".
"DS:udp:GAUGE:120:0:U ".
"DS:unknown:GAUGE:120:0:U ".
"DS:local:GAUGE:120:0:U ".
"DS:nated:GAUGE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$ct['total']}:{$ct['max']}:{$ct['assured']}:{$ct['unreplied']}:{$ct['tcp']}:{$ct['udp']}:{$ct['unknown']}:{$ct['local']}:{$ct['nated']}");
}
function graph1($name, $start, $mode, $title) {
// "normal mode"
if ($mode) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="Connections" '.
"DEF:tot=".RRDPATH."/{$name}.rrd:total:AVERAGE ".
"DEF:max=".RRDPATH."/{$name}.rrd:max:AVERAGE ".
"DEF:lavg=".RRDPATH."/{$name}.rrd:local:AVERAGE ".
"DEF:navg=".RRDPATH."/{$name}.rrd:nated:AVERAGE ".
'CDEF:navgn=navg,-1,* '.
'HRULE:0#FF0000 '.
'AREA:lavg#A0FFA0 LINE1:lavg#008000:"local " '.
'GPRINT:lavg:LAST:"Current\:%8.0lf" GPRINT:lavg:AVERAGE:"Average\:%8.0lf" GPRINT:lavg:MAX:"Maximum\:%8.0lf\n" '.
'AREA:navgn#C0C0FF LINE1:navgn#000080:"forwared " '.
'GPRINT:navg:LAST:"Current\:%8.0lf" GPRINT:navg:AVERAGE:"Average\:%8.0lf" GPRINT:navg:MAX:"Maximum\:%8.0lf\n" '.
'GPRINT:tot:LAST:"Used\: %8.0lf \n" GPRINT:max:LAST:"Maximum\:%8.0lf \n" '.
'');
} else {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="Connections" '.
"DEF:tot=".RRDPATH."/{$name}.rrd:total:AVERAGE ".
"DEF:max=".RRDPATH."/{$name}.rrd:max:AVERAGE ".
"DEF:lmax=".RRDPATH."/{$name}.rrd:local:MAX ".
"DEF:lavg=".RRDPATH."/{$name}.rrd:local:AVERAGE ".
"DEF:lmin=".RRDPATH."/{$name}.rrd:local:MIN ".
"DEF:nmax=".RRDPATH."/{$name}.rrd:nated:MAX ".
"DEF:navg=".RRDPATH."/{$name}.rrd:nated:AVERAGE ".
"DEF:nmin=".RRDPATH."/{$name}.rrd:nated:MIN ".
'CDEF:nmaxn=nmax,-1,* CDEF:navgn=navg,-1,* CDEF:nminn=nmin,-1,* '.
'CDEF:lmid=lmax,lmin,- CDEF:nmid=nmaxn,nminn,- '.
'HRULE:0#FF0000 '.
'AREA:lmin STACK:lmid#A0FFA0:"min/max local " GPRINT:lmin:MIN:"%6.0lf" GPRINT:lmax:MAX:"%6.0lf" '.
'LINE1:lmin#a0a0a0 LINE1:lmax#a0a0a0 LINE1:lavg#008000:"avg local " '.
'GPRINT:lavg:MIN:"min\: %6.0lf" GPRINT:lavg:AVERAGE:"avg\: %6.0lf" GPRINT:lavg:MAX:"max\: %6.0lf\n" '.
'AREA:nminn STACK:nmid#C0C0FF:"min/max forward " GPRINT:nmin:MIN:"%6.0lf" GPRINT:nmax:MAX:"%6.0lf" '.
'LINE1:nminn#a0a0a0 LINE1:nmaxn#a0a0a0 LINE1:navgn#000080:"avg forward" '.
'GPRINT:navg:MIN:"min\: %6.0lf" GPRINT:navg:AVERAGE:"avg\: %6.0lf" GPRINT:navg:MAX:"max\: %6.0lf\n" '.
'GPRINT:tot:LAST:"Used\: %8.0lf \n" GPRINT:max:LAST:"Maximum\:%8.0lf \n" '.
'');
}
}
function graph2($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="conntracks" '.
"DEF:c=".RRDPATH."/{$name}.rrd:assured:AVERAGE ".
"DEF:d=".RRDPATH."/{$name}.rrd:unreplied:AVERAGE ".
"DEF:e=".RRDPATH."/{$name}.rrd:tcp:AVERAGE ".
"DEF:f=".RRDPATH."/{$name}.rrd:udp:AVERAGE ".
"DEF:g=".RRDPATH."/{$name}.rrd:unknown:AVERAGE ".
'AREA:g#FF7D00:"proto\: unknown " GPRINT:g:LAST:"Current\:%8.0lf" GPRINT:g:AVERAGE:"Average\:%8.0lf" GPRINT:g:MAX:"Maximum\:%8.0lf\n" '.
'STACK:f#FFC73B:"proto\: udp " GPRINT:f:LAST:"Current\:%8.0lf" GPRINT:f:AVERAGE:"Average\:%8.0lf" GPRINT:f:MAX:"Maximum\:%8.0lf\n" '.
'STACK:e#00CF00:"proto\: tcp " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'LINE2:c#002A97:"[ASSURED] " GPRINT:c:LAST:"Current\:%8.0lf" GPRINT:c:AVERAGE:"Average\:%8.0lf" GPRINT:c:MAX:"Maximum\:%8.0lf\n" '.
'LINE2:d#FF0000:"[UNREPLIED] " GPRINT:d:LAST:"Current\:%8.0lf" GPRINT:d:AVERAGE:"Average\:%8.0lf" GPRINT:d:MAX:"Maximum\:%8.0lf\n" '.
'');
}
}
class TcpRRD {
function update($name, $tcp) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:none:GAUGE:120:0:U ".
"DS:synsent:GAUGE:120:0:U ".
"DS:synrecv:GAUGE:120:0:U ".
"DS:established:GAUGE:120:0:U ".
"DS:finwait:GAUGE:120:0:U ".
"DS:closewait:GAUGE:120:0:U ".
"DS:lastack:GAUGE:120:0:U ".
"DS:timewait:GAUGE:120:0:U ".
"DS:close:GAUGE:120:0:U ".
"DS:listen:GAUGE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd N:{$tcp['NONE']}:{$tcp['SYN_SENT']}:{$tcp['SYN_RECV']}:{$tcp['ESTABLISHED']}:{$tcp['FIN_WAIT']}:{$tcp['CLOSE_WAIT']}:{$tcp['LAST_ACK']}:{$tcp['TIME_WAIT']}:{$tcp['CLOSE']}:{$tcp['LISTEN']}");
}
function graph($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="conntracks" '.
"DEF:b=".RRDPATH."/{$name}.rrd:synsent:AVERAGE ".
"DEF:c=".RRDPATH."/{$name}.rrd:synrecv:AVERAGE ".
"DEF:d=".RRDPATH."/{$name}.rrd:established:AVERAGE ".
"DEF:e=".RRDPATH."/{$name}.rrd:finwait:AVERAGE ".
"DEF:f=".RRDPATH."/{$name}.rrd:closewait:AVERAGE ".
"DEF:g=".RRDPATH."/{$name}.rrd:lastack:AVERAGE ".
"DEF:h=".RRDPATH."/{$name}.rrd:timewait:AVERAGE ".
"DEF:i=".RRDPATH."/{$name}.rrd:close:AVERAGE ".
'AREA:b#FF0000:"SYN_SEND " GPRINT:b:LAST:"Current\:%8.0lf" GPRINT:b:AVERAGE:"Average\:%8.0lf" GPRINT:b:MAX:"Maximum\:%8.0lf\n" '.
'STACK:f#FF00FF:"CLOSE_WAIT " GPRINT:f:LAST:"Current\:%8.0lf" GPRINT:f:AVERAGE:"Average\:%8.0lf" GPRINT:f:MAX:"Maximum\:%8.0lf\n" '.
'STACK:g#0000FF:"LAST_ACK " GPRINT:g:LAST:"Current\:%8.0lf" GPRINT:g:AVERAGE:"Average\:%8.0lf" GPRINT:g:MAX:"Maximum\:%8.0lf\n" '.
'STACK:h#007FFF:"TIME_WAIT " GPRINT:h:LAST:"Current\:%8.0lf" GPRINT:h:AVERAGE:"Average\:%8.0lf" GPRINT:h:MAX:"Maximum\:%8.0lf\n" '.
'STACK:c#00FFFF:"SYN_RECV " GPRINT:c:LAST:"Current\:%8.0lf" GPRINT:c:AVERAGE:"Average\:%8.0lf" GPRINT:c:MAX:"Maximum\:%8.0lf\n" '.
'STACK:d#00FF00:"ESTABLISHED" GPRINT:d:LAST:"Current\:%8.0lf" GPRINT:d:AVERAGE:"Average\:%8.0lf" GPRINT:d:MAX:"Maximum\:%8.0lf\n" '.
'STACK:e#FFFF00:"FIN_WAIT " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'STACK:i#FF7F00:"CLOSE " GPRINT:i:LAST:"Current\:%8.0lf" GPRINT:i:AVERAGE:"Average\:%8.0lf" GPRINT:i:MAX:"Maximum\:%8.0lf\n" '.
'');
}
}
class RtStatRRD {
function update($name, $data) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:entries:GAUGE:120:0:U ".
"DS:in_hit:DERIVE:120:0:U ".
"DS:in_slow_tot:DERIVE:120:0:U ".
"DS:in_slow_mc:DERIVE:120:0:U ".
"DS:in_no_route:DERIVE:120:0:U ".
"DS:in_brd:DERIVE:120:0:U ".
"DS:in_martian_dst:DERIVE:120:0:U ".
"DS:in_martian_src:DERIVE:120:0:U ".
"DS:out_hit:DERIVE:120:0:U ".
"DS:out_slow_tot:DERIVE:120:0:U ".
"DS:out_slow_mc:DERIVE:120:0:U ".
"DS:gc_total:DERIVE:120:0:U ".
"DS:gc_ignored:DERIVE:120:0:U ".
"DS:gc_goal_miss:DERIVE:120:0:U ".
"DS:gc_dst_overflow:DERIVE:120:0:U ".
"DS:in_hlist_search:DERIVE:120:0:U ".
"DS:out_hlist_search:DERIVE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
$str = 'N';
foreach($data as $val)
$str.=':'.$val;
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd {$str}");
}
function graph1($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="calls" '.
"DEF:a=".RRDPATH."/{$name}.rrd:in_hit:AVERAGE ".
"DEF:b=".RRDPATH."/{$name}.rrd:in_slow_tot:AVERAGE ".
"DEF:c=".RRDPATH."/{$name}.rrd:in_slow_mc:AVERAGE ".
"DEF:d=".RRDPATH."/{$name}.rrd:in_no_route:AVERAGE ".
"DEF:e=".RRDPATH."/{$name}.rrd:in_brd:AVERAGE ".
"DEF:f=".RRDPATH."/{$name}.rrd:in_martian_dst:AVERAGE ".
"DEF:g=".RRDPATH."/{$name}.rrd:in_martian_src:AVERAGE ".
"DEF:h=".RRDPATH."/{$name}.rrd:in_hlist_search:AVERAGE ".
"DEF:i=".RRDPATH."/{$name}.rrd:out_hit:AVERAGE ".
"DEF:j=".RRDPATH."/{$name}.rrd:out_slow_tot:AVERAGE ".
"DEF:k=".RRDPATH."/{$name}.rrd:out_slow_mc:AVERAGE ".
"DEF:l=".RRDPATH."/{$name}.rrd:out_hlist_search:AVERAGE ".
'CDEF:ii=i,-1,* '.
'CDEF:jj=j,-1,* '.
'CDEF:kk=k,-1,* '.
'CDEF:ll=l,-1,* '.
'LINE1:a#FF0000:"in_hit " GPRINT:a:LAST:"Current\:%8.0lf" GPRINT:a:AVERAGE:"Average\:%8.0lf" GPRINT:a:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:b#FF00FF:"in_slow_tot " GPRINT:b:LAST:"Current\:%8.0lf" GPRINT:b:AVERAGE:"Average\:%8.0lf" GPRINT:b:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:c#0000FF:"in_slow_mc " GPRINT:c:LAST:"Current\:%8.0lf" GPRINT:c:AVERAGE:"Average\:%8.0lf" GPRINT:c:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:d#007FFF:"in_no_route " GPRINT:d:LAST:"Current\:%8.0lf" GPRINT:d:AVERAGE:"Average\:%8.0lf" GPRINT:d:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:e#00FFFF:"in_brd " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:f#00FF00:"in_martian_dst " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:g#FFFF00:"in_martian_src " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:h#FF7F00:"in_hlist_search " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'HRULE:0#000000:"-\n" '.
'LINE1:ii#FF0000:"out_hit " GPRINT:i:LAST:"Current\:%8.0lf" GPRINT:i:AVERAGE:"Average\:%8.0lf" GPRINT:i:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:jj#FF00FF:"out_slow_tot " GPRINT:j:LAST:"Current\:%8.0lf" GPRINT:j:AVERAGE:"Average\:%8.0lf" GPRINT:j:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:kk#0000FF:"out_slow_mc " GPRINT:k:LAST:"Current\:%8.0lf" GPRINT:k:AVERAGE:"Average\:%8.0lf" GPRINT:k:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:ll#FF7F00:"out_hlist_search " GPRINT:l:LAST:"Current\:%8.0lf" GPRINT:l:AVERAGE:"Average\:%8.0lf" GPRINT:l:MAX:"Maximum\:%8.0lf\n" '.
'');
}
function graph2($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="calls" '.
"DEF:a=".RRDPATH."/{$name}.rrd:entries:AVERAGE ".
"DEF:b=".RRDPATH."/{$name}.rrd:gc_total:AVERAGE ".
"DEF:c=".RRDPATH."/{$name}.rrd:gc_ignored:AVERAGE ".
"DEF:d=".RRDPATH."/{$name}.rrd:gc_goal_miss:AVERAGE ".
"DEF:e=".RRDPATH."/{$name}.rrd:gc_dst_overflow:AVERAGE ".
'LINE1:a#FF0000:"entries " GPRINT:a:LAST:"Current\:%8.0lf" GPRINT:a:AVERAGE:"Average\:%8.0lf" GPRINT:a:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:b#FF00FF:"gc_total " GPRINT:b:LAST:"Current\:%8.0lf" GPRINT:b:AVERAGE:"Average\:%8.0lf" GPRINT:b:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:c#0000FF:"gc_ignored " GPRINT:c:LAST:"Current\:%8.0lf" GPRINT:c:AVERAGE:"Average\:%8.0lf" GPRINT:c:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:d#007FFF:"gc_goal_miss " GPRINT:d:LAST:"Current\:%8.0lf" GPRINT:d:AVERAGE:"Average\:%8.0lf" GPRINT:d:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:e#00FFFF:"gc_dst_overflow " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'');
}
}
class CtStatRRD {
function update($name, $data) {
if (!file_exists(RRDPATH."/{$name}.rrd")) {
exec(RRDTOOL." create ".RRDPATH."/{$name}.rrd --start now -s 60 ".
"DS:entries:GAUGE:120:0:U ".
"DS:searched:DERIVE:120:0:U ".
"DS:found:DERIVE:120:0:U ".
"DS:new:DERIVE:120:0:U ".
"DS:invalid:DERIVE:120:0:U ".
"DS:ignore:DERIVE:120:0:U ".
"DS:delete:DERIVE:120:0:U ".
"DS:delete_list:DERIVE:120:0:U ".
"DS:insert:DERIVE:120:0:U ".
"DS:insert_failed:DERIVE:120:0:U ".
"DS:drop:DERIVE:120:0:U ".
"DS:early_drop:DERIVE:120:0:U ".
"DS:icmp_error:DERIVE:120:0:U ".
"DS:expect_new:DERIVE:120:0:U ".
"DS:expect_create:DERIVE:120:0:U ".
"DS:expect_delete:DERIVE:120:0:U ".
RRAAVG.RRAMAX.RRAMIN);
chmod(RRDPATH."/{$name}.rrd", RRDMOD);
chgrp(RRDPATH."/{$name}.rrd", RRDGRP);
}
$str = 'N';
foreach($data as $val)
$str.=':'.$val;
exec(RRDTOOL." update ".RRDPATH."/{$name}.rrd {$str}");
}
function graph($name, $start, $title) {
header('Content-type: image/x-png');
passthru(RRDTOOL.' graph - --imgformat PNG --start '.$start.' --end -60 --title "'.$title.'" '.
'--rigid --base=1000 --height=240 --width=800 --alt-autoscale-max '.
'--vertical-label="calls" '.
"DEF:a=".RRDPATH."/{$name}.rrd:searched:AVERAGE ".
"DEF:b=".RRDPATH."/{$name}.rrd:found:AVERAGE ".
"DEF:c=".RRDPATH."/{$name}.rrd:new:AVERAGE ".
"DEF:d=".RRDPATH."/{$name}.rrd:invalid:AVERAGE ".
"DEF:e=".RRDPATH."/{$name}.rrd:ignore:AVERAGE ".
"DEF:f=".RRDPATH."/{$name}.rrd:delete:AVERAGE ".
"DEF:g=".RRDPATH."/{$name}.rrd:delete_list:AVERAGE ".
"DEF:h=".RRDPATH."/{$name}.rrd:insert:AVERAGE ".
"DEF:i=".RRDPATH."/{$name}.rrd:insert_failed:AVERAGE ".
"DEF:j=".RRDPATH."/{$name}.rrd:drop:AVERAGE ".
"DEF:k=".RRDPATH."/{$name}.rrd:early_drop:AVERAGE ".
"DEF:l=".RRDPATH."/{$name}.rrd:icmp_error:AVERAGE ".
"DEF:m=".RRDPATH."/{$name}.rrd:expect_new:AVERAGE ".
"DEF:n=".RRDPATH."/{$name}.rrd:expect_create:AVERAGE ".
"DEF:o=".RRDPATH."/{$name}.rrd:expect_delete:AVERAGE ".
'CDEF:ii=i,-1,* '.
'CDEF:jj=j,-1,* '.
'CDEF:kk=k,-1,* '.
'CDEF:ll=l,-1,* '.
'CDEF:mm=m,-1,* '.
'CDEF:nn=n,-1,* '.
'CDEF:oo=o,-1,* '.
'LINE1:a#FF0000:"searched " GPRINT:a:LAST:"Current\:%8.0lf" GPRINT:a:AVERAGE:"Average\:%8.0lf" GPRINT:a:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:b#FF00FF:"found " GPRINT:b:LAST:"Current\:%8.0lf" GPRINT:b:AVERAGE:"Average\:%8.0lf" GPRINT:b:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:c#0000FF:"new " GPRINT:c:LAST:"Current\:%8.0lf" GPRINT:c:AVERAGE:"Average\:%8.0lf" GPRINT:c:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:d#007FFF:"invalid " GPRINT:d:LAST:"Current\:%8.0lf" GPRINT:d:AVERAGE:"Average\:%8.0lf" GPRINT:d:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:e#00FFFF:"ignore " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:f#00FF00:"delete " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:g#FFFF00:"delete_list " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:h#FF7F00:"insert " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'HRULE:0#000000:"-\n" '.
'LINE1:ii#FF0000:"insert_failed " GPRINT:i:LAST:"Current\:%8.0lf" GPRINT:i:AVERAGE:"Average\:%8.0lf" GPRINT:i:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:jj#FF00FF:"drop " GPRINT:j:LAST:"Current\:%8.0lf" GPRINT:j:AVERAGE:"Average\:%8.0lf" GPRINT:j:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:kk#0000FF:"early_drop " GPRINT:k:LAST:"Current\:%8.0lf" GPRINT:k:AVERAGE:"Average\:%8.0lf" GPRINT:k:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:ll#007FFF:"icmp_errore " GPRINT:l:LAST:"Current\:%8.0lf" GPRINT:l:AVERAGE:"Average\:%8.0lf" GPRINT:l:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:mm#00FFFF:"expect_new " GPRINT:m:LAST:"Current\:%8.0lf" GPRINT:m:AVERAGE:"Average\:%8.0lf" GPRINT:m:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:nn#00FF00:"expect_create " GPRINT:n:LAST:"Current\:%8.0lf" GPRINT:n:AVERAGE:"Average\:%8.0lf" GPRINT:n:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:oo#FFFF00:"expect_delete " GPRINT:o:LAST:"Current\:%8.0lf" GPRINT:o:AVERAGE:"Average\:%8.0lf" GPRINT:o:MAX:"Maximum\:%8.0lf\n" '.
'');
}
}
?>

180
rrdgraph.php Normal file
View File

@ -0,0 +1,180 @@
<?php
define('RRDTOOL', '/usr/bin/rrdtool');
define('RRDPATH', '/home/httpd/rrd');
define('RRDMOD', 0640);
define('RRDGRP', 'httpd');
require_once("/etc/rrdtool/rrd.class.php");
$graphs = array('cpu0' => 'CPU Usage',
'proc' => 'Interrupts / Context Switchs',
'load' => 'Load Average',
'mem' => 'Memory Usage',
'swap' => 'Swap Usage',
'uptime' => 'Uptime (days)',
'hr',
'if_br0' => 'Traffic br0 - internal bridge',
'if_eth0' => 'Traffic eth0 - 100BaseT - bridged',
'if_wlan0' => 'Traffic wlan0 - 802.11b - bridged',
'if_ppp0' => 'Traffic ppp0 - 768/128 TDSL',
'if_ppp1' => 'Traffic ppp1 - 115.2kbaud dect-link',
'if_tap0' => 'Traffic tap0 - layer2 tunnel - bridged (seppel)',
'if_tap2' => 'Traffic tap2 - openvpn tunnel (xittix) - routed',
'if_tap3' => 'Traffic tap3 - openvpn tunnel (server) - routed',
'if_tap5' => 'Traffic tap5 - layer2 tunnel - bridged (roadwarrior)',
'if_sixxs' => 'Traffic sixxs - ipv6 tunnel',
'if_hpot0' => 'Traffic hpot0 - to/from honeypot',
'hr',
'conntrack1' => 'IP Connections (overview)',
'conntrack2' => 'IP Connections (protocols)',
'tcp' => 'TCP Connection States',
'ctstat' => 'Conntrack Statistics',
'rtstat1' => 'Routing Cache Statistics',
'rtstat2' => 'Routing Cache Garbage Collector',
'hr',
'mysql' => 'MySQL Usage',
'httpd' => 'Apache Usage',
'squid1' => 'Squid Proxy Traffic Usage',
'squid2' => 'Squid Proxy Requests/Hits',
'named' => 'DNS Usage',
'hr',
'fs_hda3' => 'Filesystem /',
'disk_hda3' => 'read/write /',
'fs_hda4' => 'Filesystem /home',
'disk_hda4' => 'read/write /home',
'fs_hdc1' => 'Filesystem /mnt/data',
'disk_hdc1' => 'read/write /mnt/data',
);
$views = array( 1 => -3600 * 6,
2 => -3600 * 24,
3 => -3600 * 24 * 7,
4 => -3600 * 24 * 28,
5 => -3600 * 24 * 365,
);
function html_overview($view = 1) {
global $graphs;
echo "<html><head><title>RRDgraph Overview</title></head><body>\n";
foreach ($graphs as $graph => $text) {
if ($text != 'hr') {
echo "<a href=\"{$_SERVER['PHP_SELF']}?show={$graph}\">";
echo "<img src=\"{$_SERVER['PHP_SELF']}?graph={$graph}&view={$view}\" border=\"0\">";
echo "</a><br><br>\n";
} else {
echo "<hr><br>";
}
}
echo "</body></html>\n";
}
function html_detail($graph) {
global $graphs, $views;
echo "<html><head><title>{$graphs[$graph]}</title></head><body>\n";
foreach ($views as $view => $start) {
echo "<img src=\"{$_SERVER['PHP_SELF']}?graph={$graph}&view={$view}\">";
echo "<br><br>\n";
}
echo "</body></html>\n";
}
function img_graph($graph, $view) {
global $graphs, $views;
$start = (isset($views[$view])) ? $views[$view] : $views[1];
switch ($graph) {
case 'proc':
ProcRRD::graph($graph, $start, $graphs[$graph]);
break;
case 'load':
LavgRRD::graph($graph, $start, ($view == 1), $graphs[$graph]);
break;
case 'mem':
MemRRD::graph($graph, $start, $graphs[$graph]);
break;
case 'swap':
SwapRRD::graph($graph, $start, $graphs[$graph]);
break;
case 'mysql':
MysqlRRD::graph($graph, $start, $graphs[$graph]);
break;
case 'httpd':
HttpdRRD::graph($graph, $start, $graphs[$graph]);
break;
case 'named':
NamedRRD::graph($graph, $start, $graphs[$graph]);
break;
case 'uptime':
UpRRD::graph($graph, $start, $graphs[$graph]);
break;
case 'squid1':
SquidRRD::graph1(substr($graph, 0, strlen('squid')), $start, $graphs[$graph]);
break;
case 'squid2':
SquidRRD::graph2(substr($graph, 0, strlen('squid')), $start, $graphs[$graph]);
break;
case 'conntrack1':
ConntrackRRD::graph1(substr($graph, 0, strlen('conntrack')), $start, ($view == 1), $graphs[$graph]);
break;
case 'conntrack2':
ConntrackRRD::graph2(substr($graph, 0, strlen('conntrack')), $start, $graphs[$graph]);
break;
case 'tcp':
TcpRRD::graph($graph, $start, $graphs[$graph]);
break;
case 'rtstat1':
RtStatRRD::graph1(substr($graph, 0, strlen('rtstat')), $start, $graphs[$graph]);
break;
case 'rtstat2':
RtStatRRD::graph2(substr($graph, 0, strlen('rtstat')), $start, $graphs[$graph]);
break;
case 'ctstat':
CtStatRRD::graph($graph, $start, $graphs[$graph]);
break;
default:
if (strpos($graph, 'if_') !== false)
IfaceRRD::graph($graph, $start, ($view == 1), $graphs[$graph]);
else if (strpos($graph, 'fs_') !== false)
FsRRD::graph($graph, $start, $graphs[$graph]);
else if (strpos($graph, 'disk_') !== false)
DiskRRD::graph($graph, $start, $graphs[$graph]);
else if (strpos($graph, 'cpu') !== false)
CpuRRD::graph($graph, $start, ($view == 1), $graphs[$graph]);
break;
}
}
if (isset($_GET['show'])) {
html_detail($_GET['show']);
} else if (isset($_GET['graph'])) {
$view = (isset($_GET['view'])) ? $_GET['view'] : 1;
img_graph($_GET['graph'], $view);
} else {
html_overview();
}
?>

12
rrdgraph.xinetd Normal file
View File

@ -0,0 +1,12 @@
service rrdgraph
{
disable = no
port = 666
type = UNLISTED
flags = NOLIBWRAP
socket_type = stream
wait = no
user = root
server = /usr/bin/php
server_args = /etc/rrdtool/monitoring.php server
}

298
stat.class.php Normal file
View File

@ -0,0 +1,298 @@
<?php
class stat {
function get_cpu() {
$stat = file('/proc/stat');
foreach ($stat as $line) {
if (strpos($line, 'cpu') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$id = array_shift($parts);
$cpu[$id] = $parts;
}
}
return $cpu;
}
function get_sys() {
$stat = file('/proc/stat');
foreach ($stat as $line) {
if (strpos($line, 'intr') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$proc[0] = $parts[1];
} else if (strpos($line, 'ctxt') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$proc[1] = $parts[1];
}
}
$vmstat = file('/proc/vmstat');
foreach ($vmstat as $line) {
if (strpos($line, 'pgfault ') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$proc[2] = $parts[1];
}
}
return $proc;
}
function get_load() {
$loadavg = file('/proc/loadavg');
$load = preg_split("/[\s:]+/", trim($loadavg[0]));
array_pop($load);
array_pop($load);
return $load;
}
function get_mem() {
$meminfo = file('/proc/meminfo');
foreach ($meminfo as $line) {
if (strpos($line, 'MemTotal:') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$mem[0][0] = $parts[1];
} else if (strpos($line, 'MemFree:') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$mem[0][1] = $parts[1];
} else if (strpos($line, 'Buffers:') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$mem[0][2] = $parts[1];
} else if (strpos($line, 'SwapCached:') !== false) {
// nothing
} else if (strpos($line, 'Cached:') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$mem[0][3] = $parts[1];
} else if (strpos($line, 'SwapTotal:') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$mem[1][0] = $parts[1];
} else if (strpos($line, 'SwapFree:') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$mem[1][1] = $parts[1];
}
}
return $mem;
}
function get_uptime() {
$uptime = file('/proc/uptime');
$up = preg_split("/[\s:]+/", trim($uptime[0]));
return $up;
}
function get_interfaces() {
$netdev = file('/proc/net/dev');
foreach ($netdev as $line) {
if (strpos($line, ':') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$devs[$parts[0]][0] = $parts[1];
$devs[$parts[0]][1] = $parts[9];
}
}
return $devs;
}
function get_disks() {
$diskstats = file('/proc/diskstats');
$disks = array();
foreach ($diskstats as $line) {
$parts = preg_split("/[\s:]+/", trim($line));
$disks[$parts[2]][0] = $parts[3];
$disks[$parts[2]][1] = $parts[4];
$disks[$parts[2]][2] = $parts[5];
$disks[$parts[2]][3] = $parts[6];
}
exec('/bin/df -P', $fsstat);
foreach ($fsstat as $line) {
if (strpos($line, '/dev/') === 0) {
$parts = preg_split("/[\s:]+/", trim($line));
$name = str_replace('/dev/', '', $parts[0]);
$fs[$name][0] = $parts[1];
$fs[$name][1] = $parts[2];
$fs[$name][2] = $parts[3];
$fs[$name][3] = $disks[$name];
}
}
return $fs;
}
function get_mysql($host, $user, $pass) {
$dbh = mysql_connect($host, $user, $pass);
$res = mysql_query('SHOW STATUS', $dbh);
while ($row = mysql_fetch_assoc($res)) {
if (strpos($row['Variable_name'], "Questions") !== false)
$mysql[0] = $row['Value'];
else if (strpos($row['Variable_name'], "Threads_connected") !== false)
$mysql[1] = $row['Value'];
}
mysql_close($dbh);
return $mysql;
}
function get_httpd($host) {
$status = file($host);
foreach($status as $line) {
if (strpos($line, 'Total Accesses') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$httpd[0] = $parts[2];
} else if (strpos($line, 'Total kBytes') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$httpd[1] = $parts[2];
} else if (strpos($line, 'BusyWorkers') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$httpd[2] = $parts[1];
} else if (strpos($line, 'IdleWorkers') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$httpd[3] = $parts[1];
}
}
return $httpd;
}
function get_named($statfile) {
if (file_exists($statfile))
unlink($statfile);
exec('/usr/sbin/rndc stats');
$cnt = 100;
while (!file_exists($statfile) && ($i-- > 0))
usleep(100000);
$stats = file($statfile);
foreach ($stats as $line) {
if (strpos($line, 'success') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$named[0] = $parts[1];
} elseif (strpos($line, 'referral') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$named[1] = $parts[1];
} elseif (strpos($line, 'nxrrset') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$named[2] = $parts[1];
} elseif (strpos($line, 'nxdomain') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$named[3] = $parts[1];
} elseif (strpos($line, 'recursion') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$named[4] = $parts[1];
} elseif (strpos($line, 'failure') !== false) {
$parts = preg_split("/[\s:]+/", trim($line));
$named[5] = $parts[1];
}
}
return $named;
}
function get_squid($host, $comunity) {
$cmd = "/usr/bin/snmpget -v1 -c {$comunity} {$host} ".
".1.3.6.1.4.1.3495.1.3.2.1.1 .1.3.6.1.4.1.3495.1.3.2.1.2 ".
".1.3.6.1.4.1.3495.1.3.2.1.3 .1.3.6.1.4.1.3495.1.3.2.1.4 ".
".1.3.6.1.4.1.3495.1.3.2.1.5 .1.3.6.1.4.1.3495.1.3.2.1.10 ".
".1.3.6.1.4.1.3495.1.3.2.1.11 .1.3.6.1.4.1.3495.1.3.2.1.12 ".
".1.3.6.1.4.1.3495.1.3.2.1.13 .1.3.6.1.4.1.3495.1.3.2.1.14 ".
"-O qs";
exec($cmd, $poll);
foreach ($poll as $line) {
$parts = preg_split("/[\s:]+/", trim($line));
$squid[] = $parts[1];
}
return $squid;
}
function get_conntrack() {
$retval = array();
$retval['total'] = 0;
$retval['assured'] = 0;
$retval['unreplied'] = 0;
$retval['tcp'] = 0;
$retval['udp'] = 0;
$retval['unknown'] = 0;
$retval['stat']['NONE'] = 0;
$retval['stat']['SYN_SENT'] = 0;
$retval['stat']['SYN_RECV'] = 0;
$retval['stat']['ESTABLISHED'] = 0;
$retval['stat']['FIN_WAIT'] = 0;
$retval['stat']['CLOSE_WAIT'] = 0;
$retval['stat']['LAST_ACK'] = 0;
$retval['stat']['TIME_WAIT'] = 0;
$retval['stat']['CLOSE'] = 0;
$retval['stat']['LISTEN'] = 0;
$retval['local'] = 0;
$retval['nated'] = 0;
$max = file('/proc/sys/net/ipv4/ip_conntrack_max');
$retval['max'] = (int)$max[0];
$conn = file('/proc/net/ip_conntrack');
foreach ($conn as $line) {
$flags = 0x0;
$retval['total']++;
$parts = preg_split("/[\s:]+/", trim($line));
if (strpos($line, '[ASSURED]') !== false) {
$retval['assured']++;
}
if (strpos($line, '[UNREPLIED]') !== false) {
$retval['unreplied']++;
$flags |= 0x1;
}
if (strpos($line, 'tcp') !== false) {
$retval['tcp']++;
$retval['stat'][$parts[3]]++;
if (!($flags & 0x1)) {
// dst1 != src2 || src1 != dst2
if (substr($parts[5], 4) != substr($parts[10], 4) || substr($parts[4], 4) != substr($parts[11], 4))
$retval['nated']++;
else
$retval['local']++;
}
} else if (strpos($line, 'udp') !== false) {
$retval['udp']++;
if (!($flags & 0x1)) {
// dst1 != src2 || src1 != dst2
if (substr($parts[4], 4) != substr($parts[9], 4) || substr($parts[3], 4) != substr($parts[10], 4))
$retval['nated']++;
else
$retval['local']++;
}
} else {
$retval['unknown']++;
}
}
return $retval;
}
function get_netstat($file) {
$stat = file($file);
$retval = preg_split("/[\s:]+/", trim($stat[1]));
foreach ($retval as $key => $val)
$retval[$key] = hexdec($val);
return $retval;
}
}
?>