Exemplo n.º 1
0
function squid_memory_monitor()
{
    $unix = new unix();
    $sock = new sockets();
    $MonitConfig = unserialize(base64_decode($sock->GET_INFO("SquidWatchdogMonitConfig")));
    $MonitConfig = watchdog_config_default($MonitConfig);
    $total_memory = 0;
    $python = $unix->find_program("python");
    exec("{$python} /usr/share/artica-postfix/bin/ps_mem.py 2>&1", $results);
    while (list($index, $line) = each($results)) {
        $line = trim($line);
        if (!preg_match("#^[0-9\\.]+.*?=\\s+([0-9\\.]+)\\s+([a-zA-Z]+)\\s+squid#", $line, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "No match {$line}\n";
            }
            continue;
        }
        $total_memory = $re[1];
        $total_memory_unit = $re[2];
        if ($GLOBALS["VERBOSE"]) {
            echo "!!Match : {$total_memory} {$total_memory_unit}\n";
        }
        break;
    }
    if ($total_memory == 0) {
        return;
    }
    if ($total_memory_unit == "KiB") {
        $total_memory = round($total_memory * 1024);
    }
    if ($total_memory_unit == "MiB") {
        $total_memory = round($total_memory * 1024);
        $total_memory = $total_memory * 1024;
    }
    if ($total_memory_unit == "GiB") {
        $total_memory = round($total_memory * 1024);
        $total_memory = $total_memory * 1024;
        $total_memory = $total_memory * 1024;
    }
    $timekey = date('Ymd');
    $q = new mysql_squid_builder();
    $table = "squidmemory_{$timekey}";
    $sql = "CREATE TABLE IF NOT EXISTS `squidlogs`.`{$table}` (\n\t`zDate` DATETIME NOT NULL,\n\t`memoryuse` INT UNSIGNED NOT NULL,\n\t`percent` FLOAT NOT NULL,\n\tPRIMARY KEY `zDate`(`zDate`),\n\tKEY `memoryuse`(`memoryuse`),\n\tKEY `percent`(`percent`)\n\n\t) ENGINE=MYISAM;";
    $q->QUERY_SQL($sql, $q->database);
    if (!$q->ok) {
        squid_admin_mysql(1, "MySQL error", $q->mysql_error, __FILE__, __LINE__);
    }
    $total_memory_MB = $total_memory / 1024;
    $total_memory_MB = $total_memory_MB / 1024;
    $MEMORY_SYSTEM_MB = $unix->SYSTEM_GET_MEMORY_MB();
    if ($GLOBALS["VERBOSE"]) {
        echo "MEMORY_SYSTEM_MB: {$MEMORY_SYSTEM_MB}MB\n";
    }
    $prc = $total_memory_MB / $MEMORY_SYSTEM_MB;
    $prc = round($prc * 100, 2);
    $total_memory_MB = round($total_memory_MB);
    if ($GLOBALS["VERBOSE"]) {
        echo "Bytes: {$total_memory} MB: {$total_memory_MB}/{$MEMORY_SYSTEM_MB} ({$prc}%) \n";
    }
    $date = date("Y-m-d H:i:s");
    $q->QUERY_SQL("INSERT INTO `{$table}` (zDate,memoryuse,`percent`) VALUES ('{$date}','{$total_memory_MB}','{$prc}')");
    if (!$q->ok) {
        squid_admin_mysql(1, "MySQL error", $q->mysql_error, __FILE__, __LINE__);
    }
    squid_memory_month();
    if ($MonitConfig["watchdog"] == 0) {
        return;
    }
    if ($MonitConfig["watchdogRestart"] > 99) {
        return;
    }
    if ($prc > $MonitConfig["watchdogRestart"]) {
        $GLOBALS["ALL_SCORES"]++;
        $GLOBALS["ALL_SCORES_WHY"][] = "Proxy service memory exceed % value ({$prc})";
        $GLOBALS["BY_WATCHDOG"] = true;
        restart_squid(true);
    }
}
Exemplo n.º 2
0
    exit;
}
if (isset($_GET["freeweb-start"])) {
    freeweb_start();
    exit;
}
if (isset($_GET["schedule-apps"])) {
    apps_upgrade();
    exit;
}
if (isset($_GET["restart-arpd"])) {
    restart_arpd();
    exit;
}
if (isset($_GET["restart-squid"])) {
    restart_squid();
    exit;
}
if (isset($_GET["time-capsule-status"])) {
    time_capsule_status();
    exit;
}
if (isset($_GET["BULK_IMAP_SCHEDULE"])) {
    BULK_IMAP_SCHEDULE();
    exit;
}
if (isset($_GET["restart-netatalk"])) {
    restart_netatalk();
    exit;
}
if (isset($_GET["build-iptables"])) {
Exemplo n.º 3
0
function dev_shm()
{
    $NotifyTime = "/etc/artica-postfix/pids/squid.dev.shm";
    if (!is_dir("/run/shm")) {
        return;
    }
    $sock = new sockets();
    $MonitConfig = unserialize(base64_decode($sock->GET_INFO("SquidWatchdogMonitConfig")));
    $MonitConfig = watchdog_config_default($MonitConfig);
    $unix = new unix();
    $percent = $unix->TMPFS_USEPERCENT("/run/shm");
    @file_put_contents("/etc/artica-postfix/settings/Daemons/StatusDevSHMPerc", $percent);
    @chmod("/etc/artica-postfix/settings/Daemons/StatusDevSHMPerc", 0755);
    if ($percent > 90) {
        if ($percent < 98) {
            $NotifyTimeEx = $unix->file_time_min($NotifyTime);
            if ($NotifyTimeEx > 10) {
                squid_admin_mysql(2, "Warning Shared memory exceed 90%!", "The /dev/shm memory partition exceed 90%, at 100% the proxy will crash!");
                return;
            }
        }
    }
    if ($percent > 98) {
        if ($MonitConfig["watchdog"] == 1) {
            squid_admin_mysql(0, "Warning Shared memory exceed 98% ({$percent}%)[action=restart]", "The /dev/shm memory partition exceed 98%, at 100% the proxy will crash!, in this case, the proxy will be restarted.");
            $GLOBALS["BY_OTHER_SCRIPT"] = "function SHM";
            $GLOBALS["FORCE"] = true;
            restart_squid(true);
        } else {
            squid_admin_mysql(0, "Warning Shared memory exceed 98% ({$percent}%) [action=notify]", "The /dev/shm memory partition exceed 98%, at 100% the proxy will crash!");
        }
    }
}