From a11dba14693a571c955b35651dcced056ddc7fb6 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 19 Sep 2011 15:46:15 -0400 Subject: [PATCH] CC-2750: Ability to query health status for pypo, liquidsoap, media monitor, and recorder --- .../application/models/Systemstatus.php | 85 ++++++++++--------- install_minimal/airtime-install | 15 +++- python_apps/monit/airtime-monit.cfg | 2 +- 3 files changed, 56 insertions(+), 46 deletions(-) diff --git a/airtime_mvc/application/models/Systemstatus.php b/airtime_mvc/application/models/Systemstatus.php index e018ae466..e4de9f948 100644 --- a/airtime_mvc/application/models/Systemstatus.php +++ b/airtime_mvc/application/models/Systemstatus.php @@ -22,7 +22,6 @@ class Application_Model_Systemstatus public static function ExtractServiceInformation($p_docRoot, $p_serviceName){ - $data = array(); $starting = array("process_id"=>"STARTING...", "uptime_seconds"=>"STARTING...", "memory_perc"=>"UNKNOWN", @@ -35,64 +34,66 @@ class Application_Model_Systemstatus "memory_kb"=>"UNKNOWN", "cpu_perc"=>"UNKNOWN" ); + $data = $notRunning; + if (!is_null($p_docRoot)){ + foreach ($p_docRoot->getElementsByTagName("service") AS $item) + { + if ($item->getElementsByTagName("name")->item(0)->nodeValue == $p_serviceName){ - foreach ($p_docRoot->getElementsByTagName("service") AS $item) - { - if ($item->getElementsByTagName("name")->item(0)->nodeValue == $p_serviceName){ - - $monitor = $item->getElementsByTagName("monitor"); - if ($monitor->length > 0){ - $status = $monitor->item(0)->nodeValue; - if ($status == "2"){ - $data = $starting; - } else if ($status == 0){ - $data = $notRunning; + $monitor = $item->getElementsByTagName("monitor"); + if ($monitor->length > 0){ + $status = $monitor->item(0)->nodeValue; + if ($status == "2"){ + $data = $starting; + } else if ($status == 0){ + $data = $notRunning; + } + } + + $process_id = $item->getElementsByTagName("pid"); + if ($process_id->length > 0){ + $data["process_id"] = $process_id->item(0)->nodeValue; } - } - - $process_id = $item->getElementsByTagName("pid"); - if ($process_id->length > 0){ - $data["process_id"] = $process_id->item(0)->nodeValue; - } - $uptime = $item->getElementsByTagName("uptime"); - if ($uptime->length > 0){ - $data["uptime_seconds"] = $uptime->item(0)->nodeValue; + $uptime = $item->getElementsByTagName("uptime"); + if ($uptime->length > 0){ + $data["uptime_seconds"] = $uptime->item(0)->nodeValue; + } + + $memory = $item->getElementsByTagName("memory"); + if ($memory->length > 0){ + $data["memory_perc"] = $memory->item(0)->getElementsByTagName("percenttotal")->item(0)->nodeValue."%"; + $data["memory_kb"] = $memory->item(0)->getElementsByTagName("kilobytetotal")->item(0)->nodeValue; + } + + $cpu = $item->getElementsByTagName("cpu"); + if ($cpu->length > 0){ + $data["cpu_perc"] = $cpu->item(0)->getElementsByTagName("percent")->item(0)->nodeValue."%"; + } + break; } - - $memory = $item->getElementsByTagName("memory"); - if ($memory->length > 0){ - $data["memory_perc"] = $memory->item(0)->getElementsByTagName("percenttotal")->item(0)->nodeValue."%"; - $data["memory_kb"] = $memory->item(0)->getElementsByTagName("kilobytetotal")->item(0)->nodeValue; - } - - $cpu = $item->getElementsByTagName("cpu"); - if ($cpu->length > 0){ - $data["cpu_perc"] = $cpu->item(0)->getElementsByTagName("percent")->item(0)->nodeValue."%"; - } - break; } } - return $data; } public static function GetPlatformInfo(){ - $docRoot = self::GetMonitStatus("localhost"); - $data = array("release"=>"UNKNOWN", "machine"=>"UNKNOWN", "memory"=>"UNKNOWN", "swap"=>"UNKNOWN"); - foreach ($docRoot->getElementsByTagName("platform") AS $item) - { - $data["release"] = $item->getElementsByTagName("release")->item(0)->nodeValue; - $data["machine"] = $item->getElementsByTagName("machine")->item(0)->nodeValue; - $data["memory"] = $item->getElementsByTagName("memory")->item(0)->nodeValue; - $data["swap"] = $item->getElementsByTagName("swap")->item(0)->nodeValue; + $docRoot = self::GetMonitStatus("localhost"); + if (!is_null($docRoot)){ + foreach ($docRoot->getElementsByTagName("platform") AS $item) + { + $data["release"] = $item->getElementsByTagName("release")->item(0)->nodeValue; + $data["machine"] = $item->getElementsByTagName("machine")->item(0)->nodeValue; + $data["memory"] = $item->getElementsByTagName("memory")->item(0)->nodeValue; + $data["swap"] = $item->getElementsByTagName("swap")->item(0)->nodeValue; + } } return $data; diff --git a/install_minimal/airtime-install b/install_minimal/airtime-install index db496ebd3..bb5f443c0 100755 --- a/install_minimal/airtime-install +++ b/install_minimal/airtime-install @@ -37,6 +37,15 @@ elif [ "$result" -ne "0" ]; then fi set -e +# Need to ensure monit is running before Airtime daemons are run. This is +# so we can ensure they can register with monit to monitor them when they start. +/etc/init.d/monit start + +# We may have updated the monit config files, and monit was already running. +# In this case the previous "start" command didn't do anything, and we need +# to reload the config files instead. +/etc/init.d/monit force-reload + echo -e "\n*** API Client Installation ***" python ${SCRIPTPATH}/../python_apps/api_clients/install/api_client_install.py @@ -49,11 +58,11 @@ python ${SCRIPTPATH}/../python_apps/show-recorder/install/recorder-install.py echo -e "\n*** Media Monitor Installation ***" python ${SCRIPTPATH}/../python_apps/media-monitor/install/media-monitor-install.py -monit monitor icecast2 >/dev/null 2>&1 -monit monitor rabbitmq-server >/dev/null 2>&1 +monit monitor icecast2 +monit monitor rabbitmq-server echo -e "\n*** Verifying your system environment ***" -sleep 5 +sleep 10 airtime-check-system echo -e "\n******************************* Install Complete *******************************" diff --git a/python_apps/monit/airtime-monit.cfg b/python_apps/monit/airtime-monit.cfg index 28cb2fde0..8480dda7f 100644 --- a/python_apps/monit/airtime-monit.cfg +++ b/python_apps/monit/airtime-monit.cfg @@ -1,4 +1,4 @@ - set daemon 10 # Poll at 10 second intervals + set daemon 10 # Poll at 5 second intervals #set logfile syslog facility log_daemon set logfile /var/log/monit.log