Esempio n. 1
0
 addInfo('', 0);
 addInfo('Api KillLogs to check', $redis->zCount('tqApiChars', 0, time()));
 addInfo("Api KeyInfos to check", $redis->zCount('tqApis', 0, time()));
 addInfo('Char/Corp Apis', $redis->zCard('tqApiChars'));
 addInfo('Valid Apis', $redis->zCard('tqApis'));
 addInfo('', 0);
 $visitors = new RedisTtlCounter('ttlc:visitors', 300);
 addInfo('Unique IPs in last 5 minutes', $visitors->count());
 $requests = new RedisTtlCounter('ttlc:requests', 300);
 addInfo('Requests in last 5 minutes', $requests->count());
 $info = $redis->info();
 $mem = $info['used_memory_human'];
 $stats = $mdb->getDb()->command(['dbstats' => 1]);
 $dataSize = number_format($stats['dataSize'] / (1024 * 1024 * 1024), 2);
 $storageSize = number_format($stats['storageSize'] / (1024 * 1024 * 1024), 2);
 $memory = getSystemMemInfo();
 $memTotal = number_format($memory['MemTotal'] / (1024 * 1024), 2);
 $memUsed = number_format(($memory['MemTotal'] - $memory['MemFree'] - $memory['Cached']) / (1024 * 1024), 2);
 $maxLen = 0;
 foreach ($infoArray as $i) {
     foreach ($i as $key => $value) {
         $maxLen = max($maxLen, strlen("{$value}"));
     }
 }
 echo exec('date') . '  Load: ' . getLoad() . "  Memory: {$memUsed}G/{$memTotal}G  Redis: {$mem}  TokuDB: {$storageSize}G / {$dataSize}G\n";
 echo "\n";
 foreach ($infoArray as $i) {
     foreach ($i as $name => $count) {
         if (trim($name) == '') {
             echo "\n";
             continue;
Esempio n. 2
0
<?php

function getSystemMemInfo()
{
    $data = explode("\n", file_get_contents("/proc/meminfo"));
    $meminfo = array();
    foreach ($data as $line) {
        // some lines will not contain a colon, for those add one at the end
        list($key, $val) = explode(":", "{$line}:");
        $meminfo[$key] = trim($val);
    }
    return $meminfo;
}
// collect some stats and return them as a json object
$data = array();
$d = '/data/site/archive';
$data['disk_free_percent'] = round(100.0 * disk_free_space($d) / disk_total_space($d), 2);
$meminfo = getSystemMemInfo();
// round(100.0 * intval($meminfo['MemFree']) / intval($meminfo['MemInfo']), 2);
$data['memory_free_percent'] = round(100.0 * floatval(split(' ', $meminfo['MemFree'])[0]) / floatval(split(' ', $meminfo['MemTotal'])[0]), 2);
$data['load_avg'] = sys_getloadavg()[0];
$data['hostname'] = gethostname();
echo json_encode($data, JSON_PRETTY_PRINT);
Esempio n. 3
0
function xrun()
{
    $unix = new unix();
    $siege = $unix->find_program("siege");
    $sock = new sockets();
    $ARRAY = unserialize(base64_decode($sock->GET_INFO("SquidSiegeConfig")));
    if (!is_numeric($ARRAY["GRAB_URLS"])) {
        $ARRAY["GRAB_URLS"] = 0;
    }
    if (!is_numeric($ARRAY["USE_LOCAL_PROXY"])) {
        $ARRAY["USE_LOCAL_PROXY"] = 1;
    }
    if (!is_numeric($ARRAY["SESSIONS"])) {
        $ARRAY["SESSIONS"] = 150;
    }
    if (!is_numeric($ARRAY["MAX_TIME"])) {
        $ARRAY["MAX_TIME"] = 30;
    }
    build_progress_disconnect("{starting}", 5);
    if (!is_file($siege)) {
        build_progress_disconnect("{please_wait} {installing} SIEGE", 50);
        $unix->DEBIAN_INSTALL_PACKAGE("siege");
        $siege = $unix->find_program("siege");
        if (!is_file($siege)) {
            build_progress_disconnect("{installing} SIEGE {failed}", 110);
        }
    }
    $f[] = "internet = true";
    if ($ARRAY["USE_LOCAL_PROXY"] == 1) {
        $squid = new squidbee();
        if ($squid->hasProxyTransparent == 1) {
            $port = $squid->second_listen_port;
        } else {
            $port = $squid->listen_port;
        }
        $addr = "127.0.0.1";
    } else {
        $addr = $ARRAY["REMOTE_PROXY"];
        $port = intval($ARRAY["REMOTE_PROXY_PORT"]);
    }
    if ($addr == null) {
        build_progress_disconnect("{failed} No proxy address", 110);
        return;
    }
    if ($port == 0) {
        build_progress_disconnect("{failed} No proxy port", 110);
        return;
    }
    if ($ARRAY["SESSIONS"] == 0) {
        build_progress_disconnect("{failed} {simulate} 0 sessions", 110);
        return;
    }
    $f[] = "proxy-host ={$addr}";
    $f[] = "proxy-port = {$port}";
    $f[] = "user-agent = Mozilla/5.0 (compatible; IE 11.0; Win32; Trident/7.0)";
    $f[] = "file = /etc/siege/urls.txt";
    $f[] = "concurrent = {$ARRAY["SESSIONS"]}";
    $f[] = "time = {$ARRAY["MAX_TIME"]}S";
    $f[] = "timeout = 5";
    $f[] = "logfile = /var/log/siege.log";
    if (trim($ARRAY["USERNAME"]) != null) {
        $f[] = "username = {$ARRAY["USERNAME"]}";
        $f[] = "password = {$ARRAY["PASSWORD"]}";
    }
    @file_put_contents("/root/.siegerc", @implode("\n", $f));
    $filetemp = $unix->FILE_TEMP();
    $nohup = $unix->find_program("nohup");
    $URLS_NUMBER = $unix->COUNT_LINES_OF_FILE("/etc/siege/urls.txt");
    if ($URLS_NUMBER < 20) {
        @unlink("/etc/siege/urls.txt");
        if ($ARRAY["GRAB_URLS"] == 1) {
            import_urls();
        } else {
            @copy("/usr/share/artica-postfix/bin/install/squid/urls.txt", "/etc/siege/urls.txt");
        }
        $URLS_NUMBER = $unix->COUNT_LINES_OF_FILE("/etc/siege/urls.txt");
    }
    $FINAL["urls"] = $URLS_NUMBER;
    $FINAL["START_TIME"] = time();
    $ss[] = "{$nohup} {$siege} --concurrent={$ARRAY["SESSIONS"]}";
    $ss[] = "--internet --file=/etc/siege/urls.txt --time={$ARRAY["MAX_TIME"]}S";
    $ss[] = "--benchmark --rc=/root/.siegerc >{$filetemp} 2>&1 &";
    $cmd = @implode(" ", $ss);
    echo "{$cmd}\n";
    build_progress_disconnect("{executing}", 50);
    system($cmd);
    sleep(2);
    $pid = $unix->PIDOF($siege);
    while ($unix->process_exists($pid)) {
        $array_mem = getSystemMemInfo();
        $MemFree = $array_mem["MemFree"];
        $array_load = sys_getloadavg();
        $internal_load = $array_load[0];
        echo "Memory Free: " . round($MemFree / 1024) . " MB\n";
        echo "Load: {$internal_load}\n";
        build_progress_disconnect("{please_wait} Load:{$internal_load}", 50);
        sleep(2);
        $pid = $unix->PIDOF($siege);
    }
    build_progress_disconnect("{please_wait} {analyze}...", 90);
    $array = explode("\n", @file_get_contents($filetemp));
    @unlink($filetemp);
    while (list($num, $val) = each($array)) {
        echo "{$val}\n";
        if (preg_match("#alert#", $val)) {
            continue;
        }
        if (preg_match("#ERROR#", $val)) {
            continue;
        }
        if (preg_match("#(.+?):\\s+(.+)#", $val, $re)) {
            $FINAL[trim($re[1])] = trim($re[2]);
        }
    }
    $FINAL["STOP_TIME"] = time();
    build_progress_disconnect("{done}...", 99);
    sleep(5);
    build_progress_disconnect("{done}...", 100);
    @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/siege.report.txt", serialize($FINAL));
    @chmod("/usr/share/artica-postfix/ressources/logs/web/siege.report.txt", 0755);
}
Esempio n. 4
0
function MaxSystemLoad($MonitConfig)
{
    $array_load = sys_getloadavg();
    $internal_load = $array_load[0];
    if ($MonitConfig["MaxLoad"] > 0) {
        if ($internal_load > $MonitConfig["MaxLoad"]) {
            if ($MonitConfig["MaxLoadFailOver"] == 1) {
                $GLOBALS["ALL_SCORES"]++;
                system_is_overloaded();
                squid_admin_mysql(2, "Overloaded system Load: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}", "System reach {$MonitConfig["MaxLoadFailOver"]} value", __FILE__, __LINE__);
                $GLOBALS["ALL_SCORES_WHY"][] = "Overloaded system Load: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}, system {$GLOBALS["SYSTEM_INTERNAL_MEMM"]}MB memory free";
            }
            if ($MonitConfig["MaxLoadReboot"] == 1) {
                squid_admin_mysql(0, "Overloaded system Load: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}: reboot the server", "Watchdog system, reboot the server", __FILE__, __LINE__);
                $unix = new unix();
                $shutdown = $unix->find_program("shutdown");
                $nohup = $unix->find_program("nohup");
                shell_exec("{$nohup} {$shutdown} -r -t 5 >/dev/null 2>&1 &");
                return;
            }
        }
    }
    $array_mem = getSystemMemInfo();
    $MemFree = $array_mem["MemFree"];
    $MemFree = round($MemFree / 1024);
    if ($MonitConfig["MinFreeMem"] > 0) {
        if ($MemFree < $MonitConfig["MinFreeMem"]) {
            squid_admin_mysql(2, "No memory free: {$MemFree}MB, Need at least {$MonitConfig["MinFreeMem"]}MB", __FILE__, __LINE__);
            if ($MonitConfig["MaxLoadFailOver"] == 1) {
                $GLOBALS["ALL_SCORES"]++;
                $GLOBALS["ALL_SCORES_WHY"][] = "No memory free: {$MemFree}MB, Need at least {$MonitConfig["MinFreeMem"]}MB";
            }
        }
    }
}
Esempio n. 5
0
function MaxSystemLoad($MonitConfig)
{
    $sock = new sockets();
    $unix = new unix();
    $shutdown = $unix->find_program("shutdown");
    $nohup = $unix->find_program("nohup");
    $MonitConfig = unserialize(base64_decode($sock->GET_INFO("SquidWatchdogMonitConfig")));
    $MonitConfig = watchdog_config_default($MonitConfig);
    if ($MonitConfig["LOAD_TESTS"] == 0) {
        return;
    }
    $array_load = sys_getloadavg();
    $internal_load = $array_load[0];
    $LOAD_WARNING = $MonitConfig["LOAD_WARNING"];
    $LOAD_MAX = $MonitConfig["LOAD_MAX"];
    $LOAD_MAX_ACTION = $MonitConfig["LOAD_MAX_ACTION"];
    $array_mem = getSystemMemInfo();
    $MemFree = $array_mem["MemFree"];
    $MemFree = round($MemFree / 1024);
    if ($MonitConfig["MinFreeMem"] > 0) {
        $report = $unix->ps_mem_report();
        if ($MemFree < $MonitConfig["MinFreeMem"]) {
            squid_admin_mysql(2, "No memory free: {$MemFree}MB, Need at least {$MonitConfig["MinFreeMem"]}MB", $report, __FILE__, __LINE__);
            if ($MonitConfig["MaxLoadFailOver"] == 1) {
                $GLOBALS["ALL_SCORES"]++;
                $GLOBALS["ALL_SCORES_WHY"][] = "No memory free: {$MemFree}MB, Need at least {$MonitConfig["MinFreeMem"]}MB";
                FailOverDown("No mem free");
                return;
            }
        }
    }
    if ($internal_load > $LOAD_MAX) {
        $report = $unix->ps_mem_report();
        system_is_overloaded();
        $GLOBALS["ALL_SCORES_WHY"][] = "Overloaded system Load: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}, system {$GLOBALS["SYSTEM_INTERNAL_MEMM"]}MB memory free";
        if ($LOAD_MAX_ACTION == "reboot") {
            squid_admin_mysql(0, "Overloaded system Load: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}: reboot the server", $report, __FILE__, __LINE__);
            shell_exec("{$nohup} {$shutdown} -r -t 5 >/dev/null 2>&1 &");
            return;
        }
        if ($LOAD_MAX_ACTION == "failover") {
            squid_admin_mysql(0, "Overloaded system Load: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}: [action=failover]", $report, __FILE__, __LINE__);
            FailOverDown("Overloaded");
            return;
        }
        if ($LOAD_MAX_ACTION == "restart") {
            squid_admin_mysql(0, "Overloaded system Load: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}: [action=restart]", $report, __FILE__, __LINE__);
            restart_squid(true);
            return;
        }
        squid_admin_mysql(0, "Overloaded system Load: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}: Overloaded system [action=none]", $report, __FILE__, __LINE__);
    }
    if ($MonitConfig["MaxLoad"] > 0) {
        $report = $unix->ps_mem_report();
        if ($internal_load > $MonitConfig["MaxLoad"]) {
            if ($MonitConfig["MaxLoadFailOver"] == 1) {
                $GLOBALS["ALL_SCORES"]++;
                system_is_overloaded();
                squid_admin_mysql(2, "Overloaded system Load: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}", "System reach {$MonitConfig["MaxLoadFailOver"]} value", __FILE__, __LINE__);
                $GLOBALS["ALL_SCORES_WHY"][] = "Overloaded system Load: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}, system {$GLOBALS["SYSTEM_INTERNAL_MEMM"]}MB memory free";
            }
            if ($MonitConfig["MaxLoadReboot"] == 1) {
                squid_admin_mysql(0, "Overloaded system Load: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}: reboot the server", "Watchdog system, reboot the server", __FILE__, __LINE__);
                $unix = new unix();
                $shutdown = $unix->find_program("shutdown");
                $nohup = $unix->find_program("nohup");
                shell_exec("{$nohup} {$shutdown} -r -t 5 >/dev/null 2>&1 &");
                return;
            }
        }
    }
}