load('monitor_tools'); $this->_tools = new monitor_tools(); /* end global section for monitor cronjobs */ /* the id of the server as int */ $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'cpu_info'; /* Fetch the data into a array */ if (file_exists('/proc/cpuinfo')) { $cpuData = shell_exec('cat /proc/cpuinfo'); $cpuInfo = explode("\n", $cpuData); $processor = 0; foreach ($cpuInfo as $line) { $part = preg_split('/:/', $line); $key = trim($part[0]); $value = trim($part[1]); if ($key == 'processor') $processor = intval($value); if ($key != '') $data[$key . ' ' . $processor] = $value; } /* the cpu has no state. It is, what it is */ $state = 'no_state'; } else { /* * It is not Linux, so there is no data and no state * * no_state, NOT unknown, because "unknown" is shown as state * inside the GUI. no_state is hidden. * * We have to write NO DATA inside the DB, because the GUI * could not know, if there is any dat, or not... */ $state = 'no_state'; $data['output'] = ''; } $res = array(); $res['server_id'] = $server_id; $res['type'] = $type; $res['data'] = $data; $res['state'] = $state; /* * Insert the data into the database */ $sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . 'UNIX_TIMESTAMP(), ' . "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . "'" . $res['state'] . "'" . ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ $this->_tools->delOldRecords($res['type'], $res['server_id']); parent::onRunJob(); } /* this function is optional if it contains no custom code */ public function onAfterRun() { global $app; parent::onAfterRun(); } } ?>