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 = 'database_size'; /** The state of the database-usage */ $state = 'ok'; /** Fetch the data of all active databases into an array */ $records = $app->db->queryAllRecords("SELECT database_name, sys_groupid FROM web_database WHERE server_id = $server_id AND active='y' GROUP BY sys_groupid, database_name ASC"); if(is_array($records) && !empty($records)) { $data = array(); for ($i = 0; $i < sizeof($records); $i++) { $data[$i]['name'] = $records[$i]['database_name']; $data[$i]['size'] = $app->db->getDatabaseSize($data[$i]['name']); $data[$i]['sys_groupid'] = $records[$i]['sys_groupid']; } } $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(); } } ?>