From 9a178363a008f1dfda0408e92c5189cfc201f8ad Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 29 Sep 2014 23:03:59 +0100 Subject: [PATCH] Added ping response graphs and some small updates --- html/includes/graphs/device/ping_perf.inc.php | 27 +++++++++++++++++++ html/pages/device/graphs.inc.php | 1 + includes/definitions.inc.php | 5 +++- includes/functions.php | 20 ++++++++++---- includes/polling/functions.inc.php | 19 +++++++++++-- 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 html/includes/graphs/device/ping_perf.inc.php diff --git a/html/includes/graphs/device/ping_perf.inc.php b/html/includes/graphs/device/ping_perf.inc.php new file mode 100644 index 0000000000..cbbb48d622 --- /dev/null +++ b/html/includes/graphs/device/ping_perf.inc.php @@ -0,0 +1,27 @@ + + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +$scale_min = "0"; + +include("includes/graphs/common.inc.php"); + +$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/ping-perf.rrd"; + +$rrd_options .= " DEF:ping=".$rrd_filename.":ping:AVERAGE"; +$rrd_options .= " 'COMMENT:Seconds Current Minimum Maximum Average\\n'"; +$rrd_options .= " LINE1.25:ping#36393D:Ping"; +$rrd_options .= " GPRINT:ping:LAST:%6.2lf GPRINT:ping:AVERAGE:%6.2lf"; +$rrd_options .= " GPRINT:ping:MAX:%6.2lf 'GPRINT:ping:AVERAGE:%6.2lf\\n'"; + +?> diff --git a/html/pages/device/graphs.inc.php b/html/pages/device/graphs.inc.php index 59df21e747..3be4ad7e73 100644 --- a/html/pages/device/graphs.inc.php +++ b/html/pages/device/graphs.inc.php @@ -25,6 +25,7 @@ foreach (dbFetchRows("SELECT * FROM device_graphs WHERE device_id = ? ORDER BY g // These are standard graphs we should have for all systems $graph_enable['poller']['poller_perf'] = 'device_poller_perf'; +$graph_enable['poller']['ping_perf'] = 'device_ping_perf'; #foreach ($config['graph_sections'] as $section) foreach ($graph_enable as $section => $nothing) diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 556494faeb..ac2b2c8a2f 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -1060,7 +1060,10 @@ $config['graph_types']['device']['uptime']['order'] = '0'; $config['graph_types']['device']['uptime']['descr'] = 'System Uptime'; $config['graph_types']['device']['poller_perf']['section'] = 'poller'; $config['graph_types']['device']['poller_perf']['order'] = '0'; -$config['graph_types']['device']['poller_perf']['descr'] = 'Poller Performance'; +$config['graph_types']['device']['poller_perf']['descr'] = 'Poller Time'; +$config['graph_types']['device']['ping_perf']['section'] = 'poller'; +$config['graph_types']['device']['ping_perf']['order'] = '0'; +$config['graph_types']['device']['ping_perf']['descr'] = 'Ping Response'; $config['graph_types']['device']['vpdn_sessions_l2tp']['section'] = 'vpdn'; $config['graph_types']['device']['vpdn_sessions_l2tp']['order'] = '0'; diff --git a/includes/functions.php b/includes/functions.php index 872b6b65fb..5371621d35 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -459,23 +459,33 @@ function isSNMPable($device) } } -function isPingable($hostname) +function isPingable($hostname,$device_id) { global $config; - $status = shell_exec($config['fping'] . " $hostname 2>/dev/null"); + $status = shell_exec($config['fping'] . " -e $hostname 2>/dev/null"); if (strstr($status, "alive")) { - return TRUE; + if(is_numeric($device_id) && !empty($device_id)) + { + preg_match('/(\d+\.*\d*) (ms)/', $status, $time); + $response['last_ping_timetaken'] = $time[1]; + $response['result'] = TRUE; + } + else + { + $response['result'] = TRUE; + } } else { $status = shell_exec($config['fping6'] . " $hostname 2>/dev/null"); if (strstr($status, "alive")) { - return TRUE; + $response['result'] = TRUE; } else { - return FALSE; + $response['result'] = FALSE; } } + return($response); } function is_odd($number) diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index e64b94bd8a..6eb655f47b 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -110,7 +110,9 @@ function poll_device($device, $options) $host_rrd = $config['rrd_dir'] . "/" . $device['hostname']; if (!is_dir($host_rrd)) { mkdir($host_rrd); echo("Created directory : $host_rrd\n"); } - $device['pingable'] = isPingable($device['hostname']); + $ping_response = isPingable($device['hostname'],$device['device_id']); + $device['pingable'] = $ping_response['result']; + $ping_time = $ping_response['last_ping_timetaken']; if ($device['pingable']) { $device['snmpable'] = isSNMPable($device); @@ -196,6 +198,7 @@ function poll_device($device, $options) $device_end = utime(); $device_run = $device_end - $device_start; $device_time = substr($device_run, 0, 5); + // Poller performance rrd $poller_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/poller-perf.rrd"; if (!is_file($poller_rrd)) { @@ -203,11 +206,23 @@ function poll_device($device, $options) } if(!empty($device_time)) { - rrdtool_update($poller_rrd, "N:".$device_time); + rrdtool_update($poller_rrd, "N:$device_time"); + } + // Ping response rrd + $ping_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/ping-perf.rrd"; + if (!is_file($ping_rrd)) + { + rrdtool_create ($ping_rrd, "DS:ping:GAUGE:600:0:65535 ".$config['rrd_rra']); + } + if(!empty($ping_time)) + { + rrdtool_update($ping_rrd, "N:$ping_time"); } $update_array['last_polled'] = array('NOW()'); $update_array['last_polled_timetaken'] = $device_time; + $update_array['last_ping'] = array('NOW()'); + $update_array['last_ping_timetaken'] = $ping_time; #echo("$device_end - $device_start; $device_time $device_run"); echo("Polled in $device_time seconds\n");