vogelor
2011-03-26 51cf609f93d589eead0b66cd65953741f5b67606
fixed a error deleting to much data in a multiserver-environment
1 files modified
72 ■■■■■ changed files
server/mods-available/monitor_core_module.inc.php 72 ●●●●● patch | view | raw | blame | history
server/mods-available/monitor_core_module.inc.php
@@ -135,7 +135,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorServer() {
@@ -160,7 +160,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorOsVer() {
@@ -185,7 +185,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorIspcVer() {
@@ -210,7 +210,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorDiskUsage() {
@@ -235,7 +235,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorMemUsage() {
@@ -259,7 +259,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorCpu() {
@@ -283,7 +283,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorServices() {
@@ -308,7 +308,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorOpenVzHost() {
@@ -333,7 +333,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorOpenVzUserBeancounter() {
@@ -358,7 +358,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorSystemUpdate() {
@@ -393,7 +393,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorMailQueue() {
@@ -418,7 +418,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorRaid() {
@@ -443,7 +443,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorRkHunter() {
@@ -478,7 +478,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorFail2ban() {
@@ -503,7 +503,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorSysLog() {
@@ -528,7 +528,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorMailLog() {
@@ -553,7 +553,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorMailWarnLog() {
@@ -578,7 +578,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorMailErrLog() {
@@ -603,7 +603,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorMessagesLog() {
@@ -628,7 +628,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorISPCCronLog() {
@@ -653,7 +653,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorFreshClamLog() {
@@ -678,7 +678,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorClamAvLog() {
@@ -703,7 +703,7 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    private function _monitorIspConfigLog() {
@@ -728,23 +728,35 @@
        $app->dbmaster->query($sql);
        /* The new data is written, now we can delete the old one */
        $this->_delOldRecords($type, 4);
        $this->_delOldRecords($type, $res['server_id']);
    }
    /*
      Deletes Records older than n.
    /**
     * Deletes Records older than 4 minutes.
     * The monitor writes new data every 5 minutes or longer (4 hour, 1 day).
     * So if i delete all Date older than 4 minutes i can be sure, that all old data
     * are deleted...
     */
    private function _delOldRecords($type, $min, $hour=0, $days=0) {
    private function _delOldRecords($type, $serverId) {
        global $app;
        $now = time();
        $old = $now - ($min * 60) - ($hour * 60 * 60) - ($days * 24 * 60 * 60);
        $old = $now - (4 * 60); // 4 minutes
        /*
         * ATTENTION if i do NOT pay attention of the server id, i delete all data (of the type)
         * of ALL servers. This means, if i have a multiserver-environment and a server has a
         * time not synced with the others (for example, all server has 11:00 and ONE server has
         * 10:45) then the actual data of this server (with the time-stamp 10:45) get lost
         * even though it is the NEWEST data of this server. To avoid this i HAVE to include
         * the server-id!
         */
        $sql = 'DELETE FROM monitor_data ' .
                'WHERE ' .
                'type =' . "'" . $app->dbmaster->quote($type) . "' " .
                'AND ' .
                'created < ' . $old;
                '  created < ' . $old . ' ' .
                'AND ' .
                '  server_id = ' . $serverId;
        $app->dbmaster->query($sql);
    }