Ejemplo n.º 1
0
function squid_mem_status($ByExec = false)
{
    $sock = new sockets();
    $tpl = new templates();
    $page = CurrentPageName();
    $unix = new unix();
    $reboot = false;
    $users = new usersMenus();
    $cachefile = "/usr/share/artica-postfix/ressources/logs/web/squid_mem_status.html";
    $cacheSwap = "/usr/share/artica-postfix/ressources/logs/web/squid_swap_status.html";
    $cacheSwapT = "/usr/share/artica-postfix/ressources/logs/web/squid_swap_status.time";
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    if ($ByExec) {
        $pid = $unix->get_pid_from_file($pidFile);
        if ($unix->process_exists($pid)) {
            if ($unix->PROCCESS_TIME_MIN($pid, 10) < 2) {
                return;
            }
        }
        @file_put_contents($pidFile, getmypid());
    }
    $squid_pid = SQUID_PID();
    if (!$unix->process_exists($squid_pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "squid_mem_status(): Squid-Cache is not running\n";
        }
        if (is_file("/usr/share/artica-postfix/ressources/logs/web/status.squid")) {
            @chmod("/usr/share/artica-postfix/ressources/logs/web/status.squid", 0777);
        }
        return;
    }
    $ttl = $unix->PROCCESS_TIME_MIN($squid_pid);
    if ($ttl < 3) {
        if ($GLOBALS["OUTPUT"]) {
            echo "squid_mem_status(): Squid-Cache is running since {$ttl}Mn, please wait at least 5mn\n";
        }
        if (is_file("/usr/share/artica-postfix/ressources/logs/web/status.squid")) {
            @chmod("/usr/share/artica-postfix/ressources/logs/web/status.squid", 0777);
        }
        return;
    }
    if ($GLOBALS["FORCE"]) {
        @unlink($cachefile);
        @unlink($cacheSwap);
        @unlink($cacheSwapT);
    }
    @unlink($cachefile);
    if ($users->WEBSTATS_APPLIANCE) {
        return null;
    }
    $datas = unserialize(base64_decode(squid_get_system_info()));
    $StoreDirs = unserialize(base64_decode(squid_get_storage_info()));
    $freebin = $unix->find_program("free");
    $MEMSEC = $datas["Memory usage for squid via mallinfo()"];
    $Total_space_in_arena = trim($MEMSEC["Total space in arena"]);
    $Total_in_use = trim($MEMSEC["Total in use"]);
    $InternalDataStructures = $datas["Internal Data Structures"];
    $StoreEntriesWithMemObjects = $InternalDataStructures["StoreEntries with MemObjects"];
    $HotObjectCacheItems = $InternalDataStructures["Hot Object Cache Items"];
    exec("{$freebin} -m 2>&1", $results);
    while (list($index, $ligne) = each($results)) {
        if (preg_match("#^Swap:\\s+([0-9]+)\\s+([0-9]+)#", $ligne, $re)) {
            $SwapTotal = $re[1];
            $SwapUsed = $re[2];
            $SwapPerc = $SwapUsed / $SwapTotal * 100;
            $SwapPerc = round($SwapPerc, 1);
            break;
        }
    }
    @unlink($cacheSwap);
    if ($SwapPerc > 40) {
        $cacheSwapTime = $unix->file_time_min($cacheSwapT);
        if ($cacheSwapTime > 30) {
            @unlink($cacheSwapT);
            @file_put_contents($cacheSwapT, time());
            squid_admin_mysql(1, "{high_swap_value} {$SwapPerc}%", "{high_swap_value_exceed_explain}");
        }
    }
    if ($SwapPerc > 10) {
        $swaphtml = "<div style='min-height:147px'>\n\t\t<table style='width:100%'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td style='vertical-align:top'><img src='img/warning-panneau-42.png'></td>\n\t\t\t\t\t<td style='vertical-align:top'><div style='font-size:14px;font-weight:bold'>{high_swap_value} {$SwapPerc}%</div>\n\t\t\t\t\t<div style='font-weight:bold'>{high_swap_value_exceed_explain}</div>\n\t\t\t\t</tr>\n\t\t</table>\n\t\t</div>\t\t\t\t\n\t\t";
        @file_put_contents($cacheSwap, RoundedLightGreen($swaphtml));
        @chmod($cacheSwap, 0755);
    }
    $ConnectionInformationForSquid = $datas["Connection information for squid"];
    $NumberOfHTTPRequestsReceived = $ConnectionInformationForSquid["Number of HTTP requests received"];
    $AverageHTTPRequestsPerMinuteSinceStart = round($ConnectionInformationForSquid["Average HTTP requests per minute since start"]);
    $StorageMemSize = $datas["Cache information for squid"]["Storage Mem size"];
    $StorageMemCapacity = $datas["Cache information for squid"]["Storage Mem capacity"];
    preg_match("#^([0-9]+)\\s+([A-Z]+)#", trim($StorageMemSize), $re);
    $StorageMemSize = round($re[1] / 1024, 2);
    preg_match("#([0-9\\.]+)% used#", trim($StorageMemCapacity), $re);
    $StorageMemCapacityPourc = $re[1];
    preg_match("#^([0-9]+)\\s+([A-Z]+)#", trim($MEMSEC["Total space in arena"]), $re);
    if ($re[2] == "KB") {
        $Total_space_in_arena = round($Total_space_in_arena / 1024, 2);
    }
    if ($re[2] == "GB") {
        $Total_space_in_arena = round($Total_space_in_arena * 1024, 2);
    }
    preg_match("#^([0-9]+)\\s+([A-Z]+).*?([0-9\\.]+)%#", $Total_in_use, $re);
    $USED_VALUE = $re[1];
    $USED_UNIT = $re[2];
    $USED_PRC = $re[3];
    if ($USED_UNIT == "KB") {
        $USED_VALUE = round($USED_VALUE / 1024, 2);
    }
    if ($USED_UNIT == "GB") {
        $USED_VALUE = round($USED_VALUE * 1024, 2);
    }
    $NumberOfHTTPRequestsReceived = FormatNumber($NumberOfHTTPRequestsReceived);
    $HotObjectCacheItems = FormatNumber($HotObjectCacheItems);
    $StoreEntriesWithMemObjects = FormatNumber($StoreEntriesWithMemObjects);
    if (isset($StoreDirs["MEM"])) {
        $BigMem = $StoreDirs["MEM"]["SIZE"];
        $Items = $StoreDirs["MEM"]["ENTRIES"];
        if ($BigMem > 0) {
            $MemDir = "\t<tr>\n\t\t\t\t<td style='font-weight:bold;font-size:12px' align='right' nowrap>{memory_cache}:</td>\n\t\t\t\t<td style='font-weight:bold;font-size:12px'>" . FormatBytes($BigMem) . " ({$Items} {items})</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t<td>" . pourcentage($StoreDirs["MEM"]["PERC"]) . "</td>\n\t\t\t</tr>\t";
        }
    }
    $usersC = 0;
    $ipzs = 0;
    $size = 0;
    $q = new mysql_squid_builder();
    $current_table = "quotahours_" . date('YmdH', time());
    if ($q->COUNT_ROWS($current_table) > 0) {
        $results = $q->QUERY_SQL("SELECT COUNT(uid) as tcount FROM {$current_table} GROUP BY uid");
        $usersC = mysql_num_rows($results);
        $results = $q->QUERY_SQL("SELECT COUNT(ipaddr) as tcount FROM {$current_table} GROUP BY ipaddr");
        $ipzs = mysql_num_rows($results);
        $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT SUM(size) as size FROM {$current_table}"));
        if ($ligne["size"] > 0) {
            $size = FormatBytes($ligne["size"] / 1024);
        }
    }
    $imgRefresh = imgtootltip("20-refresh.png", "{refresh}", "Loadjs('squid.store.status.php',true)");
    $html = "\n\t<div style='min-height:147px'>\n\t\t<table style='width:100%'>\n\t\t\t{$MemDir}\n\t\t\t<tr>\n\t\t\t\t<td style='font-weight:bold;font-size:12px' align='right'>{memory}:</td>\n\t\t\t\t<td style='font-weight:bold;font-size:12px'>{$StorageMemSize}&nbsp;MB</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t<td>" . pourcentage($StorageMemCapacityPourc) . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td style='font-weight:bold;font-size:12px' align='right'>{objects}:</td>\n\t\t\t\t<td style='font-weight:bold;font-size:12px'>{$StoreEntriesWithMemObjects}</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td style='font-weight:bold;font-size:12px' align='right'>{hot_objects}:</td>\n\t\t\t\t<td style='font-weight:bold;font-size:12px'>{$HotObjectCacheItems}</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td style='font-weight:bold;font-size:12px' align='right'>{requests}:</td>\n\t\t\t\t<td style='font-weight:bold;font-size:12px'>{$NumberOfHTTPRequestsReceived} ({$AverageHTTPRequestsPerMinuteSinceStart} {requests}/{minute})</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td style='font-weight:bold;font-size:12px' align='right'>{members}:</td>\n\t\t\t\t<td style='font-weight:bold;font-size:12px'>{$usersC}</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td style='font-weight:bold;font-size:12px' align='right'>{clients}:</td>\n\t\t\t\t<td style='font-weight:bold;font-size:12px'>{$ipzs} ({$size})</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td colspan=2 align='right'>{$imgRefresh}</td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t</div>\n\t";
    @file_put_contents($cachefile, RoundedLightGreen($html));
    @chmod($cachefile, 0755);
    if (is_file("/usr/share/artica-postfix/ressources/logs/web/status.squid")) {
        @chmod("/usr/share/artica-postfix/ressources/logs/web/status.squid", 0777);
    }
}
Ejemplo n.º 2
0
    exit;
}
if (isset($_GET["force-cache-status"])) {
    squid_force_cache_status();
    exit;
}
if (isset($_GET["catzdb-changedir"])) {
    catzdb_changedir();
    exit;
}
if (isset($_GET["ufdbclient"])) {
    ufdbclient_tests();
    exit;
}
if (isset($_GET["squid-get-system-info"])) {
    squid_get_system_info();
    exit;
}
if (isset($_GET["squid-get-storage-info"])) {
    squid_get_storage_info();
    exit;
}
if (isset($_GET["MacToUidStats"])) {
    MacToUidStats();
    exit;
}
if (isset($_GET["MacToUid"])) {
    MacToUid();
    exit;
}
if (isset($_GET["watchdog-log"])) {