function xtsart() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; if ($GLOBALS["VERBOSE"]) { echo "TimeFile:{$pidTime}\n"; } $unix = new unix(); if (!$GLOBALS["VERBOSE"]) { if ($unix->file_time_min($pidTime) < 10) { die; } if ($unix->process_exists(@file_get_contents($pidfile, basename(__FILE__)))) { if ($GLOBALS["VERBOSE"]) { echo " --> Already executed.. " . @file_get_contents($pidfile) . " aborting the process\n"; } writelogs(basename(__FILE__) . ":Already executed.. aborting the process", basename(__FILE__), __FILE__, __LINE__); die; } @file_put_contents($pidfile, getmypid()); @unlink($pidTime); @file_put_contents($pidTime, time()); } $array_load = sys_getloadavg(); $internal_load = $array_load[0]; $time = time(); $BASEDIR = "/usr/share/artica-postfix"; $hash_mem = array(); @chmod("/usr/share/artica-postfix/ressources/mem.pl", 0755); $datas = shell_exec(dirname(__FILE__) . "/ressources/mem.pl"); if (preg_match('#T=([0-9]+) U=([0-9]+)#', $datas, $re)) { $ram_used = $re[2]; } $cpuUsage = null; $ps = $unix->find_program("ps"); exec("{$ps} -aux 2>&1", $processes); foreach ($processes as $process) { $cols = explode(' ', preg_replace('# +#', ' ', $process)); if (strpos($cols[2], '.') > -1) { $cpuUsage += floatval($cols[2]); } } if ($GLOBALS["VERBOSE"]) { echo "CPU: {$cpuUsage}, LOAD: {$internal_load}, MEM: {$ram_used}\n"; } $q = new postgres_sql(); $q->CREATE_TABLES(); $proxyname = $unix->hostname_g(); $time = date("Y-m-d H:i:s"); $sql = "INSERT INTO system (zdate,proxyname,load_avg,mem_stats,cpu_stats)\n\tVALUES('{$time}','{$proxyname}','{$internal_load}','" . intval($ram_used) . "','{$cpuUsage}')"; if ($GLOBALS["VERBOSE"]) { echo $sql . "\n"; } $q->QUERY_SQL($sql); if (!$q->ok) { echo $q->mysql_error . "\n"; } RXTX(); if (system_is_overloaded(basename(__FILE__))) { $date = time(); @mkdir("/var/log/artica-postfix/sys_alerts", 0755, true); if (!is_file("/var/log/artica-postfix/sys_alerts/{$date}")) { $ps = $unix->find_program("ps"); $nohup = $unix->find_program($nohup); $nice = $unix->EXEC_NICE(); $load = $GLOBALS["SYSTEM_INTERNAL_LOAD"]; if (!$unix->process_exists($unix->PIDOF_PATTERN("{$ps}"))) { $cmd = trim("{$nohup} {$nice} {$ps} auxww >/var/log/artica-postfix/sys_alerts/{$date}-{$load} 2>&1"); shell_exec($cmd); } } } }
function xtsart() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; if ($GLOBALS["VERBOSE"]) { echo "TimeFile:{$pidTime}\n"; } $unix = new unix(); if (!$GLOBALS["VERBOSE"]) { if ($unix->file_time_min($pidTime) < 10) { die; } if ($unix->process_exists(@file_get_contents($pidfile, basename(__FILE__)))) { if ($GLOBALS["VERBOSE"]) { echo " --> Already executed.. " . @file_get_contents($pidfile) . " aborting the process\n"; } writelogs(basename(__FILE__) . ":Already executed.. aborting the process", basename(__FILE__), __FILE__, __LINE__); die; } @file_put_contents($pidfile, getmypid()); @unlink($pidTime); @file_put_contents($pidTime, time()); } $array_load = sys_getloadavg(); $internal_load = $array_load[0]; $time = time(); $BASEDIR = "/usr/share/artica-postfix"; $hash_mem = array(); @chmod("/usr/share/artica-postfix/ressources/mem.pl", 0755); $datas = shell_exec(dirname(__FILE__) . "/ressources/mem.pl"); if (preg_match('#T=([0-9]+) U=([0-9]+)#', $datas, $re)) { $ram_used = $re[2]; } $cpuUsage = null; $ps = $unix->find_program("ps"); exec("{$ps} -aux 2>&1", $processes); foreach ($processes as $process) { $cols = explode(' ', preg_replace('# +#', ' ', $process)); if (strpos($cols[2], '.') > -1) { $cpuUsage += floatval($cols[2]); } } if ($GLOBALS["VERBOSE"]) { echo "CPU: {$cpuUsage}, LOAD: {$internal_load}, MEM: {$ram_used}\n"; } $array["fields"]["LOAD_AVG"] = $internal_load; $array["fields"]["MEM_STATS"] = intval($ram_used); $array["fields"]["CPU_STATS"] = $cpuUsage; $array["tags"]["proxyname"] = $unix->hostname_g(); $influx = new influx(); $influx->insert("SYSTEM", $array); RXTX(); if (system_is_overloaded(basename(__FILE__))) { $date = time(); @mkdir("/var/log/artica-postfix/sys_alerts", 0755, true); if (!is_file("/var/log/artica-postfix/sys_alerts/{$date}")) { $ps = $unix->find_program("ps"); $nohup = $unix->find_program($nohup); $nice = $unix->EXEC_NICE(); $load = $GLOBALS["SYSTEM_INTERNAL_LOAD"]; if (!$unix->process_exists($unix->PIDOF_PATTERN("{$ps}"))) { $cmd = trim("{$nohup} {$nice} {$ps} auxww >/var/log/artica-postfix/sys_alerts/{$date}-{$load} 2>&1"); shell_exec($cmd); } } } }