Plugin for monitoring uWSGI Emperor vassal states
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.1 KiB

  1. #!/usr/local/bin/php
  2. <?php
  3. # check_influx - Plugin for monitoring uWSGI Emperor vassal states with Nagios and Influx LP output formats
  4. # version 1.0 19.06.2016
  5. # by Mikanoshi - iam@mikanoshi.name, http://code.highspec.ru/Mikanoshi/check_uwsgi
  6. #
  7. # This plugin is a free software and comes with ABSOLUTELY NO WARRANTY.
  8. # It may be used, redistributed and/or modified under the terms of the
  9. # GNU General Public Licence Version 3 (see https://www.gnu.org/licenses/gpl.txt).
  10. $options = getopt("s:im:");
  11. if (isset($options["s"]))
  12. $socketpath = $options["s"];
  13. else
  14. usage();
  15. $isinflux = isset($options["i"]) ? true : false;
  16. $measurement = isset($options["m"]) ? $options["m"] : "uwsgi";
  17. $timestamp = time() * 1000000000;
  18. $socket = fsockopen("unix://".$socketpath);
  19. while ($resp = fread($socket, 512)) {
  20. if (trim($resp) == '') break;
  21. $json .= $resp;
  22. }
  23. fclose($socket);
  24. $data = json_decode($json);
  25. $out = Array();
  26. $status = 0;
  27. if (count($data->vassals) == 0) {
  28. $status = 3;
  29. } else foreach ($data->vassals as $vassal) {
  30. $out[] = Array(str_replace(Array('.uwsgi.ini','.ini'), Array('',''), $vassal->id), $vassal->accepting, $vassal->loyal, $vassal->ready, $vassal->cursed);
  31. if (intval($vassal->accepting) !== 1) $status = 2;
  32. }
  33. if ($isinflux) $status = 0;
  34. else if ($status == 0) echo "OK - ";
  35. else if ($status == 1) echo "WARNING - ";
  36. else if ($status == 2) echo "CRITICAL - ";
  37. else if ($status == 3) echo "UNKNOWN\n";
  38. if ($status < 3) {
  39. foreach ($out as $point) {
  40. $tmp .= $isinflux ? $measurement.",vassal=".$point[0]." accepting=".$point[1].",loyal=".$point[2].",ready=".$point[3].",cursed=".$point[4]." ".$timestamp."\n"
  41. : $point[0]." is ".(intval($point[1]) == 1 ? "accepting" : "NOT accepting" ).", ";
  42. $tmp2 .= $point[0]."_accepting=".$point[1]."; ";
  43. }
  44. echo $isinflux ? $tmp : rtrim($tmp, ', ')." | ".$tmp2."\n";
  45. }
  46. exit($status);
  47. function usage() {
  48. echo "Usage: check_uwsgi -s <path to emperor-stats socket> [-i] [-m measurement]
  49. Optional parameters
  50. -i Influx Line Protocol output format instead of nagios
  51. -m Measurement name (\"uwsgi\" by default)
  52. Example: check_uwsgi -s /tmp/uwsgistats.sock -i -m uwsgistats\n";
  53. exit(1);
  54. }
  55. ?>