2014-11-16 08:21:55 +08:00
|
|
|
<?php
|
|
|
|
App::uses('AppController', 'Controller');
|
|
|
|
|
|
|
|
class HostController extends AppController {
|
|
|
|
|
|
|
|
public $components = array('RequestHandler');
|
|
|
|
|
|
|
|
public function daemonCheck($daemon=false, $args=false) {
|
2014-11-22 05:42:21 +08:00
|
|
|
$string = Configure::read('ZM_PATH_BIN')."/zmdc.pl check";
|
2014-11-16 08:21:55 +08:00
|
|
|
if ( $daemon )
|
|
|
|
{
|
|
|
|
$string .= " $daemon";
|
|
|
|
if ( $args )
|
|
|
|
$string .= " $args";
|
|
|
|
}
|
|
|
|
$result = exec( $string );
|
|
|
|
$result = preg_match( '/running/', $result );
|
|
|
|
|
|
|
|
$this->set(array(
|
|
|
|
'result' => $result,
|
|
|
|
'_serialize' => array('result')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2014-11-22 03:49:03 +08:00
|
|
|
function getLoad() {
|
2014-11-26 00:07:27 +08:00
|
|
|
$load = sys_getloadavg();
|
|
|
|
|
2014-11-22 03:49:03 +08:00
|
|
|
$this->set(array(
|
|
|
|
'load' => $load,
|
|
|
|
'_serialize' => array('load')
|
|
|
|
));
|
|
|
|
}
|
2014-11-22 06:15:32 +08:00
|
|
|
|
2014-11-26 00:10:34 +08:00
|
|
|
// If $mid is set, only return disk usage for that monitor
|
|
|
|
// Else, return an array of total disk usage, and per-monitor
|
|
|
|
// usage.
|
2014-11-25 03:56:44 +08:00
|
|
|
function getDiskPercent($mid = null) {
|
2014-11-22 06:15:32 +08:00
|
|
|
$this->loadModel('Config');
|
2014-11-25 03:56:44 +08:00
|
|
|
$this->loadModel('Monitor');
|
|
|
|
|
2014-11-26 00:10:34 +08:00
|
|
|
// If $mid is passed, see if it is valid
|
2014-11-25 03:56:44 +08:00
|
|
|
if ($mid) {
|
|
|
|
if (!$this->Monitor->exists($mid)) {
|
|
|
|
throw new NotFoundException(__('Invalid monitor'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-22 06:15:32 +08:00
|
|
|
$zm_dir_events = $this->Config->find('list', array(
|
|
|
|
'conditions' => array('Name' => 'ZM_DIR_EVENTS'),
|
|
|
|
'fields' => array('Name', 'Value')
|
|
|
|
));
|
|
|
|
$zm_dir_events = $zm_dir_events['ZM_DIR_EVENTS' ];
|
|
|
|
|
|
|
|
// Test to see if $zm_dir_events is relative or absolute
|
|
|
|
if ('/' === "" || strrpos($zm_dir_events, '/', -strlen($zm_dir_events)) !== TRUE) {
|
|
|
|
// relative - so add the full path
|
|
|
|
$zm_dir_events = Configure::read('ZM_PATH_WEB') . '/' . $zm_dir_events;
|
|
|
|
}
|
|
|
|
|
2014-11-25 03:56:44 +08:00
|
|
|
if ($mid) {
|
|
|
|
// Get disk usage for $mid
|
2014-11-26 00:10:34 +08:00
|
|
|
$usage = shell_exec ("du -sh0 $zm_dir_events/$mid | awk '{print $1}'");
|
2014-11-25 03:56:44 +08:00
|
|
|
} else {
|
2014-11-26 00:10:34 +08:00
|
|
|
$monitors = $this->Monitor->find('list');
|
|
|
|
$usage = array();
|
|
|
|
|
|
|
|
// Add each monitor's usage to array
|
|
|
|
foreach ($monitors as $id => $name) {
|
|
|
|
$space = shell_exec ("du -s0 $zm_dir_events/$id | awk '{print $1}'");
|
|
|
|
if ($space == null) {
|
|
|
|
$space = 0;
|
|
|
|
}
|
|
|
|
$space = $space/1024/1024;
|
|
|
|
$usage[$name] = rtrim($space);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add total usage to array
|
|
|
|
$space = shell_exec( "df $zm_dir_events |tail -n1 | awk '{print $3 }'");
|
|
|
|
$space = $space/1024/1024;
|
|
|
|
$usage['Total'] = rtrim($space);
|
2014-11-25 03:56:44 +08:00
|
|
|
}
|
2014-11-22 06:15:32 +08:00
|
|
|
|
|
|
|
$this->set(array(
|
2014-11-26 00:10:34 +08:00
|
|
|
'usage' => $usage,
|
|
|
|
'_serialize' => array('usage')
|
2014-11-22 06:15:32 +08:00
|
|
|
));
|
|
|
|
}
|
2014-11-24 08:52:27 +08:00
|
|
|
|
|
|
|
function getVersion() {
|
|
|
|
$version = Configure::read('ZM_VERSION');
|
|
|
|
|
|
|
|
$this->set(array(
|
|
|
|
'version' => $version,
|
|
|
|
'_serialize' => array('version')
|
|
|
|
));
|
|
|
|
}
|
2014-11-16 08:21:55 +08:00
|
|
|
}
|