From 08335d57482499639575a2d52b50484367f3b48c Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 10 Nov 2017 16:36:29 -0600 Subject: [PATCH 1/2] feature: track rrdtool time for poller --- includes/functions.php | 52 ++++++++++++++++++++++++++++++++++++---- includes/rrdtool.inc.php | 3 +++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 3f64c342c83e..ab3e5d217987 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -2009,7 +2009,7 @@ function get_toner_levels($device, $raw_value, $capacity) */ function initStats() { - global $snmp_stats, $db_stats; + global $snmp_stats, $db_stats, $rrd_stats; if (!isset($snmp_stats)) { $snmp_stats = array( @@ -2040,6 +2040,17 @@ function initStats() 'fetchrows_sec' => 0.0, ); } + + if (!isset($rrd_stats)) { + $rrd_stats = array( + 'update' => 0, + 'update_sec' => 0.0, + 'create' => 0, + 'create_sec' => 0.0, + 'other' => 0, + 'other_sec' => 0.0, + ); + } } /** @@ -2047,10 +2058,11 @@ function initStats() */ function printStats() { - global $snmp_stats, $db_stats; + global $snmp_stats, $db_stats, $rrd_stats; printf( - "SNMP: Get[%d/%.2fs] Getnext [%d/%.2fs] Walk [%d/%.2fs]\n", + "SNMP %.2fs: Get[%d/%.2fs] Getnext [%d/%.2fs] Walk [%d/%.2fs]\n", + $snmp_stats['snmpget_sec'] + $snmp_stats['snmpgetnext_sec'] + $snmp_stats['snmpwalk_sec'], $snmp_stats['snmpget'], $snmp_stats['snmpget_sec'], $snmp_stats['snmpgetnext'], @@ -2059,7 +2071,8 @@ function printStats() $snmp_stats['snmpwalk_sec'] ); printf( - "MySQL: Cell[%d/%.2fs] Row[%d/%.2fs] Rows[%d/%.2fs] Column[%d/%.2fs] Update[%d/%.2fs] Insert[%d/%.2fs] Delete[%d/%.2fs]\n", + "MySQL %.2fs: Cell[%d/%.2fs] Row[%d/%.2fs] Rows[%d/%.2fs] Column[%d/%.2fs] Update[%d/%.2fs] Insert[%d/%.2fs] Delete[%d/%.2fs]\n", + $db_stats['fetchcell_sec'] + $db_stats['fetchrow_sec'] + $db_stats['fetchrows_sec'] + $db_stats['fetchcolumn_sec'] + $db_stats['update_sec'] + $db_stats['insert_sec'] + $db_stats['delete_sec'], $db_stats['fetchcell'], $db_stats['fetchcell_sec'], $db_stats['fetchrow'], @@ -2075,6 +2088,37 @@ function printStats() $db_stats['delete'], $db_stats['delete_sec'] ); + printf( + "RRD %.2fs: Update [%d/%.2fs] Create [%d/%.2fs] Other [%d/%.2fs]\n", + $rrd_stats['update_sec'] + $rrd_stats['create_sec'] + $rrd_stats['other_sec'], + $rrd_stats['update'], + $rrd_stats['update_sec'], + $rrd_stats['create'], + $rrd_stats['create_sec'], + $rrd_stats['other'], + $rrd_stats['other_sec'] + ); +} + +/** + * Update statistics for rrd operations + * + * @param string $stat create, update, and other + * @param float $start_time The time the operation started with 'microtime(true)' + * @return float The calculated run time + */ +function recordRrdStatistic($stat, $start_time) +{ + global $rrd_stats; + initStats(); + + var_dump($stat); + $stat = ($stat == 'update' || $stat == 'create') ? $stat : 'other'; + $runtime = microtime(true) - $start_time; + $rrd_stats[$stat]++; + $rrd_stats["${stat}_sec"] += $runtime; + + return $runtime; } /** diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php index b9b2838b9f75..922451d5fb3b 100644 --- a/includes/rrdtool.inc.php +++ b/includes/rrdtool.inc.php @@ -135,6 +135,8 @@ function rrdtool($command, $filename, $options) /** @var Proc $rrd_sync_process */ /** @var Proc $rrd_async_process */ + $start_time = microtime(true); + try { $cmd = rrdtool_build_command($command, $filename, $options); } catch (FileExistsException $e) { @@ -168,6 +170,7 @@ function rrdtool($command, $filename, $options) echo $output[1]; } + recordRrdStatistic($command, $start_time); return $output; } From 15d42d9dd81fd467e331ca0fbeea9a12d1d7bd12 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sat, 11 Nov 2017 19:27:10 +0000 Subject: [PATCH 2/2] Removed var_dump() --- includes/functions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/functions.php b/includes/functions.php index ab3e5d217987..faf1dab5e014 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -2112,7 +2112,6 @@ function recordRrdStatistic($stat, $start_time) global $rrd_stats; initStats(); - var_dump($stat); $stat = ($stat == 'update' || $stat == 'create') ? $stat : 'other'; $runtime = microtime(true) - $start_time; $rrd_stats[$stat]++;