Esempio n. 1
0
function xLoadAvg()
{
    if (!isset($GLOBALS["CLASS_UNIX"])) {
        CheckCallable();
    }
    if (function_exists("sys_getloadavg")) {
        $timeDaemonFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
        if (!is_file($timeDaemonFile)) {
            @file_put_contents($timeDaemonFile, time());
            $GLOBALS["FORCE"] = true;
        }
        $DaemonTime = $GLOBALS["CLASS_UNIX"]->file_time_min($timeDaemonFile);
        if ($GLOBALS["VERBOSE"]) {
            echo "\"{$timeDaemonFile}\" : {$DaemonTime} minutes...\n";
        }
        if (!$GLOBALS["FORCE"]) {
            if ($DaemonTime < 3) {
                events_Loadavg("End due of time ({$timeDaemonFile}) = {$DaemonTime} < 3", __FUNCTION__, __LINE__);
                if ($GLOBALS["VERBOSE"]) {
                    echo "End due of time\n";
                }
                return;
            }
        }
        @unlink($timeDaemonFile);
        @file_put_contents($timeDaemonFile, time());
        $array_load = sys_getloadavg();
        $ttt = time();
        $internal_load = $array_load[0];
        if ($GLOBALS["VERBOSE"]) {
            echo "System load {$internal_load}\n";
        }
        events_Loadavg("System load {$internal_load}", __FUNCTION__, __LINE__);
        if (!is_dir("/var/log/artica-postfix/loadavg")) {
            @mkdir("/var/log/artica-postfix/loadavg", 644, true);
        }
        events_Loadavg("saving in /var/log/artica-postfix/loadavg/{$ttt}", __FUNCTION__, __LINE__);
        @file_put_contents("/var/log/artica-postfix/loadavg/{$ttt}", $internal_load);
        $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.syslog-engine.php --loadavg >/dev/null 2>&1 &";
        $cmd = trim($cmd);
        events_Loadavg("{$cmd}", __FUNCTION__, __LINE__);
        shell_exec($cmd);
    } else {
        events_Loadavg("Fatal: System load \"sys_getloadavg\" no such function", __FUNCTION__, __LINE__);
    }
}
Esempio n. 2
0
function loadavg_logs()
{
    include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        echo "Already running pid {$pid}\n";
        return;
    }
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("artica_events")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Stop !\n";
        }
        events_Loadavg("loadavg_logs:: artica_events database does not exists... try to build one" . __LINE__);
        $q->BuildTables();
    }
    if (!$q->DATABASE_EXISTS("artica_events")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Stop !\n";
        }
        events_Loadavg("loadavg_logs:: artica_events database cannot continue" . __LINE__);
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Scan {$GLOBALS["ARTICALOGDIR"]}/loadavg/*\n";
    }
    $COUNT = $unix->COUNT_FILES("{$GLOBALS["ARTICALOGDIR"]}/loadavg");
    if ($COUNT > 5000) {
        if (!($handle = opendir("{$GLOBALS["ARTICALOGDIR"]}/loadavg"))) {
            return;
        }
        while (false !== ($filename = readdir($handle))) {
            if ($filename == ".") {
                continue;
            }
            if ($filename == "..") {
                continue;
            }
            $filename = "{$GLOBALS["ARTICALOGDIR"]}/loadavg/{$filename}";
            @unlink($filename);
        }
        return;
    }
    if (!($handle = opendir("{$GLOBALS["ARTICALOGDIR"]}/loadavg"))) {
        @mkdir("{$GLOBALS["ARTICALOGDIR"]}/loadavg", 0755, true);
        return;
    }
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $filename = "{$GLOBALS["ARTICALOGDIR"]}/loadavg/{$filename}";
        if ($unix->file_time_min($filename) > 240) {
            @unlink($filename);
            continue;
        }
        $time = basename($filename);
        $load = @file_get_contents($filename);
        $date = date('Y-m-d H:i:s', $time);
        $sql = "INSERT IGNORE INTO loadavg (`stime`,`load`) VALUES ('{$date}','{$load}');";
        $q->QUERY_SQL($sql, "artica_events");
        if (!$q->ok) {
            events_Loadavg("loadavg_logs:: {$q->mysql_error} line:" . __LINE__);
            continue;
        }
        events_Loadavg("loadavg_logs:: success {$filename}" . __LINE__);
        @unlink($filename);
    }
}
Esempio n. 3
0
function loadavg_logs()
{
    include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        echo "Already running pid {$pid}\n";
        return;
    }
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("artica_events")) {
        events_Loadavg("loadavg_logs:: artica_events database does not exists... try to build one" . __LINE__);
        $q->BuildTables();
    }
    if (!$q->DATABASE_EXISTS("artica_events")) {
        events_Loadavg("loadavg_logs:: artica_events database cannot continue" . __LINE__);
        return;
    }
    foreach (glob("/var/log/artica-postfix/loadavg/*") as $filename) {
        $time = basename($filename);
        $load = @file_get_contents($filename);
        $date = date('Y-m-d H:i:s', $time);
        $sql = "INSERT IGNORE INTO loadavg (`stime`,`load`) VALUES ('{$date}','{$load}');";
        $q->QUERY_SQL($sql, "artica_events");
        if (!$q->ok) {
            events_Loadavg("loadavg_logs:: {$q->mysql_error} line:" . __LINE__);
            continue;
        }
        events_Loadavg("loadavg_logs:: success {$filename}" . __LINE__);
        @unlink($filename);
    }
    $file_time = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($unix->file_time_min($file_time) > 300) {
        $sql = "DELETE FROM loadavg WHERE stime < DATE_SUB( NOW( ) , INTERVAL 7 DAY )";
        $q->QUERY_SQL($sql, "artica_events");
        @unlink($file_time);
        @file_put_contents($file_time, time());
    }
}