Initial Import

git-svn-id: http://www.observium.org/svn/observer/trunk@2 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Super User
2007-04-03 14:10:23 +00:00
parent 824c4d2ad4
commit ff70062aa9
1377 changed files with 19404 additions and 0 deletions
+180
View File
@@ -0,0 +1,180 @@
<?php
class snmpCDP {
var $community = "public";
var $host = "";
/**
* Initialises the class.
* $snmp = new snmpCDP('device','public');
*/
function snmpCDP($host,$community) {
$this->host=$host;
$this->community=$community;
}
/**
* Identify
* Determines if the queried device is made by Cisco or not.
* $type = $snmp->identify();
* @return string
*/
function identify() {
$ret=snmpget($this->host,$this->community,"SNMPv2-MIB::sysDescr.0");
if (substr_count($ret,"Cisco") > 0) {
return "cisco";
} else {
return "unknown";
}
}
/**
* Location
* Returns the location string configured on the device.
* $location = $snmp->location();
* @return string
*/
function location() {
return snmpget($this->host,$this->community,"SNMPv2-MIB::sysLocation.0");
}
/**
* Function to determine if port is up or down from returned SNMP string.
* @access private
*/
function _isitup($text) {
$x = substr($text,9);
switch($x) {
case "up(1)": return true; break;
case "down(2)": return false; break;
}
}
/**
* Returns the type of port depending on the returned SNMP string.
* @access private
*/
function _porttype($text) {
$x = substr($text,9);
switch($x) {
case "ethernetCsmacd(6)": return "ethernet"; break;
case "propVirtual(53)": return "virtual"; break;
case "propPointToPointSerial(22)": return "serial"; break;
default: return $text; break;
}
}
/**
* Get Port List
* Returns an array forming a list of the ports on the device, including name, alias and type.
* The returned array is indexed by the port index in the SNMP tree.
*
* $snmp->getports();
*
* An example of the output:
* Array
* (
* [2] => Array
* (
* [desc] => GigabitEthernet0/1
* [alias] =>
* [type] => ethernet
* )
* )
* @return array
*/
function getports() {
$nosint = @snmpget($this->host,$this->community,"IF-MIB::ifNumber.0");
$ports = @snmpwalk($this->host,$this->community,"IF-MIB::ifIndex");
$results=array();
foreach($ports as $port) {
$x = substr($port,9);
$admin = snmpget($this->host,$this->community,"IF-MIB::ifAdminStatus.$x");
if ($this->_isitup($admin)==true) {
$desc = substr(snmpget($this->host,$this->community,"IF-MIB::ifDescr.$x"),8);
$alias = substr(snmpget($this->host,$this->community,"IF-MIB::ifAlias.$x"),8);
$type = $this->_porttype(snmpget($this->host,$this->community,"IF-MIB::ifType.$x"));
$results["$x"]=array("desc"=>$desc,"alias"=>$alias,"type"=>$type);
}
}
return $results;
}
/**
* Port Status
* Returns the status of an individual port. Takes the SNMP index as the parameter.
* if ($snmp->portstatus(2)==true) {
* echo "Port is up!";
* }
* @var integer $id
* @return bool
*/
function portstatus($id) {
$adminStatus = @snmpget($this->host,$this->community,"IF-MIB::ifAdminStatus.$id");
if ($this->_isitup($adminStatus)==true) {
$operStatus = @snmpget($this->host,$this->community,"IF-MIB::ifOperStatus.$id");
if ($this->_isitup($operStatus)==true) {
return true;
} else {
return false;
}
} else {
return true;
}
}
/**
* @access private
*/
function _walkget($oid) {
$ret = snmpwalk($this->host,$this->community,$oid);
if (sizeof($ret) > 0) {
return $ret[0];
} else {
return false;
}
}
/**
* Explore CDP
* When supplied with the current port list from the device, it will determine each ports CDP status.
* Returns an array containing the device name and port of the remote SNMP device detected via CDP,
* assuming that it has the same community string as the initial device. The returned array is indexed
* by the SNMP ports of the initial device.
*
* $ports = $snmp->getports();
* $cdp = $snmp->explore_cdp($ports);
*
* An example of the output will look like:
* Array
* (
* [2] => Array
* (
* [host] => second.device.hostname
* [port] => FastEthernet0/1
* )
* )
* @var array ports
* @return array
*/
function explore_cdp($ports) {
$cdpports=array();
foreach($ports as $id => $port) {
if ($ret = $this->_walkget("SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.6.$id")) {
// this port is connected to another cisco!
$remote_id = substr($ret,9,strlen($ret)-10);
if ($ret = $this->_walkget("SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.7.$id")) {
$remote_port = substr($ret,9,strlen($ret)-10);
}
#echo "$this->host($port[desc]) is connected to $remote_id($remote_port)\n";
$cdpports[$id]=array('host'=>$remote_id,'port'=>$remote_port);
}
}
return $cdpports;
}
}
?>
+1046
View File
File diff suppressed because it is too large Load Diff
+48
View File
@@ -0,0 +1,48 @@
<?
function pollDevice() {
global $device;
global $community;
$id = $device['id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];
$features = $device['features'];
$location = $device['location'];
$os = $device['location'];
$temprrd = "rrd/" . $hostname . "-temp.rrd";
$tempgraph = "public_html/graphs/" . $hostname . "-temp.png";
$cpurrd = "rrd/" . $hostname . "-cpu.rrd";
$cpugraph = "public_html/graphs/" . $hostname . "-cpu.png";
$memrrd = "rrd/" . $hostname . "-mem.rrd";
$memgraph = "public_html/graphs/" . $hostname . "-mem.png";
list ($cpu5m, $cpu5s) = explode("\n", `snmpget -O qv -v2c -c $community $hostname 1.3.6.1.4.1.9.2.1.58.0 1.3.6.1.4.1.9.2.1.56.0`);
$cpu5m = $cpu5m + 0;
$cpu5s = $cpu5s + 0;
list ($tempin1, $tempout1) = explode("\n", `snmpget -O qv -v2c -c $community $hostname .1.3.6.1.4.1.9.9.13.1.3.1.3.1 .1.3.6.1.4.1.9.9.13.1.3.1.3.2`);
$tempin1 = $tempin1 +0;
$tempout1 = $tempout1 + 0;
list ($memfreeio, $memfreeproc, $memusedio, $memusedproc) = explode("\n", `snmpget -O qv -v2c -c $community $hostname .1.3.6.1.4.1.9.9.48.1.1.1.6.2 .1.3.6.1.4.1.9.9.48.1.1.1.6.1 .1.3.6.1.4.1.9.9.48.1.1.1.5.2 .1.3.6.1.4.1.9.9.48.1.1.1.5.1`);
echo("$hostname\n");
$memfreeio = $memfreeio + 0;
$memfreeproc = $memfreeproc + 0;
$memusedio = $memusedio + 0;
$memusedproc = $memusedproc + 0;
$memtotal = $memfreeio + $memfreeproc + $memusedio + $memusedproc;
if (!is_file($cpurrd)) {
$rrdcreate = `rrdtool create $cpurrd --step 300 DS:LOAD5S:GAUGE:600:-1:100 DS:LOAD5M:GAUGE:600:-1:100 RRA:AVERAGE:0.5:1:1200`;
}
if (!is_file($temprrd)) {
$rrdcreate = `rrdtool create $temprrd --step 300 DS:TEMPIN1:GAUGE:600:-1:100 DS:TEMPOUT1:GAUGE:600:-1:100 RRA:AVERAGE:0.5:1:1200`;
}
if (!is_file($memrrd)) {
$rrdcreate = `rrdtool create $memrrd --step 300 DS:IOFREE:GAUGE:600:0:500000000 DS:IOUSED:GAUGE:600:-1:500000000 DS:PROCFREE:GAUGE:600:0:500000000 DS:PROCUSED:GAUGE:600:-1:500000000 DS:MEMTOTAL:GAUGE:600:-1:500000000 RRA:AVERAGE:0.5:1:1200`;
}
`rrdtool update $temprrd N:$tempin1:$tempout1`;
`rrdtool update $cpurrd N:$cpu5s:$cpu5m`;
`rrdtool update $memrrd N:$$memfreeio:$memusedio:$memfreeproc:$memusedproc:$memtotal`;
}
?>
+43
View File
@@ -0,0 +1,43 @@
<?php
function temp_graph ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical, "--alt-autoscale-max",
"-l 0",
"-E",
"-b 1024",
"--title", $title);
$hostname = gethostbyid($device);
$imgfile = "graphs/" . "$graph";
$iter = "1";
$sql = mysql_query("SELECT * FROM temperature where temp_host = '$device'");
$optsa[] = "COMMENT: Cur Max";
while($fs = mysql_fetch_array($sql)) {
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
} elseif($iter=="7") {$colour="FF0084"; unset($iter); }
$fs[temp_descr] = str_pad($fs[temp_descr], 28);
$fs[temp_descr] = substr($fs[temp_descr],0,28);
$optsa[] = "DEF:temp$fs[temp_id]=rrd/$hostname-temp$fs[temp_id].rrd:temp:AVERAGE";
$optsa[] = "LINE1:temp$fs[temp_id]#" . $colour . ":$fs[temp_descr]";
$optsa[] = "GPRINT:temp$fs[temp_id]:LAST:%3.0lf°C";
$optsa[] = "GPRINT:temp$fs[temp_id]:MAX:%3.0lf°C\l";
$iter++;
}
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
?>
+88
View File
@@ -0,0 +1,88 @@
<?
function pollDeviceIOS() {
global $device;
global $community;
$id = $device['id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];
$features = $device['features'];
$location = $device['location'];
$os = $device['location'];
$temprrd = "rrd/" . $hostname . "-temp.rrd";
$tempgraph = "public_html/graphs/" . $hostname . "-temp.png";
$cpurrd = "rrd/" . $hostname . "-cpu.rrd";
$cpugraph = "public_html/graphs/" . $hostname . "-cpu.png";
$memrrd = "rrd/" . $hostname . "-mem.rrd";
$memgraph = "public_html/graphs/" . $hostname . "-mem.png";
list ($cpu5m, $cpu5s) = explode("\n", `snmpget -O qv -v2c -c $community $hostname 1.3.6.1.4.1.9.2.1.58.0 1.3.6.1.4.1.9.2.1.56.0`);
$cpu5m = $cpu5m + 0;
$cpu5s = $cpu5s + 0;
list ($tempin1, $tempout1) = explode("\n", `snmpget -O qv -v2c -c $community $hostname .1.3.6.1.4.1.9.9.13.1.3.1.3.1 .1.3.6.1.4.1.9.9.13.1.3.1.3.2`);
$tempin1 = $tempin1 +0;
$tempout1 = $tempout1 + 0;
$mem_get = ".1.3.6.1.4.1.9.9.48.1.1.1.6.2 .1.3.6.1.4.1.9.9.48.1.1.1.6.1 .1.3.6.1.4.1.9.9.48.1.1.1.6.3";
$mem_get .= ".1.3.6.1.4.1.9.9.48.1.1.1.5.2 .1.3.6.1.4.1.9.9.48.1.1.1.5.1 .1.3.6.1.4.1.9.9.48.1.1.1.5.3";
$mem_raw = `snmpget -O qv -v2c -c $community $hostname $mem_get`;
$mem_raw = str_replace("No Such Instance currently exists at this OID", "0", $mem_raw);
list ($memfreeio, $memfreeproc, $memfreeprocb, $memusedio, $memusedproc, $memusedprocb) = explode("\n", $mem_raw);
echo("$hostname\n");
$memfreeproc = $memfreeproc + $memfreeprocb;
$memusedproc = $memusedproc + $memusedprocb;
$memfreeio = $memfreeio + 0;
$memfreeproc = $memfreeproc + 0;
$memusedio = $memusedio + 0;
$memusedproc = $memusedproc + 0;
$memtotal = $memfreeio + $memfreeproc + $memusedio + $memusedproc;
if (!is_file($cpurrd)) {
$rrdcreate = `rrdtool create $cpurrd --step 300 \
DS:LOAD5S:GAUGE:600:-1:100 \
DS:LOAD5M:GAUGE:600:-1:100 \
RRA:AVERAGE:0.5:1:2000 \
RRA:AVERAGE:0.5:6:2000 \
RRA:AVERAGE:0.5:24:2000 \
RRA:AVERAGE:0.5:288:2000 \
RRA:MAX:0.5:1:2000 \
RRA:MAX:0.5:6:2000 \
RRA:MAX:0.5:24:2000 \
RRA:MAX:0.5:288:2000`;
}
if (!is_file($temprrd)) {
$rrdcreate = `rrdtool create $temprrd --step 300 \
DS:TEMPIN1:GAUGE:600:-25:100 \
DS:TEMPOUT1:GAUGE:600:-25:100 \
RRA:AVERAGE:0.5:1:2000 \
RRA:AVERAGE:0.5:6:2000 \
RRA:AVERAGE:0.5:24:2000 \
RRA:AVERAGE:0.5:288:2000 \
RRA:MAX:0.5:1:2000 \
RRA:MAX:0.5:6:2000 \
RRA:MAX:0.5:24:2000 \
RRA:MAX:0.5:288:2000`;
}
if (!is_file($memrrd)) {
$rrdcreate = `rrdtool create $memrrd --step 300 \
DS:IOFREE:GAUGE:600:0:U \
DS:IOUSED:GAUGE:600:-1:U \
DS:PROCFREE:GAUGE:600:0:U \
DS:PROCUSED:GAUGE:600:-1:U \
DS:MEMTOTAL:GAUGE:600:-1:U \
RRA:AVERAGE:0.5:1:2000 \
RRA:AVERAGE:0.5:6:2000 \
RRA:AVERAGE:0.5:24:2000 \
RRA:AVERAGE:0.5:288:2000 \
RRA:MAX:0.5:1:2000 \
RRA:MAX:0.5:6:2000 \
RRA:MAX:0.5:24:2000 \
RRA:MAX:0.5:288:2000`;
}
`rrdtool update $temprrd N:$tempin1:$tempout1`;
`rrdtool update $cpurrd N:$cpu5s:$cpu5m`;
`rrdtool update $memrrd N:$memfreeio:$memusedio:$memfreeproc:$memusedproc:$memtotal`;
}
?>
+64
View File
@@ -0,0 +1,64 @@
<?php
function cpugraphHP ($rrd, $graph , $from, $to, $width, $height)
{
global $rrdtool; global $installdir;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array( "--start", $from, "--width", $width, "--height", $height, "--vertical-label", $vertical, "--alt-autoscale-max",
"-l 0",
"-E",
"--title", $title,
"DEF:load=$database:LOAD:AVERAGE",
"AREA:load#FAFDCE:",
"LINE1.25:load#dd8800:Load",
"GPRINT:load:LAST:Cur\:%3.2lf",
"GPRINT:load:AVERAGE:Avg\:%3.2lf",
"GPRINT:load:MIN:Min\:%3.2lf",
"GPRINT:load:MAX:Max\:%3.2lf\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
#echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function memgraphHP ($rrd, $graph , $from, $to, $width, $height, $title, $vertical)
{
global $rrdtool; global $installdir;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$memrrd = $database;
$opts = "--start $from \
--alt-autoscale-max \
--width $width --height $height \
-l 0 -E \
-b 1024 \
DEF:TOTAL=$memrrd:TOTAL:AVERAGE \
DEF:FREE=$memrrd:FREE:AVERAGE \
DEF:USED=$memrrd:USED:AVERAGE \
AREA:USED#ee9900:Used \
AREA:FREE#FAFDCE:Free:STACK \
LINE1.5:TOTAL#cc0000:";
if($width <= "300") {$opts .= "\
--font LEGEND:7:$installdir/DejaVuSansMono.ttf \
--font AXIS:6:$installdir/DejaVuSansMono.ttf \
--font-render-mode normal";}
`$rrdtool graph $imgfile $opts`;
return $imgfile;
}
+36
View File
@@ -0,0 +1,36 @@
<?
include("procurve-graphing.php");
function pollDeviceHP() {
global $device;
global $community;
$id = $device['id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];
$features = $device['features'];
$location = $device['location'];
$os = $device['location'];
$cpurrd = "rrd/" . $hostname . "-cpu.rrd";
$memrrd = "rrd/" . $hostname . "-mem.rrd";
$cpu = `snmpget -O qv -v2c -c $community $hostname 1.3.6.1.4.1.11.2.14.11.5.1.9.6.1.0`;
$meminfo = `snmpget -O qv -v2c -c $community $hostname 1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.5.1 1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.6.1 1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.7.1`;
echo("$meminfo");
list ($memtotal, $memfree, $memused) = explode("\n", $meminfo);
echo("$hostname\n");
$memused = $memused + 0;
$memfree = $memfree + 0;
$memtotal = $memtotal + 0;
if (!is_file($cpurrd)) {
$rrdcreate = `rrdtool create $cpurrd --step 300 DS:LOAD:GAUGE:600:-1:100 RRA:AVERAGE:0.5:1:1200`;
}
if (!is_file($memrrd)) {
$rrdcreate = `rrdtool create $memrrd --step 300 DS:TOTAL:GAUGE:600:0:500000000 DS:FREE:GAUGE:600:-1:500000000 DS:USED:GAUGE:600:0:500000000 RRA:AVERAGE:0.5:1:1200`;
}
`rrdtool update $cpurrd N:$cpu`;
`rrdtool update $memrrd N:$memtotal:$memfree:$memused`;
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
$check = `checkers/check_dns -H $service[param] -s $service[hostname]`;
list($check, $time) = split("\|", $check);
if(strstr($check, "DNS OK: ")) {
$status = '1';
} else {
$status = '0';
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
$check = `checkers/check_ftp -H $service[hostname]`;
list($check, $time) = split("\|", $check);
if(strstr($check, "FTP OK - ")) {
$status = '1';
} else {
$status = '0';
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
$check = `checkers/check_http -H $service[hostname]`;
list($check, $time) = split("\|", $check);
if(strstr($check, "HTTP OK")) {
$status = '1';
} else {
$status = '0';
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
$check = `checkers/check_imap -H $service[hostname]`;
list($check, $time) = split("\|", $check);
if(strstr($check, "IMAP OK - ")) {
$status = '1';
} else {
$status = '0';
}
?>
+15
View File
@@ -0,0 +1,15 @@
<?php
$check = `checkers/check_mysql -H $service[hostname] $service[service_param]`;
echo($check);
list($check, $time) = split("\|", $check);
if(strstr($check, "Uptime:")) {
$status = '1';
} else {
$status = '0';
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
$check = `checkers/check_pop -H $service[hostname]`;
list($check, $time) = split("\|", $check);
if(strstr($check, "POP OK - ")) {
$status = '1';
} else {
$status = '0';
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
$check = `checkers/check_simap -H $service[hostname]`;
list($check, $time) = split("\|", $check);
if(strstr($check, "SIMAP OK")) {
$status = '1';
} else {
$status = '0';
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
$check = `checkers/check_smtp -H $service[hostname]`;
list($check, $time) = split("\|", $check);
if(strstr($check, "SMTP OK")) {
$status = '1';
} else {
$status = '0';
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
$check = `checkers/check_spop -H $service[hostname]`;
list($check, $time) = split("\|", $check);
if(strstr($check, "SPOP OK")) {
$status = '1';
} else {
$status = '0';
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
$check = `checkers/check_ssh -H $service[hostname]`;
list($check, $time) = split("\|", $check);
if(strstr($check, "SSH OK")) {
$status = '1';
} else {
$status = '0';
}
?>
+16
View File
@@ -0,0 +1,16 @@
<?php
if($service[service_port]) { $port = $service[service_port]; } else { $port = '23'; }
$check = `checkers/check_tcp -H $service[hostname] -p $port`;
list($check, $time) = split("\|", $check);
if(strstr($check, "TCP OK - ")) {
$status = '1';
} else {
$status = '0';
}
?>
+36
View File
@@ -0,0 +1,36 @@
<?php
function callsgraphSNOM ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical ,"--alt-autoscale-max",
"-l 0",
"-E",
"--title", $title,
"DEF:call=$database:CALLS:AVERAGE",
"CDEF:calls=call,360,*",
"LINE1.25:calls#FF9900:Calls",
"GPRINT:calls:LAST:Cu\: %2.0lf/min",
"GPRINT:calls:AVERAGE:Av\: %2.0lf/min",
"GPRINT:calls:MAX:Mx\: %2.0lf/min\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
?>
+49
View File
@@ -0,0 +1,49 @@
<?
include("snom-graphing.php");
function pollDeviceSNOM() {
global $device;
global $community;
$snmpver = $device['snmpver'];
$id = $device['id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];
$features = $device['features'];
$location = $device['location'];
$snmpdata = `snmpget -Ovq -$snmpver -c $community $hostname 1.3.6.1.2.1.7526.2.1.1 1.3.6.1.2.1.7526.2.1.2 1.3.6.1.2.1.7526.2.2.1 1.3.6.1.2.1.7526.2.2.2`;
$snmpdatab = `snmpget -Oqv -$snmpver -c $community $hostname 1.3.6.1.2.1.7526.2.5 1.3.6.1.2.1.7526.2.6`;
list($rxbytes, $rxpkts, $txbytes, $txpkts) = explode("\n", $snmpdata);
list($calls, $registrations) = explode("\n", $snmpdatab);
$txbytes = 0 - $txbytes * 8;
$rxbytes = 0 - $rxbytes * 8;
echo("$rxbytes, $rxpkts, $txbytes, $txpkts, $calls, $registrations");
$rrdfile = "rrd/" . $hostname . "-data.rrd";
if(!is_file($rrdfile)) {
$woo = `rrdtool create $rrdfile \
DS:INOCTETS:COUNTER:600:U:100000000000 \
DS:OUTOCTETS:COUNTER:600:U:10000000000 \
DS:INPKTS:COUNTER:600:U:10000000000 \
DS:OUTPKTS:COUNTER:600:U:10000000000 \
DS:CALLS:COUNTER:600:U:10000000000 \
DS:REGISTRATIONS:COUNTER:600:U:10000000000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797`;
}
$rrdupdate = "N:$rxbytes:$txbytes:$rxpkts:$rxbytes:$calls:$registrations";
$ret = rrd_update("$rrdfile", $rrdupdate);
}
?>
+627
View File
@@ -0,0 +1,627 @@
<?php
// Start Graphing Functions
function mailerrorgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$range = $to - $from;
$points_per_sample = 3;
$xpoints = '540';
$step = $range*$points_per_sample/$xpoints;
$rrd_virus = "rrd/" . $rrd . "-mail_virus.rrd";
$rrd = "rrd/" . $rrd . "-mail.rrd";
$imgfile = "graphs/" . "$graph";
$optsa = array(
"-E",
"--lower-limit", "0",
"--units-exponent", "0",
"--title", $title,
"--vertical-label", $vertical,
"-l 0",
"--width", $width, "--height", $height,
"--start", $from, "--end", $to,
"DEF:rejected=$rrd:rejected:AVERAGE",
"DEF:mrejected=$rrd:rejected:MAX",
"CDEF:rrejected=rejected,60,*",
"CDEF:drejected=rejected,UN,0,rejected,IF,$step,*",
"CDEF:srejected=PREV,UN,drejected,PREV,IF,drejected,+",
"CDEF:rmrejected=mrejected,60,*",
"DEF:bounced=$rrd:bounced:AVERAGE",
"DEF:mbounced=$rrd:bounced:MAX",
"CDEF:rbounced=bounced,60,*",
"CDEF:dbounced=bounced,UN,0,bounced,IF,$step,*",
"CDEF:sbounced=PREV,UN,dbounced,PREV,IF,dbounced,+",
"CDEF:rmbounced=mbounced,60,*",
"DEF:virus=$rrd_virus:virus:AVERAGE",
"DEF:mvirus=$rrd_virus:virus:MAX",
"CDEF:rvirus=virus,60,*",
"CDEF:dvirus=virus,UN,0,virus,IF,$step,*",
"CDEF:svirus=PREV,UN,dvirus,PREV,IF,dvirus,+",
"CDEF:rmvirus=mvirus,60,*",
"DEF:spam=$rrd_virus:spam:AVERAGE",
"DEF:mspam=$rrd_virus:spam:MAX",
"CDEF:rspam=spam,60,*",
"CDEF:dspam=spam,UN,0,spam,IF,$step,*",
"CDEF:sspam=PREV,UN,dspam,PREV,IF,dspam,+",
"CDEF:rmspam=mspam,60,*",
"LINE2:rrejected#cc0000:reject",
'GPRINT:srejected:MAX:tot\: %6.0lf msgs',
'GPRINT:rrejected:AVERAGE:avg\: %5.2lf/min',
'GPRINT:rmrejected:MAX:max\: %3.0lf/min\l',
"AREA:rbounced#0000cc:bounce",
'GPRINT:sbounced:MAX:tot\: %6.0lf msgs',
'GPRINT:rbounced:AVERAGE:avg\: %5.2lf/min',
'GPRINT:rmbounced:MAX:max\: %3.0lf/min\l',
"STACK:rvirus#000000:virus ",
'GPRINT:svirus:MAX:tot\: %6.0lf msgs',
'GPRINT:rvirus:AVERAGE:avg\: %5.2lf/min',
'GPRINT:rmvirus:MAX:max\: %3.0lf/min\l',
"STACK:rspam#00cc00:spam ",
'GPRINT:sspam:MAX:tot\: %6.0lf msgs',
'GPRINT:rspam:AVERAGE:avg\: %5.2lf/min',
'GPRINT:rmspam:MAX:max\: %3.0lf/min\l');
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function mailsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$points_per_sample = 3;
$range = $to - $from;
$xpoints = '540';
$step = $range*$points_per_sample/$xpoints;
$rrd = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"-E",
"--lower-limit", "0",
"--units-exponent", "0",
"--title", $title,
"--vertical-label", $vertical,
"-l 0",
"--width", $width, "--height", $height,
"--start",
$from, "--end", $to,
"DEF:sent=$rrd:sent:AVERAGE",
"DEF:msent=$rrd:sent:MAX",
"CDEF:rsent=sent,60,*",
"CDEF:rmsent=msent,60,*",
"CDEF:dsent=sent,UN,0,sent,IF,$step,*",
"CDEF:ssent=PREV,UN,dsent,PREV,IF,dsent,+",
"DEF:recv=$rrd:recv:AVERAGE",
"DEF:mrecv=$rrd:recv:MAX",
"CDEF:rrecv=recv,60,*",
"CDEF:rmrecv=mrecv,60,*",
"CDEF:drecv=recv,UN,0,recv,IF,$step,*",
"CDEF:srecv=PREV,UN,drecv,PREV,IF,drecv,+",
"AREA:rsent#00c000:sent",
"LINE1:rsent#005000:",
"GPRINT:ssent:MAX:Tot\: %5.0lf msgs",
"GPRINT:rsent:AVERAGE:Avg\: %4.2lf/min",
"GPRINT:rmsent:MAX:Max\: %3.0lf/min\l",
"LINE1.5:rrecv#cc0000:rcvd",
"GPRINT:srecv:MAX:Tot\: %5.0lf msgs",
"GPRINT:rrecv:AVERAGE:Avg\: %4.2lf/min",
"GPRINT:rmrecv:MAX:Max\: %3.0lf/min\l");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function memgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical)
{
global $rrdtool; global $installdir;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array (
"--start", $from, "--end", $to,
"-b 1024",
"-E",
"-v", $vertical,
"--title", $title,
"-l 0",
"--width", $width, "--height", $height,
"DEF:atotalswap=$database:totalswap:AVERAGE",
"DEF:aavailswap=$database:availswap:AVERAGE",
"DEF:atotalreal=$database:totalreal:AVERAGE",
"DEF:aavailreal=$database:availreal:AVERAGE",
"DEF:atotalfree=$database:totalfree:AVERAGE",
"DEF:ashared=$database:shared:AVERAGE",
"DEF:abuffered=$database:buffered:AVERAGE",
"DEF:acached=$database:cached:AVERAGE",
"CDEF:totalswap=atotalswap,1024,*",
"CDEF:availswap=aavailswap,1024,*",
"CDEF:totalreal=atotalreal,1024,*",
"CDEF:availreal=aavailreal,1024,*",
"CDEF:totalfree=atotalfree,1024,*",
"CDEF:shared=ashared,1024,*",
"CDEF:buffered=abuffered,1024,*",
"CDEF:cached=acached,1024,*",
"CDEF:usedreal=totalreal,availreal,-",
"CDEF:usedswap=totalswap,availswap,-",
"CDEF:cusedswap=usedswap,-1,*",
"CDEF:cdeftot=availreal,shared,buffered,usedreal,cached,usedswap,+,+,+,+,+",
"COMMENT:Bytes Current Average Maximum\\n",
"LINE1:usedreal#d0b080:",
"AREA:usedreal#f0e0a0:used",
"GPRINT:usedreal:LAST: %7.2lf %s",
"GPRINT:usedreal:AVERAGE:%7.2lf %s",
"GPRINT:usedreal:MAX:%7.2lf %s\\n",
"STACK:availreal#e5e5e5:free",
"GPRINT:availreal:LAST: %7.2lf %s",
"GPRINT:availreal:AVERAGE:%7.2lf %s",
"GPRINT:availreal:MAX:%7.2lf %s\\n",
"LINE1:usedreal#d0b080:",
"AREA:shared#afeced::",
"AREA:buffered#cc0000::STACK",
"AREA:cached#ffaa66::STACK",
"LINE1.25:shared#008fea:shared",
"GPRINT:shared:LAST: %7.2lf %s",
"GPRINT:shared:AVERAGE:%7.2lf %s",
"GPRINT:shared:MAX:%7.2lf %s\\n",
"LINE1.25:buffered#ff1a00:buffers:STACK",
"GPRINT:buffered:LAST:%7.2lf %s",
"GPRINT:buffered:AVERAGE:%7.2lf %s",
"GPRINT:buffered:MAX:%7.2lf %s\\n",
"LINE1.25:cached#ea8f00:cached:STACK",
"GPRINT:cached:LAST: %7.2lf %s",
"GPRINT:cached:AVERAGE:%7.2lf %s",
"GPRINT:cached:MAX:%7.2lf %s\\n",
"LINE1:totalreal#050505:",
"AREA:cusedswap#C3D9FF:swap",
"LINE1.25:cusedswap#356AA0:",
"GPRINT:usedswap:LAST: %7.2lf %s",
"GPRINT:usedswap:AVERAGE:%7.2lf %s",
"GPRINT:usedswap:MAX:%7.2lf %s\\n",
"LINE1:totalreal#050505:total",
"GPRINT:totalreal:AVERAGE: %7.2lf %s");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function loadgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"--title", $title,
"--start",
$from, "--end", $to,
"-E",
"-v", $vertical,
"--rigid",
"--alt-autoscale-max",
"-l 0",
"--width", $width, "--height", $height,
"DEF:1min=$database:1min:AVERAGE",
"DEF:5min=$database:5min:AVERAGE",
"DEF:15min=$database:15min:AVERAGE",
"CDEF:a=1min,100,/",
"CDEF:b=5min,100,/",
"CDEF:c=15min,100,/",
"CDEF:cdefd=a,b,c,+,+",
"COMMENT:Load Average Current Average Maximum\\n",
"AREA:a#ffeeaa:1 Min:",
"LINE1:a#c5aa00:",
"GPRINT:a:LAST: %7.2lf",
"GPRINT:a:AVERAGE: %7.2lf",
"GPRINT:a:MAX: %7.2lf\\n",
"LINE1.25:b#ea8f00:5 Min:",
"GPRINT:b:LAST: %7.2lf",
"GPRINT:b:AVERAGE: %7.2lf",
"GPRINT:b:MAX: %7.2lf\\n",
"LINE1.25:c#cc0000:15 Min",
"GPRINT:c:LAST: %7.2lf",
"GPRINT:c:AVERAGE: %7.2lf",
"GPRINT:c:MAX: %7.2lf\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function usersgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"--title", $title,
"--start",
$from, "--end", $to,
"-E",
"-v", $vertical,
"--rigid",
"--alt-autoscale-max",
"-l 0",
"--width", $width, "--height", $height,
"DEF:users=$database:users:AVERAGE",
"COMMENT:Users Cur Ave Min Max\\n",
"AREA:users#CDEB8B:",
"LINE1.25:users#008C00: ",
"GPRINT:users:LAST: %6.2lf",
"GPRINT:users:AVERAGE:%6.2lf",
"GPRINT:users:MIN:%6.2lf",
"GPRINT:users:MAX:%6.2lf\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function procsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"--title", $title,
"--start", $from, "--end", $to,
"-E",
"-v", $vertical,
"--rigid",
"--alt-autoscale-max",
"-l 0",
"--width", $width, "--height", $height,
"DEF:procs=$database:procs:AVERAGE",
"DEF:maxprocs=$database:procs:MAX",
"COMMENT:Processes Cur Ave Min Max\\n",
"AREA:procs#C3D9FF:",
"LINE1.25:procs#356AA0: ",
"GPRINT:procs:LAST: %6.2lf",
"GPRINT:procs:AVERAGE:%6.2lf",
"GPRINT:procs:MIN:%6.2lf",
"GPRINT:procs:MAX:%6.2lf\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function cpugraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"--title", $title,
"--start",
$from, "--end", $to,
"-E",
"-v", $vertical,
"--rigid",
"--alt-autoscale-max",
"-l 0",
"--width", $width, "--height", $height,
"DEF:user=$database:user:AVERAGE",
"DEF:nice=$database:nice:AVERAGE",
"DEF:system=$database:system:AVERAGE",
"DEF:idle=$database:idle:AVERAGE",
"CDEF:total=user,nice,system,idle,+,+,+",
"CDEF:user_perc=user,total,/,100,*",
"CDEF:nice_perc=nice,total,/,100,*",
"CDEF:system_perc=system,total,/,100,*",
"CDEF:idle_perc=idle,total,/,100,*",
"AREA:user_perc#c02020:user",
"GPRINT:user_perc:LAST: Cur\:%3.0lf%%",
"GPRINT:user_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:user_perc:MAX: Max\:%3.0lf%%\\n",
"AREA:nice_perc#008f00:nice:STACK",
"GPRINT:nice_perc:LAST: Cur\:%3.0lf%%",
"GPRINT:nice_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:nice_perc:MAX: Max\:%3.0lf%%\\n",
"AREA:system_perc#ea8f00:system:STACK",
"GPRINT:system_perc:LAST:Cur\:%3.0lf%%",
"GPRINT:system_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:system_perc:MAX: Max\:%3.0lf%%\\n",
"AREA:idle_perc#f5f5e5:idle:STACK",
"GPRINT:idle_perc:LAST: Cur\:%3.0lf%%",
"GPRINT:idle_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:idle_perc:MAX: Max\:%3.0lf%%\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
# $err = rrd_error();
return FALSE;
} else {
return $imgfile;
}
}
function couriergraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$points_per_sample = 3;
$range = $to - $from;
$rrd = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"-E",
"--lower-limit", "0",
"--units-exponent", "0",
"--title", $title,
"--vertical-label", $vertical,
"-l 0",
"--width", $width, "--height", $height,
"--start", $from, "--end", $to,
"DEF:pop3d_login=$rrd:pop3d_login:AVERAGE",
"DEF:mpop3d_login=$rrd:pop3d_login:MAX",
"DEF:imapd_login=$rrd:imapd_login:AVERAGE",
"DEF:mimapd_login=$rrd:imapd_login:MAX",
"CDEF:rpop3d_login=pop3d_login,60,*",
"CDEF:vpop3d_login=pop3d_login,UN,0,pop3d_login,IF,$range,*",
"CDEF:rmpop3d_login=mpop3d_login,60,*",
"CDEF:rimapd_login=imapd_login,60,*",
"CDEF:vimapd_login=imapd_login,UN,0,imapd_login,IF,$range,*",
"CDEF:rmimapd_login=mimapd_login,60,*",
"DEF:pop3d_ssl_login=$rrd:pop3d_ssl_login:AVERAGE",
"DEF:mpop3d_ssl_login=$rrd:pop3d_ssl_login:MAX",
"DEF:imapd_ssl_login=$rrd:imapd_ssl_login:AVERAGE",
"DEF:mimapd_ssl_login=$rrd:imapd_ssl_login:MAX",
"CDEF:rpop3d_ssl_login=pop3d_ssl_login,60,*",
"CDEF:vpop3d_ssl_login=pop3d_ssl_login,UN,0,pop3d_ssl_login,IF,$range,*",
"CDEF:rmpop3d_ssl_login=mpop3d_ssl_login,60,*",
"CDEF:rimapd_ssl_login=imapd_ssl_login,60,*",
"CDEF:rmimapd_ssl_login=mimapd_ssl_login,60,*",
"CDEF:vimapd_ssl_login=imapd_ssl_login,UN,0,imapd_ssl_login,IF,$range,*",
'LINE1.5:rpop3d_login#BB0000:pop3',
'GPRINT:vpop3d_login:AVERAGE: tot\: %5.0lf',
'GPRINT:rpop3d_login:AVERAGE:avg\: %4.0lf/min',
'GPRINT:rmpop3d_login:MAX:max\: %4.0lf/min\l',
'LINE1.5:rimapd_login#009900:imap',
'GPRINT:vimapd_login:AVERAGE: tot\: %5.0lf',
'GPRINT:rimapd_login:AVERAGE:avg\: %4.0lf/min',
'GPRINT:rmimapd_login:MAX:max\: %4.0lf/min\l',
'LINE1.5:rpop3d_ssl_login#000000:pop3-ssl',
'GPRINT:vpop3d_ssl_login:AVERAGE:tot\: %5.0lf',
'GPRINT:rpop3d_ssl_login:AVERAGE:avg\: %4.0lf/min',
'GPRINT:rmpop3d_ssl_login:MAX:max\: %4.0lf/min\l',
'LINE1.5:rimapd_ssl_login#000099:imap-ssl',
'GPRINT:vimapd_ssl_login:AVERAGE:tot\: %5.0lf',
'GPRINT:rimapd_ssl_login:AVERAGE:avg\: %4.0lf/min',
'GPRINT:rmimapd_ssl_login:MAX:max\: %4.0lf/min\l');
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function apachehitsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical ,"--alt-autoscale-max",
"-l 0",
"-E",
"--title", $title,
"DEF:hits=$database:hits:AVERAGE",
"COMMENT: Current Average Maximum\\n",
"AREA:hits#ff9933:",
"LINE1.25:hits#FF6600:Hits",
"GPRINT:hits:LAST: %6.2lf/sec",
"GPRINT:hits:AVERAGE:%6.2lf/sec",
"GPRINT:hits:MAX:%6.2lf/sec\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function unixfsgraph ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical, "--alt-autoscale-max",
"-l 0",
"-E",
"-b 1024",
"--title", $title);
$hostname = gethostbyid($device);
$imgfile = "graphs/" . "$graph";
$iter = "1";
$sql = mysql_query("SELECT * FROM storage where host_id = '$device'");
$optsa[] = "COMMENT: Size Used %age\l";
while($fs = mysql_fetch_array($sql)) {
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
} elseif($iter=="7") {$colour="FF0084"; $iter = "0"; }
$descr = str_pad($fs[hrStorageDescr], 16);
$descr = substr($descr,0,16);
$text = str_replace("/", "_", $fs['hrStorageDescr']);
$optsa[] = "DEF:$fs[storage_id]=rrd/$hostname-storage-$text.rrd:used:AVERAGE";
$optsa[] = "DEF:$fs[storage_id]s=rrd/$hostname-storage-$text.rrd:size:AVERAGE";
$optsa[] = "DEF:$fs[storage_id]p=rrd/$hostname-storage-$text.rrd:perc:AVERAGE";
$optsa[] = "LINE1.25:$fs[storage_id]p#" . $colour . ":$descr";
$optsa[] = "GPRINT:$fs[storage_id]s:LAST:%6.2lf%SB";
$optsa[] = "GPRINT:$fs[storage_id]:LAST:%6.2lf%SB";
$optsa[] = "GPRINT:$fs[storage_id]p:LAST:%3.0lf%%\l";
$iter++;
}
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
#echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function apachebitsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool; global $installdir;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical,"--alt-autoscale-max",
"-l 0",
"-E",
"--title", $title,
"DEF:bits=$database:bits:AVERAGE",
"COMMENT: Current Average Maximum\\n",
"AREA:bits#cccc00:",
"LINE1.25:bits#999900:Bits",
"GPRINT:bits:LAST:%6.2lf%sbps",
"GPRINT:bits:AVERAGE:%6.2lf%sbps",
"GPRINT:bits:MAX:%6.2lf%sbps\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function tempgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical)
{
global $rrdtool; global $installdir;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical ,"--alt-autoscale-max",
"-E", "-l 0", "--title", $title,
"DEF:cpu=$database:cputemp:AVERAGE",
"DEF:sys=$database:systemp:AVERAGE",
"LINE1.25:cpu#cc0000:CPU ",
"GPRINT:cpu:LAST:Cur\:%6.2lf",
"GPRINT:cpu:AVERAGE:Avg\: %6.2lf",
"GPRINT:cpu:MIN:Min\:%6.2lf",
"GPRINT:cpu:MAX:Max\:%6.2lf\\n",
"LINE1.25:sys#009900:System ",
"GPRINT:sys:LAST:Cur\:%6.2lf",
"GPRINT:sys:AVERAGE:Avg\: %6.2lf",
"GPRINT:sys:MIN:Min\:%6.2lf",
"GPRINT:sys:MAX:Max\:%6.2lf\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
?>
+195
View File
@@ -0,0 +1,195 @@
<?
include("unix-graphing.php");
function pollDeviceUnix() {
global $device;
global $community;
global $rrdtool;
$id = $device['id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];
$features = $device['features'];
if($device['apache'] == "1") { $apache = "yes"; }
$loadrrd = "rrd/" . $hostname . "-load.rrd";
$loadgraph = "public_html/graphs/" . $hostname . "-load.png";
$cpurrd = "rrd/" . $hostname . "-cpu.rrd";
$cpugraph = "public_html/graphs/" . $hostname . "-cpu.png";
$memrrd = "rrd/" . $hostname . "-mem.rrd";
$memgraph = "public_html/graphs/" . $hostname . "-mem.png";
$sysrrd = "rrd/" . $hostname . "-sys.rrd";
$sysgraph = "public_html/graphs/" . $hostname . "-sys.png";
## Check Disks
$dq = mysql_query("SELECT * FROM storage WHERE host_id = '$id'");
while ($dr = mysql_fetch_array($dq)) {
$hrStorageIndex = $dr['hrStorageIndex'];
$hrStorageAllocationUnits = $dr['hrStorageAllocationUnits'];
$hrStorageSize = $dr['hrStorageAllocationUnits'] * $dr['hrStorageSize'];
$hrStorageDescr = $dr['hrStorageDescr'];
$used = `snmpget -O qv -v2c -c $community $hostname hrStorageUsed.$hrStorageIndex`;
$used = $used * $hrStorageAllocationUnits;
$perc = $used / $hrStorageSize * 100;
$filedesc = str_replace("\"", "", str_replace("/", "_", $hrStorageDescr));
$storerrd = "rrd/" . $hostname . "-storage-" . $filedesc . ".rrd";
if (!is_file($storerrd)) {
`rrdtool create $storerrd \
--step 300 \
DS:size:GAUGE:600:0:U \
DS:used:GAUGE:600:0:U \
DS:perc:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
rrd_update($storerrd, "N:$hrStorageSize:$used:$perc");
}
## Set OIDs
$oid_ssCpuRawUser = ".1.3.6.1.4.1.2021.11.50.0";
$oid_ssCpuRawNice = ".1.3.6.1.4.1.2021.11.51.0";
$oid_ssCpuRawSystem = ".1.3.6.1.4.1.2021.11.52.0";
$oid_ssCpuRawIdle = ".1.3.6.1.4.1.2021.11.53.0";
$oid_hrSystemProcesses = ".1.3.6.1.2.1.25.1.6.0";
$oid_hrSystemNumUsers = ".1.3.6.1.2.1.25.1.5.0";
$s = `snmpget -O qv -v2c -c $community $hostname $oid_ssCpuRawUser $oid_ssCpuRawSystem $oid_ssCpuRawNice $oid_ssCpuRawIdle $oid_hrSystemProcesses $oid_hrSystemNumUsers .1.3.6.1.4.1.2021.1.101.1`;
list ($cpuUser, $cpuSystem, $cpuNice, $cpuIdle, $procs, $users, $cputemp) = explode("\n", $s);
## Create CPU RRD if it doesn't already exist
if (!is_file($cpurrd)) {
`rrdtool create $cpurrd \
--step 300 \
DS:user:COUNTER:600:0:U \
DS:system:COUNTER:600:0:U \
DS:nice:COUNTER:600:0:U \
DS:idle:COUNTER:600:0:U \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
rrd_update($cpurrd, "N:$cpuUser:$cpuSystem:$cpuNice:$cpuIdle");
## If the device isn't monowall or pfsense, monitor all the pretty things
if($device[os] != "m0n0wall" && $device[os] != "Voswall" && $device[os] != "pfSense" ) {
if (!is_file($sysrrd)) {
`rrdtool create $sysrrd \
--step 300 \
DS:users:GAUGE:600:0:U \
DS:procs:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
if (!is_file($memrrd)) {
`rrdtool create $memrrd \
--step 300 \
DS:totalswap:GAUGE:600:0:10000000000 \
DS:availswap:GAUGE:600:0:10000000000 \
DS:totalreal:GAUGE:600:0:10000000000 \
DS:availreal:GAUGE:600:0:10000000000 \
DS:totalfree:GAUGE:600:0:10000000000 \
DS:shared:GAUGE:600:0:10000000000 \
DS:buffered:GAUGE:600:0:10000000000 \
DS:cached:GAUGE:600:0:10000000000 \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
if(!is_file($loadrrd)) {
`$rrdtool create $loadrrd \
--step 300 \
DS:1min:GAUGE:600:0:5000 \
DS:5min:GAUGE:600:0:5000 \
DS:15min:GAUGE:600:0:5000 \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
$mem_get = "memTotalSwap.0 memAvailSwap.0 memTotalReal.0 memAvailReal.0 memTotalFree.0 memShared.0 memBuffer.0 memCached.0";
$mem_raw = `snmpget -O qv -v2c -c $community $hostname $mem_get`;
list($memTotalSwap, $memAvailSwap, $memTotalReal, $memAvailReal, $memTotalFree, $memShared, $memBuffer, $memCached) = explode("\n", $mem_raw);
$load_get = "laLoadInt.1 laLoadInt.2 laLoadInt.3";
$load_raw = `snmpget -O qv -v2c -c $community $hostname $load_get`;
list ($load1, $load5, $load10) = explode ("\n", $load_raw);
rrd_update($sysrrd, "N:$users:$procs");
rrd_update($loadrrd, "N:$load1:$load5:$load10");
rrd_update($memrrd, "N:$memTotalSwap:$memAvailSwap:$memTotalReal:$memAvailReal:$memTotalFree:$memShared:$memBuffer:$memCached");
if($device['temp'] = 1) {
$temprrd = "rrd/" . $hostname . "-temp.rrd";
$cputemp = str_replace("\"", "", $cputemp);
if (!is_file($temprrd)) {
$rrdcreate = `rrdtool create $temprrd --step 300 \
DS:cputemp:GAUGE:600:-25:125 \
DS:systemp:GAUGE:600:-25:125 \
RRA:AVERAGE:0.5:1:2000 \
RRA:AVERAGE:0.5:6:2000 \
RRA:AVERAGE:0.5:24:2000 \
RRA:AVERAGE:0.5:288:2000 \
RRA:MAX:0.5:1:2000 \
RRA:MAX:0.5:6:2000 \
RRA:MAX:0.5:24:2000 \
RRA:MAX:0.5:288:2000`;
}
rrd_update($temprrd, "N:$cputemp:0");
}
if($apache) {
$apacherrd = "rrd/" . $hostname . "-apache.rrd";
if(!is_file($apacherrd)) {
$woo= `rrdtool create $apacherrd \
DS:bits:COUNTER:600:U:10000000 \
DS:hits:COUNTER:600:U:10000000 \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797`;
}
list($ahits,$abits) = explode("\n", `./get-apache.sh $hostname`);
$abits = $abits * 8;
rrd_update($apacherrd,"N:$abits:$ahits");
}
} // End Monowall Test
}
+363
View File
@@ -0,0 +1,363 @@
<?
function pollDeviceWin() {
global $device;
global $community;
global $rrdtool;
$id = $device['id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];
$features = $device['features'];
$loadrrd = "rrd/" . $hostname . "-load.rrd";
$cpurrd = "rrd/" . $hostname . "-cpu.rrd";
$memrrd = "rrd/" . $hostname . "-mem.rrd";
$sysrrd = "rrd/" . $hostname . "-sys.rrd";
$oid_ssCpuRawUser = ".1.3.6.1.4.1.2021.11.50.0";
$oid_ssCpuRawSystem = ".1.3.6.1.4.1.2021.11.51.0";
$oid_ssCpuRawNice = ".1.3.6.1.4.1.2021.11.52.0";
$oid_ssCpuRawIdle = ".1.3.6.1.4.1.2021.11.53.0";
$oid_hrSystemProcesses = ".1.3.6.1.2.1.25.1.6.0";
$oid_hrSystemNumUsers = ".1.3.6.1.2.1.25.1.5.0";
$s = `snmpget -O qv -v2c -c $community $hostname $oid_ssCpuRawUser $oid_ssCpuRawSystem $oid_ssCpuRawNice $oid_ssCpuRawIdle $oid_hrSystemProcesses $oid_hrSystemNumUsers`;
list ($cpuUser, $cpuSystem, $cpuNice, $cpuIdle, $procs, $users) = explode("\n", $s);
if (!is_file($cpurrd)) {
`rrdtool create $cpurrd \
--step 300 \
DS:user:COUNTER:600:0:U \
DS:system:COUNTER:600:0:U \
DS:nice:COUNTER:600:0:U \
DS:idle:COUNTER:600:0:U \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
if (!is_file($sysrrd)) {
`rrdtool create $sysrrd \
--step 300 \
DS:users:GAUGE:600:0:U \
DS:procs:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
if (!is_file($memrrd)) {
`rrdtool create $memrrd \
--step 300 \
DS:totalswap:GAUGE:600:0:10000000000 \
DS:availswap:GAUGE:600:0:10000000000 \
DS:totalreal:GAUGE:600:0:10000000000 \
DS:availreal:GAUGE:600:0:10000000000 \
DS:totalfree:GAUGE:600:0:10000000000 \
DS:shared:GAUGE:600:0:10000000000 \
DS:buffered:GAUGE:600:0:10000000000 \
DS:cached:GAUGE:600:0:10000000000 \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
if(!is_file($loadrrd)) {
`$rrdtool create $loadrrd \
--step 300 \
DS:1min:GAUGE:600:0:5000 \
DS:5min:GAUGE:600:0:5000 \
DS:15min:GAUGE:600:0:5000 \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
$mem_get = "memTotalSwap.0 memAvailSwap.0 memTotalReal.0 memAvailReal.0 memTotalFree.0 memShared.0 memBuffer.0 memCached.0";
$mem_raw = `snmpget -O qv -v2c -c $community $hostname $mem_get`;
list($memTotalSwap, $memAvailSwap, $memTotalReal, $memAvailReal, $memTotalFree, $memShared, $memBuffer, $memCached) = explode("\n", $mem_raw);
$load_get = "laLoadInt.1 laLoadInt.2 laLoadInt.3";
$load_raw = `snmpget -O qv -v2c -c $community $hostname $load_get`;
list ($load1, $load5, $load10) = explode ("\n", $load_raw);
rrd_update($sysrrd, "N:$users:$procs");
rrd_update($loadrrd, "N:$load1:$load5:$load10");
rrd_update($memrrd, "N:$memTotalSwap:$memAvailSwap:$memTotalReal:$memAvailReal:$memTotalFree:$memShared:$memBuffer:$memCached");
rrd_update($cpurrd, "N:$cpuUser:$cpuSystem:$cpuNice:$cpuIdle");
}
function memgraphWin ($rrd, $graph, $from="-2d")
{
global $rrdtool;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$opts = array (
"--start",
$from,
"-v MB",
"-b 1000",
"--rigid",
"--title", "Memory Usage",
"--alt-autoscale-max",
"-l 0",
"--width", "335", "--height", "100",
"DEF:totalswap=$database:totalswap:AVERAGE",
"DEF:availswap=$database:availswap:AVERAGE",
"DEF:totalreal=$database:totalreal:AVERAGE",
"DEF:availreal=$database:availreal:AVERAGE",
"DEF:totalfree=$database:totalfree:AVERAGE",
"DEF:shared=$database:shared:AVERAGE",
"DEF:buffered=$database:buffered:AVERAGE",
"DEF:cached=$database:cached:AVERAGE",
"CDEF:usedreal=totalreal,availreal,-",
"CDEF:usedswap=totalswap,availswap,-",
"CDEF:cdeftot=availreal,shared,buffered,usedreal,cached,usedswap,+,+,+,+,+",
"AREA:usedreal#ee8000:used",
"GPRINT:usedreal:LAST: Cur\:%8.2lf %s",
"GPRINT:usedreal:AVERAGE: Avg\:%8.2lf %s",
"GPRINT:usedreal:MAX: Max\:%8.2lf %s\\n",
"STACK:shared#ec9900:shared",
"GPRINT:shared:LAST: Cur\:%8.2lf %s",
"GPRINT:shared:AVERAGE: Avg\:%8.2lf %s",
"GPRINT:shared:MAX: Max\:%8.2lf %s\\n",
"STACK:availreal#eacc00:free",
"GPRINT:availreal:LAST: Cur\:%8.2lf %s",
"GPRINT:availreal:AVERAGE: Avg\:%8.2lf %s",
"GPRINT:availreal:MAX: Max\:%8.2lf %s\\n",
"STACK:buffered#cc0000:buffers",
"GPRINT:buffered:LAST:Cur\:%8.2lf %s",
"GPRINT:buffered:AVERAGE: Avg\:%8.2lf %s",
"GPRINT:buffered:MAX: Max\:%8.2lf %s\\n",
"STACK:cached#9fa4ee:cached",
"GPRINT:cached:LAST: Cur\:%8.2lf %s",
"GPRINT:cached:AVERAGE: Avg\:%8.2lf %s",
"GPRINT:cached:MAX: Max\:%8.2lf %s\\n",
"STACK:usedswap#afeced:swap",
"GPRINT:usedswap:LAST: Cur\:%8.2lf %s",
"GPRINT:usedswap:AVERAGE: Avg\:%8.2lf %s",
"GPRINT:usedswap:MAX: Max\:%8.2lf %s",
"LINE1:totalreal#050505:total");
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function loadgraphWin ($rrd, $graph, $from="-2d") {
global $rrdtool;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$opts = array(
"--title", "Load Averages",
"--start",
$from,
"-v Load",
"--rigid",
"--alt-autoscale-max",
"-l 0",
"--width", "335", "--height", "100",
"DEF:1min=$database:1min:AVERAGE",
"DEF:5min=$database:5min:AVERAGE",
"DEF:15min=$database:15min:AVERAGE",
"CDEF:a=1min,100,/",
"CDEF:b=5min,100,/",
"CDEF:c=15min,100,/",
"CDEF:cdefd=a,b,c,+,+",
"AREA:a#eacc00:1 Minute:",
"LINE1:a#c5aa00:",
"GPRINT:a:LAST: Cur\:%8.2lf %s",
"GPRINT:a:AVERAGE: Ave\:%8.2lf %s",
"GPRINT:a:MAX: Max\:%8.2lf %s\\n",
"LINE1.5:b#ea8f00:5 Minute:",
"GPRINT:b:LAST: Cur\:%8.2lf %s",
"GPRINT:b:AVERAGE: Ave\:%8.2lf %s",
"GPRINT:b:MAX: Max\:%8.2lf %s\\n",
"LINE1.5:c#cc0000:15 Minute",
"GPRINT:c:LAST:Cur\:%8.2lf %s",
"GPRINT:c:AVERAGE: Ave\:%8.2lf %s",
"GPRINT:c:MAX: Max\:%8.2lf %s\\n");
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function usersgraphWin ($rrd, $graph, $from="-2d") {
global $rrdtool;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$opts = array(
"--title", "Logged on Users",
"--vertical-label", "Users",
"-l 0",
"--width", "335", "--height", "100",
"--start",
$from,
"DEF:users=$database:users:AVERAGE",
"AREA:users#eacc00:users",
"LINE1.5:users#cc0000:",
"GPRINT:users:LAST: Cur\:%3.0lf %s",
"GPRINT:users:AVERAGE: Avg\:%3.0lf %s",
"GPRINT:users:MIN: Min\:%3.0lf %s",
"GPRINT:users:MAX: Max\:%3.0lf %s\\n");
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function procsgraphWin ($rrd, $graph, $from="-2d") {
global $rrdtool;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$opts = array(
"-v # Processes",
"--title", "Running Processes",
"--vertical-label", "procs",
"-l 0",
"--width", "335", "--height", "100",
"--start",
$from,
"DEF:procs=$database:procs:AVERAGE",
"AREA:procs#eacc00:Processes",
"LINE1.5:procs#cc0000:",
"GPRINT:procs:LAST: Cur\:%3.0lf %s",
"GPRINT:procs:AVERAGE: Avg\:%3.0lf %s",
"GPRINT:procs:MIN: Min\:%3.0lf %s",
"GPRINT:procs:MAX: Max\:%3.0lf %s\\n");
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function cpugraphWin ($rrd, $graph, $from="-2d") {
global $rrdtool;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$opts = array(
"-v CPU Utilization",
"--title", "Processor Usage",
"-u 100",
"--rigid",
"--vertical-label", "Load (%)",
"-l 0",
"--width", "335", "--height", "100",
"--start",
$from,
"DEF:user=$database:user:AVERAGE",
"DEF:nice=$database:nice:AVERAGE",
"DEF:system=$database:system:AVERAGE",
"DEF:idle=$database:idle:AVERAGE",
"CDEF:total=user,nice,system,idle,+,+,+",
"CDEF:user_perc=user,total,/,100,*",
"CDEF:nice_perc=nice,total,/,100,*",
"CDEF:system_perc=system,total,/,100,*",
"CDEF:idle_perc=idle,total,/,100,*",
"AREA:user_perc#eacc00:user",
"GPRINT:user_perc:LAST: Cur\:%3.0lf%%",
"GPRINT:user_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:user_perc:MAX: Max\:%3.0lf%%\\n",
"AREA:nice_perc#ea8f00:system:STACK",
"GPRINT:nice_perc:LAST:Cur\:%3.0lf%%",
"GPRINT:nice_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:nice_perc:MAX: Max\:%3.0lf%%\\n",
"AREA:system_perc#ff3932:nice:STACK",
"GPRINT:system_perc:LAST: Cur\:%3.0lf%%",
"GPRINT:system_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:system_perc:MAX: Max\:%3.0lf%%\\n",
"AREA:idle_perc#fafdce:idle:STACK",
"GPRINT:idle_perc:LAST: Cur\:%3.0lf%%",
"GPRINT:idle_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:idle_perc:MAX: Max\:%3.0lf%%\\n");
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
return FALSE;
} else {
return $imgfile;
}
}
function storagegraphWin ($rrd, $graph, $from="-2d", $descr)
{
global $rrdtool;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$opts = array (
"--start",
$from,
"-v MB",
"-b 1024",
"--rigid",
"--title", $descr,
"--alt-autoscale-max",
"-l 0",
"--width", "335", "--height", "100",
"DEF:size=$database:size:AVERAGE",
"DEF:used=$database:used:AVERAGE",
"AREA:size#80ee80:Total",
"GPRINT:size:LAST:Cur\:%8.2lf %s",
"GPRINT:size:AVERAGE: Avg\:%8.2lf %s",
"GPRINT:size:MAX: Max\:%8.2lf %s\\n",
"AREA:used#ec9900:Used",
"GPRINT:used:LAST: Cur\:%8.2lf %s",
"GPRINT:used:AVERAGE: Avg\:%8.2lf %s",
"GPRINT:used:MAX: Max\:%8.2lf %s\\n",
"LINE1:size#000000:");
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
?>