root / plugins / php / sphinx_connections @ 4b7a73e0
Historique | Voir | Annoter | Télécharger (1,51 ko)
| 1 |
#!/usr/bin/php |
|---|---|
| 2 |
<?php |
| 3 |
/** |
| 4 |
* @author: Konstantin Kuklin <konstantin.kuklin@gmail.com> |
| 5 |
* Date: 24.05.12 |
| 6 |
*/ |
| 7 |
|
| 8 |
$sCommandSystem = "echo 'show status;' | mysql -h127.0.0.1 -P9306 | grep connections | awk '{ print $2}';";
|
| 9 |
$sTmpFilePath = "/tmp/sphinx_connections"; |
| 10 |
|
| 11 |
if (isset($argc) && $argc > 1) {
|
| 12 |
if ($argv[1] == 'autoconf') {
|
| 13 |
echo "yes\n"; |
| 14 |
} |
| 15 |
if ($argv[1] == 'config') {
|
| 16 |
echo "graph_title Sphinx Connections in last 5 minutes\n" . |
| 17 |
"graph_info This graph shows the number of connections for last 5 minutes\n" . |
| 18 |
"graph_category sphinx\n" . |
| 19 |
"graph_args --base 1000 --lower-limit 0\n" . |
| 20 |
"graph_vlabel Connections\n" . |
| 21 |
"graph_info The number of current connections with respect to the max_connections setting.graph_category sphinx\n" . |
| 22 |
"graph_order current\n" . |
| 23 |
"graph_total Total\n" . |
| 24 |
"current.label In Use\n" . |
| 25 |
"current.draw AREA\n" . |
| 26 |
"current.info The number of connections in last 5 minutes\n" . |
| 27 |
"current.warning 2500\n" . |
| 28 |
"current.critical 4000\n"; |
| 29 |
} |
| 30 |
exit(0); |
| 31 |
} |
| 32 |
$iCurrent = @exec($sCommandSystem); |
| 33 |
|
| 34 |
if (!file_exists($sTmpFilePath)) {
|
| 35 |
$fp = fopen($sTmpFilePath, "w"); |
| 36 |
fputs($fp, $iCurrent); |
| 37 |
fclose($fp); |
| 38 |
|
| 39 |
$toShow = 0; |
| 40 |
} else {
|
| 41 |
|
| 42 |
$iOldCount = file_get_contents($sTmpFilePath, true); |
| 43 |
|
| 44 |
$fp = fopen($sTmpFilePath, "w"); |
| 45 |
fputs($fp, $iCurrent); |
| 46 |
fclose($fp); |
| 47 |
|
| 48 |
$toShow = (int) ($iCurrent - (int) $iOldCount); |
| 49 |
} |
| 50 |
|
| 51 |
echo "current.value $toShow\n"; |
