2011-08-31 00:00:03 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Application_Model_Systemstatus
|
|
|
|
{
|
|
|
|
|
2011-09-16 23:51:28 +02:00
|
|
|
public static function GetMonitStatus($p_ip){
|
2011-09-14 00:43:16 +02:00
|
|
|
|
2011-09-16 23:51:28 +02:00
|
|
|
$url = "http://$p_ip:2812/_status?format=xml";
|
|
|
|
|
2011-09-14 00:43:16 +02:00
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($ch, CURLOPT_USERPWD, "admin:monit");
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
$xmlDoc = new DOMDocument();
|
|
|
|
$xmlDoc->loadXML($result);
|
2011-09-13 20:56:24 +02:00
|
|
|
|
2011-09-14 00:43:16 +02:00
|
|
|
return $xmlDoc->documentElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function ExtractServiceInformation($p_docRoot, $p_serviceName){
|
2011-09-17 03:40:44 +02:00
|
|
|
|
|
|
|
$data = array();
|
|
|
|
$starting = array("process_id"=>"STARTING...",
|
|
|
|
"uptime_seconds"=>"STARTING...",
|
|
|
|
"memory_perc"=>"UNKNOWN",
|
|
|
|
"memory_kb"=>"UNKNOWN",
|
|
|
|
"cpu_perc"=>"UNKNOWN");
|
|
|
|
|
|
|
|
$notRunning = array("process_id"=>"FAILED",
|
|
|
|
"uptime_seconds"=>"FAILED",
|
2011-09-16 23:51:28 +02:00
|
|
|
"memory_perc"=>"UNKNOWN",
|
|
|
|
"memory_kb"=>"UNKNOWN",
|
|
|
|
"cpu_perc"=>"UNKNOWN"
|
|
|
|
);
|
2011-09-14 00:43:16 +02:00
|
|
|
|
2011-09-17 03:40:44 +02:00
|
|
|
|
|
|
|
|
2011-09-14 00:43:16 +02:00
|
|
|
foreach ($p_docRoot->getElementsByTagName("service") AS $item)
|
|
|
|
{
|
|
|
|
if ($item->getElementsByTagName("name")->item(0)->nodeValue == $p_serviceName){
|
2011-09-17 03:40:44 +02:00
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$uptime = $item->getElementsByTagName("uptime");
|
|
|
|
if ($uptime->length > 0){
|
|
|
|
$data["uptime_seconds"] = $uptime->item(0)->nodeValue;
|
|
|
|
}
|
|
|
|
|
2011-09-17 03:30:50 +02:00
|
|
|
$memory = $item->getElementsByTagName("memory");
|
|
|
|
if ($memory->length > 0){
|
2011-09-17 03:40:44 +02:00
|
|
|
$data["memory_perc"] = $memory->item(0)->getElementsByTagName("percenttotal")->item(0)->nodeValue."%";
|
2011-09-17 03:30:50 +02:00
|
|
|
$data["memory_kb"] = $memory->item(0)->getElementsByTagName("kilobytetotal")->item(0)->nodeValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cpu = $item->getElementsByTagName("cpu");
|
|
|
|
if ($cpu->length > 0){
|
2011-09-17 03:40:44 +02:00
|
|
|
$data["cpu_perc"] = $cpu->item(0)->getElementsByTagName("percent")->item(0)->nodeValue."%";
|
2011-09-17 03:30:50 +02:00
|
|
|
}
|
2011-09-14 00:43:16 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-09-13 20:56:24 +02:00
|
|
|
|
2011-09-14 00:43:16 +02:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2011-09-16 23:51:28 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-09-14 00:43:16 +02:00
|
|
|
public static function GetPypoStatus(){
|
2011-09-16 23:51:28 +02:00
|
|
|
|
|
|
|
$component = CcComponentQuery::create()->findOneByDbName("pypo");
|
|
|
|
$ip = $component->getDbIp();
|
|
|
|
|
|
|
|
$docRoot = self::GetMonitStatus($ip);
|
2011-09-14 00:43:16 +02:00
|
|
|
$data = self::ExtractServiceInformation($docRoot, "airtime-playout");
|
|
|
|
|
2011-09-16 23:51:28 +02:00
|
|
|
return $data;
|
2011-09-12 22:18:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetLiquidsoapStatus(){
|
2011-09-16 23:51:28 +02:00
|
|
|
|
|
|
|
$component = CcComponentQuery::create()->findOneByDbName("pypo");
|
|
|
|
$ip = $component->getDbIp();
|
|
|
|
|
|
|
|
$docRoot = self::GetMonitStatus($ip);
|
2011-09-14 00:43:16 +02:00
|
|
|
$data = self::ExtractServiceInformation($docRoot, "airtime-liquidsoap");
|
|
|
|
|
2011-09-16 23:51:28 +02:00
|
|
|
return $data;
|
2011-09-12 22:18:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetShowRecorderStatus(){
|
2011-09-16 23:51:28 +02:00
|
|
|
|
|
|
|
$component = CcComponentQuery::create()->findOneByDbName("show-recorder");
|
|
|
|
$ip = $component->getDbIp();
|
|
|
|
|
|
|
|
$docRoot = self::GetMonitStatus($ip);
|
2011-09-14 00:43:16 +02:00
|
|
|
$data = self::ExtractServiceInformation($docRoot, "airtime-show-recorder");
|
|
|
|
|
2011-09-16 23:51:28 +02:00
|
|
|
return $data;
|
2011-09-12 22:18:08 +02:00
|
|
|
}
|
|
|
|
|
2011-09-16 23:51:28 +02:00
|
|
|
public static function GetMediaMonitorStatus(){
|
|
|
|
|
|
|
|
$component = CcComponentQuery::create()->findOneByDbName("media-monitor");
|
|
|
|
$ip = $component->getDbIp();
|
|
|
|
|
|
|
|
$docRoot = self::GetMonitStatus($ip);
|
2011-09-14 00:43:16 +02:00
|
|
|
$data = self::ExtractServiceInformation($docRoot, "airtime-media-monitor");
|
|
|
|
|
2011-09-16 23:51:28 +02:00
|
|
|
return $data;
|
2011-09-12 22:18:08 +02:00
|
|
|
}
|
|
|
|
|
2011-09-14 00:43:16 +02:00
|
|
|
public static function GetIcecastStatus(){
|
2011-09-16 23:51:28 +02:00
|
|
|
$docRoot = self::GetMonitStatus("localhost");
|
2011-09-14 00:43:16 +02:00
|
|
|
$data = self::ExtractServiceInformation($docRoot, "icecast2");
|
|
|
|
|
2011-09-16 23:51:28 +02:00
|
|
|
return $data;
|
2011-09-12 22:18:08 +02:00
|
|
|
}
|
2011-09-16 23:51:28 +02:00
|
|
|
|
|
|
|
public static function GetRabbitMqStatus(){
|
|
|
|
$docRoot = self::GetMonitStatus("localhost");
|
|
|
|
$data = self::ExtractServiceInformation($docRoot, "rabbitmq-server");
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2011-09-12 22:18:08 +02:00
|
|
|
|
|
|
|
public static function GetAirtimeVersion(){
|
|
|
|
return AIRTIME_VERSION;
|
|
|
|
}
|
2011-09-14 00:43:16 +02:00
|
|
|
/*
|
2011-09-12 22:18:08 +02:00
|
|
|
|
|
|
|
|
2011-08-31 00:00:03 +02:00
|
|
|
private function getCheckSystemResults(){
|
2011-08-31 18:52:12 +02:00
|
|
|
//exec("airtime-check-system", $output);
|
2011-08-31 00:00:03 +02:00
|
|
|
|
2011-08-31 18:52:12 +02:00
|
|
|
require_once "/usr/lib/airtime/utils/airtime-check-system.php";
|
|
|
|
$arrs = AirtimeCheck::CheckAirtimeDaemons();
|
2011-08-31 00:00:03 +02:00
|
|
|
|
2011-08-31 18:52:12 +02:00
|
|
|
$status = array("AIRTIME_VERSION" => AIRTIME_VERSION);
|
|
|
|
foreach($arrs as $arr){
|
|
|
|
$status[$arr[0]] = $arr[1];
|
2011-08-31 00:00:03 +02:00
|
|
|
}
|
|
|
|
|
2011-08-31 18:52:12 +02:00
|
|
|
$storDir = MusicDir::getStorDir()->getDirectory();
|
|
|
|
|
|
|
|
$freeSpace = disk_free_space($storDir);
|
|
|
|
$totalSpace = disk_total_space($storDir);
|
|
|
|
|
|
|
|
$status["DISK_SPACE"] = sprintf("%01.3f%%", $freeSpace/$totalSpace*100);
|
|
|
|
|
2011-08-31 00:00:03 +02:00
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getResults(){
|
|
|
|
$keyValues = $this->getCheckSystemResults();
|
|
|
|
|
|
|
|
$results = array();
|
|
|
|
$key = "AIRTIME_VERSION";
|
|
|
|
$results[$key] = array("Airtime Version", $keyValues[$key], false);
|
|
|
|
|
|
|
|
$triplets = array(array("PLAYOUT_ENGINE_RUNNING_SECONDS", "Playout Engine Status", true),
|
|
|
|
array("LIQUIDSOAP_RUNNING_SECONDS", "Liquidsoap Status", true),
|
|
|
|
array("MEDIA_MONITOR_RUNNING_SECONDS", "Media-Monitor Status", true),
|
|
|
|
array("SHOW_RECORDER_RUNNING_SECONDS", "Show-Recorder Status", true));
|
|
|
|
|
|
|
|
foreach($triplets as $triple){
|
|
|
|
list($key, $desc, $downloadLog) = $triple;
|
|
|
|
$results[$key] = array($desc, $this->convertRunTimeToPassFail($keyValues[$key]), $downloadLog);
|
|
|
|
}
|
|
|
|
|
2011-08-31 18:52:12 +02:00
|
|
|
$key = "DISK_SPACE";
|
|
|
|
$results[$key] = array("Disk Space Free: ", $keyValues[$key], false);
|
|
|
|
|
2011-08-31 00:00:03 +02:00
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function convertRunTimeToPassFail($runTime){
|
|
|
|
return $runTime > 3 ? "Pass" : "Fail";
|
|
|
|
}
|
2011-09-14 00:43:16 +02:00
|
|
|
|
|
|
|
*/
|
2011-08-31 00:00:03 +02:00
|
|
|
}
|