split netstats pollers into protocols. update $graphs array for each one successfully polled

git-svn-id: http://www.observium.org/svn/observer/trunk@1501 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2010-07-28 12:59:59 +00:00
parent 0473ff752b
commit 29f5afa472
12 changed files with 304 additions and 131 deletions

View File

@@ -4,17 +4,17 @@
// Generic System Statistics
$hrSystem_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/hrSystem.rrd";
$hrSystem_cmd = $config['snmpget'] . " -M ".$config['mibdir']." -m HOST-RESOURCES-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
$hrSystem_cmd .= " hrSystemProcesses.0 hrSystemNumUsers.0 hrMemorySize.0";
$hrSystem = `$hrSystem_cmd`;
list ($hrSystemProcesses, $hrSystemNumUsers, $hrMemorySize) = explode("\n", $hrSystem);
if (!is_file($hrSystem_rrd)) {
shell_exec($config['rrdtool'] . " create $hrSystem_rrd \
$oid_list = "hrSystemProcesses.0 hrSystemNumUsers.0";
$hrSystem = snmp_get_multi ($device, $oid_list, "-OUQs", "HOST-RESOURCES-MIB");
if(isset($hrSystem[0]['hrSystemProcesses']))
{
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/hr-processes.rrd";
if (!is_file($rrd_file)) {
shell_exec($config['rrdtool'] . " create $rrd_file \
--step 300 \
DS:users:GAUGE:600:0:U \
DS:procs:GAUGE:600:0:U \
DS:uptime:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
@@ -23,9 +23,30 @@ if (!is_file($hrSystem_rrd)) {
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800");
}
rrdtool_update($rrd_file, "N:$hrSystemProcesses");
$graphs['hrprocesses'] = TRUE;
}
rrdtool_update($hrSystem_rrd, "N:$hrSystemNumUsers:$hrSystemProcesses:$uptime");
if(isset($hrSystem[0]['hrSystemNumUsers']))
{
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/hr-users.rrd";
if (!is_file($rrd_file)) {
shell_exec($config['rrdtool'] . " create $rrd_file \
--step 300 \
DS:users: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");
}
rrdtool_update($rrd_file, "N:$hrSystemNumUsers");
$graphs['hrusers'] = TRUE;
}
?>

View File

@@ -1,45 +0,0 @@
<?php
/// HOST-RESOURCES-MIB - Storage Objects
$dq = mysql_query("SELECT * FROM storage WHERE device_id = '" . $device['device_id'] . "'");
while ($dr = mysql_fetch_array($dq)) {
$storage_index = $dr['storage_index'];
$storage_units = $dr['storage_units'];
$storage_size = $dr['storage_units'] * $dr['storage_size'];
$storage_descr = $dr['storage_descr'];
$cmd = $config['snmpget'] . " -M ".$config['mibdir']. " -m HOST-RESOURCES-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " storage_used.$storage_index";
$used_units = trim(shell_exec($cmd));
$used = $used_units * $storage_units;
$perc = round($used / $storage_size * 100, 2);
$filedesc = str_replace("\"", "", str_replace("/", "_", $storage_descr));
$old_storage_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("storage-" . $filedesc . ".rrd");
$storage_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("hrStorage-" . $storage_index . ".rrd");
if(is_file($old_storage_rrd)) { rename($old_storage_rrd,$storage_rrd); }
if (!is_file($storage_rrd)) {
shell_exec($config['rrdtool'] . " create $storage_rrd \
--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");
}
rrdtool_update($storage_rrd, "N:$storage_size:$used:$perc");
mysql_query("UPDATE `storage` SET `storage_used` = '$used_units', `storage_perc` = '$perc' WHERE storage_id = '" . $dr['storage_id'] . "'");
if (!is_numeric($dr['storage_perc_warn'])) { $dr['storage_perc_warn'] = 60; }
if($dr['storage_perc'] < $dr['storage_perc_warn'] && $perc >= $dr['storage_perc_warn'])
{
$msg = "Disk Alarm: " . $device['hostname'] . " " . $dr['storage_descr'] . " is " . $perc . "% at " . date($config['timestamp_format']);
notify($device, "Disk Alarm: " . $device['hostname'] . " " . $dr['storage_descr'], $msg);
echo("Alerting for " . $device['hostname'] . " " . $dr['storage_descr'] . "\n");
}
}

View File

@@ -88,6 +88,11 @@
if(!file_exists($rrdfile)) { shell_exec($rrd_create); }
rrdtool_update($rrdfile, $rrdupdate);
unset($rrdupdate, $rrd_create);
## FIXME per-AF?
$graphs['ipSystemStats'] = TRUE;
}
}

View File

@@ -51,7 +51,6 @@ while($mempool = mysql_fetch_array($mempool_data)) {
mysql_query($update_query);
if($debug) { echo($update_query); }
}
unset($mempool_cache);

View File

@@ -0,0 +1,52 @@
<?php
if($device[os] != "Snom") {
echo(" ICMP");
#### Below have more oids, and are in trees by themselves, so we can snmpwalk_cache_oid them
$oids = array('icmpInMsgs','icmpOutMsgs','icmpInErrors','icmpOutErrors','icmpInEchos','icmpOutEchos','icmpInEchoReps',
'icmpOutEchoReps','icmpInDestUnreachs','icmpOutDestUnreachs','icmpInParmProbs','icmpInTimeExcds',
'icmpInSrcQuenchs','icmpInRedirects','icmpInTimestamps','icmpInTimestampReps','icmpInAddrMasks',
'icmpInAddrMaskReps','icmpOutTimeExcds','icmpOutParmProbs','icmpOutSrcQuenchs','icmpOutRedirects',
'icmpOutTimestamps','icmpOutTimestampReps','icmpOutAddrMasks','icmpOutAddrMaskReps');
unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create);
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-icmp.rrd";
$rrd_create = "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";
foreach($oids as $oid){
$oid_ds = truncate($oid, 19, '');
$rrd_create .= " DS:$oid_ds:COUNTER:600:U:100000000000";
$snmpstring .= " $oid.0";
}
$data_array = snmpwalk_cache_oid($device, "icmp", array());
$rrdupdate = "N";
foreach($oids as $oid){
if(is_numeric($data_array[$device['device_id']][0][$oid])) {
$value = $data_array[$device['device_id']][0][$oid];
} else {
$value = "0";
}
$rrdupdate .= ":$value";
}
unset($snmpstring);
if(isset($data_array[$device['device_id']][0]['icmpInMsgs']) && isset($data_array[$device['device_id']][0]['icmpOutMsgs'])) {
if(!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); }
rrdtool_update($rrd_file, $rrdupdate);
$graphs['netstats-icmp'] = TRUE;
}
unset($oids, $data, $data_array, $oid, $protos);
}
?>

View File

@@ -0,0 +1,52 @@
<?php
if($device[os] != "Snom") {
echo(" IP");
#### These are at the start of large trees that we don't want to walk the entirety of, so we snmp_get_multi them
$oids = array ('ipForwDatagrams','ipInDelivers','ipInReceives','ipOutRequests','ipInDiscards','ipOutDiscards','ipOutNoRoutes',
'ipReasmReqds','ipReasmOKs','ipReasmFails','ipFragOKs','ipFragFails','ipFragCreates', 'ipInUnknownProtos',
'ipInHdrErrors', 'ipInAddrErrors');
unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create);
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-ip.rrd";
$rrd_create = "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";
foreach($oids as $oid){
$oid_ds = truncate($oid, 19, '');
$rrd_create .= " DS:$oid_ds:COUNTER:600:U:100000000000";
$snmpstring .= " $oid.0";
}
$data = snmp_get_multi($device, $snmpstring);
$rrdupdate = "N";
foreach($oids as $oid){
if(is_numeric($data[0][$oid]))
{
$value = $data[0][$oid];
} else {
$value = "0";
}
$rrdupdate .= ":$value";
}
print_r($data);
if(isset($data[0]['ipOutRequests']) && isset($data[0]['ipInReceives'])) {
if(!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); }
rrdtool_update($rrd_file, $rrdupdate);
$graphs['netstats-ip'] = TRUE;
}
}
unset($oids, $data, $data_array, $oid);
?>

View File

@@ -0,0 +1,47 @@
<?php
if($device[os] != "Snom") {
echo(" SNMP");
#### Below have more oids, and are in trees by themselves, so we can snmpwalk_cache_oid them
$oids = array ('snmpInPkts','snmpOutPkts','snmpInBadVersions','snmpInBadCommunityNames','snmpInBadCommunityUses','snmpInASNParseErrs',
'snmpInTooBigs','snmpInNoSuchNames','snmpInBadValues','snmpInReadOnlys','snmpInGenErrs','snmpInTotalReqVars','snmpInTotalSetVars',
'snmpInGetRequests','snmpInGetNexts','snmpInSetRequests','snmpInGetResponses','snmpInTraps','snmpOutTooBigs','snmpOutNoSuchNames',
'snmpOutBadValues','snmpOutGenErrs','snmpOutGetRequests','snmpOutGetNexts','snmpOutSetRequests','snmpOutGetResponses','snmpOutTraps','snmpSilentDrops','snmpProxyDrops');
unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create);
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("netstats-snmp.rrd");
$rrd_create = "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";
foreach($oids as $oid){
$oid_ds = truncate($oid, 19, '');
$rrd_create .= " DS:$oid_ds:COUNTER:600:U:100000000000";
}
$data_array = snmpwalk_cache_oid($device, "snmp", array());
$rrdupdate = "N";
foreach($oids as $oid){
if(is_numeric($data_array[$device['device_id']][0][$oid])) {
$value = $data_array[$device['device_id']][0][$oid];
} else {
$value = "0";
}
$rrdupdate .= ":$value";
}
if(isset($data_array[$device['device_id']][0]['snmpInPkts']) && isset($data_array[$device['device_id']][0]['snmpOutPkts'])) {
if(!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); }
rrdtool_update($rrd_file, $rrdupdate);
$graphs['netstats-snmp'] = TRUE;
}
unset($oids, $data, $data_array, $oid, $protos);
}
?>

View File

@@ -0,0 +1,54 @@
<?php
if($device[os] != "Snom") {
echo(" TCP");
$oids = array ('tcpActiveOpens', 'tcpPassiveOpens', 'tcpAttemptFails', 'tcpEstabResets', 'tcpCurrEstab',
'tcpInSegs', 'tcpOutSegs', 'tcpRetransSegs', 'tcpInErrs', 'tcpOutRsts');
# $oids['tcp_collect'] = $oids['tcp'];
# $oids['tcp_collect'][] = 'tcpHCInSegs';
# $oids['tcp_collect'][] = 'tcpHCOutSegs';
unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create);
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-tcp.rrd";
$rrd_create = "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";
foreach($oids as $oid){
$oid_ds = truncate($oid, 19, '');
$rrd_create .= " DS:$oid_ds:COUNTER:600:U:10000000"; ## Limit to 10MPPS
$snmpstring .= " $oid.0";
}
$snmpstring .= " tcpHCInSegs.0";
$snmpstring .= " tcpHCOutSegs.0";
$data = snmp_get_multi($device, $snmpstring);
$rrdupdate = "N";
foreach($oids as $oid){
if(is_numeric($data[0][$oid]))
{
$value = $data[0][$oid];
} else {
$value = "0";
}
$rrdupdate .= ":$value";
}
unset($snmpstring);
if(isset($data[0]['tcpInSegs']) && isset($data[0]['tcpOutSegs'])) {
if(!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); }
rrdtool_update($rrd_file, $rrdupdate);
$graphs['netstats-tcp'] = TRUE;
}
unset($oids, $data, $data_array, $oid, $protos);
}
?>

View File

@@ -0,0 +1,45 @@
<?php
if($device[os] != "Snom") {
echo(" UDP");
#### These are at the start of large trees that we don't want to walk the entirety of, so we snmpget_multi them
$oids = array ('udpInDatagrams','udpOutDatagrams','udpInErrors','udpNoPorts');
unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create);
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-udp.rrd";
$rrd_create = "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";
foreach($oids as $oid){
$oid_ds = truncate($oid, 19, '');
$rrd_create .= " DS:$oid_ds:COUNTER:600:U:1000000"; ## Limit to 1MPPS?
$snmpstring .= " $oid.0";
}
$data = snmp_get_multi($device, $snmpstring);
$rrdupdate = "N";
foreach($oids as $oid){
if(is_numeric($data[0][$oid]))
{
$value = $data[0][$oid];
} else {
$value = "0";
}
$rrdupdate .= ":$value";
}
if(isset($data[0]['udpInDatagrams']) && isset($data[0]['udpOutDatagrams'])) {
if(!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); }
rrdtool_update($rrd_file, $rrdupdate);
$graphs['netstats-udp'] = TRUE;
}
}
unset($oids, $data, $data_array, $oid, $protos, $snmpstring);
?>

View File

@@ -1,82 +1,13 @@
<?php
if($device[os] != "Snom") {
echo("Polling Netstats:");
echo("Polling device network statistics...\n");
include("netstats-ip.inc.php");
include("netstats-tcp.inc.php");
include("netstats-udp.inc.php");
include("netstats-icmp.inc.php");
include("netstats-snmp.inc.php");
#### These are at the start of large trees that we don't want to walk the entirety of, so we snmpget_multi them
$oids = array();
$oids['ip'] = array ('ipForwDatagrams','ipInDelivers','ipInReceives','ipOutRequests','ipInDiscards','ipOutDiscards','ipOutNoRoutes',
'ipReasmReqds','ipReasmOKs','ipReasmFails','ipFragOKs','ipFragFails','ipFragCreates', 'ipInUnknownProtos',
'ipInHdrErrors', 'ipInAddrErrors');
$oids['tcp'] = array ('tcpActiveOpens', 'tcpPassiveOpens', 'tcpAttemptFails', 'tcpEstabResets', 'tcpCurrEstab',
'tcpInSegs', 'tcpOutSegs', 'tcpRetransSegs', 'tcpInErrs', 'tcpOutRsts');
$oids['udp'] = array ('udpInDatagrams','udpOutDatagrams','udpInErrors','udpNoPorts');
$oids['tcp_collect'] = $oids['tcp'];
$oids['tcp_collect'][] = 'tcpHCInSegs';
$oids['tcp_collect'][] = 'tcpHCOutSegs';
#### Below have more oids, and are in trees by themselves, so we can snmpwalk_cache_oid them
$oids['icmp'] = array('icmpInMsgs','icmpOutMsgs','icmpInErrors','icmpOutErrors','icmpInEchos','icmpOutEchos','icmpInEchoReps',
'icmpOutEchoReps','icmpInDestUnreachs','icmpOutDestUnreachs','icmpInParmProbs','icmpInTimeExcds',
'icmpInSrcQuenchs','icmpInRedirects','icmpInTimestamps','icmpInTimestampReps','icmpInAddrMasks',
'icmpInAddrMaskReps','icmpOutTimeExcds','icmpOutParmProbs','icmpOutSrcQuenchs','icmpOutRedirects',
'icmpOutTimestamps','icmpOutTimestampReps','icmpOutAddrMasks','icmpOutAddrMaskReps');
$oids['snmp'] = array ('snmpInPkts','snmpOutPkts','snmpInBadVersions','snmpInBadCommunityNames','snmpInBadCommunityUses','snmpInASNParseErrs',
'snmpInTooBigs','snmpInNoSuchNames','snmpInBadValues','snmpInReadOnlys','snmpInGenErrs','snmpInTotalReqVars','snmpInTotalSetVars',
'snmpInGetRequests','snmpInGetNexts','snmpInSetRequests','snmpInGetResponses','snmpInTraps','snmpOutTooBigs','snmpOutNoSuchNames',
'snmpOutBadValues','snmpOutGenErrs','snmpOutGetRequests','snmpOutGetNexts','snmpOutSetRequests','snmpOutGetResponses','snmpOutTraps','snmpSilentDrops','snmpProxyDrops');
$protos = array('ip','icmp', 'snmp', 'udp', 'tcp');
foreach($protos as $proto) {
unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create);
$rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("netstats-".$proto.".rrd");
$rrd_create = $config['rrdtool'] . " create $rrdfile ";
$rrd_create .= "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";
foreach($oids[$proto] as $oid){
$oid_ds = truncate($oid, 19, '');
$rrd_create .= " DS:$oid_ds:COUNTER:600:U:100000000000";
$snmpstring .= " $oid.0";
}
if(!file_exists($rrdfile)) { shell_exec($rrd_create); }
if($proto == "ip" || $proto == "tcp" || $proto == "udp")
{
$data = snmp_get_multi($device, $snmpstring);
} else {
$data_array = snmpwalk_cache_oid($device, $proto, array());
}
$rrdupdate = "N";
foreach($oids[$proto] as $oid){
if(is_numeric($data[0][$oid]))
{
$value = $data[0][$oid];
} elseif(is_numeric($data_array[$device['device_id']][0][$oid])) {
$value = $data_array[$device['device_id']][0][$oid];
} else {
$value = "0";
}
$rrdupdate .= ":$value";
}
unset($snmpstring);
rrdtool_update($rrdfile, $rrdupdate);
}
unset($oids, $data, $data_array, $oid, $protos);
}
echo("\n");
?>

View File

@@ -2,6 +2,8 @@
$storage_cache = array();
echo("Storage: ");
$query = "SELECT * FROM storage WHERE device_id = '" . $device['device_id'] . "'";
$storage_data = mysql_query($query);
while($storage = mysql_fetch_array($storage_data)) {
@@ -54,4 +56,6 @@ while($storage = mysql_fetch_array($storage_data)) {
unset($storage);
echo("\n");
?>

View File

@@ -42,6 +42,9 @@ if ($device['type'] == 'network')
}
rrdtool_update($wificlientsrrd,"N:".$wificlients1);
$graphs['airport_wireless'] = TRUE;
}
if (isset($wificlients2) && $wificlients2 != "")
@@ -59,8 +62,13 @@ if ($device['type'] == 'network')
}
rrdtool_update($wificlientsrrd,"N:".$wificlients2);
$graphs['airport_wireless'] = TRUE;
}
unset($wificlients2, $wificlients1);
}
echo "\n";