From e599e52c38f36fb1786bc419477593d2366fe88c Mon Sep 17 00:00:00 2001 From: Konstantin Kuklin Date: Thu, 24 May 2012 15:27:52 +0400 Subject: [PATCH] Plugins for Sphinx on PHP --- plugins/sphinx-php/sphinx_connections | 51 +++++++++++++++++++++++++++ plugins/sphinx-php/sphinx_queries | 51 +++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 plugins/sphinx-php/sphinx_connections create mode 100644 plugins/sphinx-php/sphinx_queries diff --git a/plugins/sphinx-php/sphinx_connections b/plugins/sphinx-php/sphinx_connections new file mode 100644 index 00000000..e0eb644a --- /dev/null +++ b/plugins/sphinx-php/sphinx_connections @@ -0,0 +1,51 @@ +#!/usr/bin/php + + * Date: 24.05.12 + */ + +$sCommandSystem = "echo 'show status;' | mysql -h127.0.0.1 -P9306 | grep connections | awk '{ print $2}';"; +$sTmpFilePath = "/tmp/sphinx_connections"; + +if (isset($argc) && $argc > 1) { + if ($argv[1] == 'autoconf') { + echo "yes\n"; + } + if ($argv[1] == 'config') { + echo "graph_title Sphinx Connections in last 5 minutes\n" . + "graph_info This graph shows the number of connections 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 connections with respect to the max_connections setting.graph_category sphinx\n" . + "graph_order current\n" . + "graph_total Total\n" . + "current.label In Use\n" . + "current.draw AREA\n" . + "current.info The number of connections in last 5 minutes\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); +} + +echo "current.value $toShow\n"; diff --git a/plugins/sphinx-php/sphinx_queries b/plugins/sphinx-php/sphinx_queries new file mode 100644 index 00000000..f11c5e83 --- /dev/null +++ b/plugins/sphinx-php/sphinx_queries @@ -0,0 +1,51 @@ +#!/usr/bin/php + + * Date: 24.05.12 + */ + +$sCommandSystem = "echo 'show status;' | mysql -h127.0.0.1 -P9306 | grep '^queries' | awk '{ print $2}';"; +$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); +} + +echo "current.value $toShow\n";