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);
|
|
|
|
|
2011-09-22 16:45:43 +02:00
|
|
|
$docRoot = null;
|
|
|
|
if ($result != ""){
|
|
|
|
$xmlDoc = new DOMDocument();
|
|
|
|
$xmlDoc->loadXML($result);
|
|
|
|
$docRoot = $xmlDoc->documentElement;
|
|
|
|
}
|
2011-09-13 20:56:24 +02:00
|
|
|
|
2011-09-22 16:45:43 +02:00
|
|
|
return $docRoot;
|
2011-09-14 00:43:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function ExtractServiceInformation($p_docRoot, $p_serviceName){
|
2011-09-17 03:40:44 +02:00
|
|
|
|
2011-09-19 23:55:26 +02:00
|
|
|
$starting = array(
|
|
|
|
"name"=>"",
|
|
|
|
"process_id"=>"STARTING...",
|
2011-09-22 16:45:43 +02:00
|
|
|
"uptime_seconds"=>"-1",
|
2011-09-19 23:55:26 +02:00
|
|
|
"status"=>true,
|
2011-09-22 16:45:43 +02:00
|
|
|
"memory_perc"=>"0%",
|
|
|
|
"memory_kb"=>"0",
|
|
|
|
"cpu_perc"=>"0%");
|
2011-09-17 03:40:44 +02:00
|
|
|
|
2011-09-19 23:55:26 +02:00
|
|
|
$notRunning = array(
|
2011-09-22 16:45:43 +02:00
|
|
|
"name"=>$p_serviceName,
|
2011-09-19 23:55:26 +02:00
|
|
|
"process_id"=>"FAILED",
|
2011-09-22 16:45:43 +02:00
|
|
|
"uptime_seconds"=>"-1",
|
2011-09-19 23:55:26 +02:00
|
|
|
"status"=>false,
|
2011-09-22 16:45:43 +02:00
|
|
|
"memory_perc"=>"0%",
|
|
|
|
"memory_kb"=>"0",
|
|
|
|
"cpu_perc"=>"0%"
|
2011-09-16 23:51:28 +02:00
|
|
|
);
|
2011-09-19 21:46:15 +02:00
|
|
|
$data = $notRunning;
|
2011-09-14 00:43:16 +02:00
|
|
|
|
2011-09-17 03:40:44 +02:00
|
|
|
|
2011-09-19 21:46:15 +02:00
|
|
|
if (!is_null($p_docRoot)){
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2011-09-19 23:55:26 +02:00
|
|
|
|
|
|
|
$process_id = $item->getElementsByTagName("name");
|
|
|
|
if ($process_id->length > 0){
|
|
|
|
$data["name"] = $process_id->item(0)->nodeValue;
|
|
|
|
}
|
2011-09-19 21:46:15 +02:00
|
|
|
|
|
|
|
$process_id = $item->getElementsByTagName("pid");
|
|
|
|
if ($process_id->length > 0){
|
|
|
|
$data["process_id"] = $process_id->item(0)->nodeValue;
|
2011-09-19 23:55:26 +02:00
|
|
|
$data["status"] = true;
|
2011-09-17 03:40:44 +02:00
|
|
|
}
|
|
|
|
|
2011-09-19 21:46:15 +02:00
|
|
|
$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;
|
2011-09-17 03:30:50 +02:00
|
|
|
}
|
2011-09-14 00:43:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2011-09-16 23:51:28 +02:00
|
|
|
public static function GetPlatformInfo(){
|
|
|
|
$data = array("release"=>"UNKNOWN",
|
|
|
|
"machine"=>"UNKNOWN",
|
|
|
|
"memory"=>"UNKNOWN",
|
|
|
|
"swap"=>"UNKNOWN");
|
|
|
|
|
2011-09-19 21:46:15 +02:00
|
|
|
$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;
|
|
|
|
}
|
2011-09-16 23:51:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-09-14 00:43:16 +02:00
|
|
|
public static function GetPypoStatus(){
|
2011-09-16 23:51:28 +02:00
|
|
|
|
2011-09-30 20:08:15 +02:00
|
|
|
$component = CcServiceRegisterQuery::create()->findOneByDbName("pypo");
|
2011-09-16 23:51:28 +02:00
|
|
|
$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
|
|
|
|
2011-09-30 20:08:15 +02:00
|
|
|
$component = CcServiceRegisterQuery::create()->findOneByDbName("pypo");
|
2011-09-16 23:51:28 +02:00
|
|
|
$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
|
|
|
|
2011-09-30 20:08:15 +02:00
|
|
|
$component = CcServiceRegisterQuery::create()->findOneByDbName("show-recorder");
|
2011-10-27 23:13:36 +02:00
|
|
|
if (is_null($component)){
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
$ip = $component->getDbIp();
|
|
|
|
|
|
|
|
$docRoot = self::GetMonitStatus($ip);
|
|
|
|
$data = self::ExtractServiceInformation($docRoot, "airtime-show-recorder");
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2011-09-12 22:18:08 +02:00
|
|
|
}
|
|
|
|
|
2011-09-16 23:51:28 +02:00
|
|
|
public static function GetMediaMonitorStatus(){
|
|
|
|
|
2011-09-30 20:08:15 +02:00
|
|
|
$component = CcServiceRegisterQuery::create()->findOneByDbName("media-monitor");
|
2011-10-27 23:13:36 +02:00
|
|
|
if (is_null($component)){
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
$ip = $component->getDbIp();
|
|
|
|
|
|
|
|
$docRoot = self::GetMonitStatus($ip);
|
|
|
|
$data = self::ExtractServiceInformation($docRoot, "airtime-media-monitor");
|
|
|
|
|
|
|
|
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-22 16:45:43 +02:00
|
|
|
public static function GetDiskInfo(){
|
|
|
|
/* First lets get all the watched directories. Then we can group them
|
|
|
|
* into the same paritions by comparing the partition sizes. */
|
2011-09-22 18:24:17 +02:00
|
|
|
$musicDirs = Application_Model_MusicDir::getWatchedDirs();
|
|
|
|
$musicDirs[] = Application_Model_MusicDir::getStorDir();
|
2011-09-22 16:45:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
$partions = array();
|
|
|
|
|
|
|
|
foreach($musicDirs as $md){
|
|
|
|
$totalSpace = disk_total_space($md->getDirectory());
|
|
|
|
|
|
|
|
if (!isset($partitions[$totalSpace])){
|
|
|
|
$partitions[$totalSpace] = new StdClass;
|
|
|
|
$partitions[$totalSpace]->totalSpace = $totalSpace;
|
|
|
|
$partitions[$totalSpace]->totalFreeSpace = disk_free_space($md->getDirectory());
|
|
|
|
}
|
|
|
|
|
|
|
|
$partitions[$totalSpace]->dirs[] = $md->getDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_values($partitions);
|
|
|
|
}
|
2011-08-31 00:00:03 +02:00
|
|
|
}
|