From 1ff2a8c8102dfa35113240d5fe017063c8ae1b8c Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Tue, 14 Oct 2014 12:16:34 +0200 Subject: [PATCH] refactor queuelength munin graph to show individual values as an AREASTACK graph. --- ykval-munin-queuelength.php | 49 +++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/ykval-munin-queuelength.php b/ykval-munin-queuelength.php index 1779cd4..ac50acc 100755 --- a/ykval-munin-queuelength.php +++ b/ykval-munin-queuelength.php @@ -1,7 +1,7 @@ #!/usr/bin/php addField('ip', $_SERVER['REMOTE_ADDR']); + +$db = Db::GetDatabaseHandle($baseParams, 'ykval-munin-queuelength'); +if (!$db->connect()) { + logdie($myLog, 'ERROR Database connect error (1)'); } -$len = $sync->getQueueLength (); -echo "queuelength.value $len\n"; +$res = $db->customQuery('select server,count(server) as count from queue group by server'); +if ($res) { + $r = $res->fetchAll(PDO::FETCH_ASSOC); +} else { + logdie($myLog, 'ERROR getting data from db'); +} + +foreach ($shortnames as $shortname) { + $count = 0; + foreach ($r as $result) { + if(strpos($result['server'], "$shortname.") !== FALSE) { + $count = $result['count']; + break; + } + } + echo "queuelength_${shortname}.value $count\n"; +} #%# family=auto #%# capabilities=autoconf