2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/sphinx/sphinx_queries

63 lines
1.6 KiB
Plaintext
Raw Normal View History

2012-05-24 13:27:52 +02:00
#!/usr/bin/php
<?php
/**
* @author: Konstantin Kuklin <konstantin.kuklin@gmail.com>
* Date: 24.05.12
*/
2013-11-27 15:03:06 +01:00
$host = getenv('host');
$port = getenv('port');
2012-05-24 13:27:52 +02:00
2013-11-27 15:03:06 +01:00
if (!$host)
$host = '127.0.0.1';
if (!$port)
$port = 9306;
$sCommandSystem = "echo 'show status;' | mysql -h{$host} -P{$port} | grep '^queries' | awk '{ print $2}';";
2012-05-24 13:27:52 +02:00
$sTmpFilePath = "/tmp/sphinx_queries";
if (isset($argc) && $argc > 1) {
if ($argv[1] == 'autoconf') {
echo "yes\n";
}
if ($argv[1] == 'config') {
echo "graph_title Sphinx Queries in last 5 minutes\n" .
"graph_info This graph shows the number of queries for last 5 minutes\n" .
"graph_category sphinx\n" .
"graph_args --base 1000 --lower-limit 0\n" .
"graph_vlabel Connections\n" .
"graph_info The number of current queries\n" .
"graph_order current\n" .
"graph_total Total\n" .
"current.label In Use\n" .
"current.draw AREA\n" .
"current.info The number of current queries\n" .
"current.warning 2500\n" .
"current.critical 4000\n";
}
exit(0);
}
$iCurrent = @exec($sCommandSystem);
if (!file_exists($sTmpFilePath)) {
$fp = fopen($sTmpFilePath, "w");
fputs($fp, $iCurrent);
fclose($fp);
$toShow = 0;
} else {
$iOldCount = file_get_contents($sTmpFilePath, true);
$fp = fopen($sTmpFilePath, "w");
fputs($fp, $iCurrent);
fclose($fp);
$toShow = (int) ($iCurrent - (int) $iOldCount);
if ($toShow < 0) {
$toShow = 0;
}
2012-05-24 13:27:52 +02:00
}
echo "current.value $toShow\n";