echo ' <p> <a href="?order=' . urlencode($order) . '">' . $info[0] . '</a> </p>'; } if (isset($_GET['order']) && array_key_exists($_GET['order'], $orders)) { $order = $_GET['order']; $_base->page->add_message($orders[$order][1]); } else { if (isset($_GET['order'])) { $_base->page->add_message("Ugyldig sorteringsnavn.", "error"); } $_base->page->load(); } $request = new httpreq(); $data = $request->get("/httpd-status-server", array()); if (!$data) { echo ' <p><b>Feil:</b> Kunne ikke hente data.</p>'; } else { $data = $data['content']; // offset $data = mb_substr($data, mb_strpos($data, '<b>Request</b></td></tr>')); /* <tr bgcolor="#ffffff"><td><b>0-0</b><td>12488<td>10/4899/26246<td><b>K</b> <td>100.31<td>2<td>3<td>54.7<td>22.59<td>126.61 <td nowrap><font face="Arial,Helvetica" size="-1">80.212.189.104</font><td nowrap><font face="Arial,Helvetica" size="-1">www.kofradia.no</font><td nowrap><font face="Arial,Helvetica" size="-1">GET /antibot/bilde?aid=12022&id=9&c=117269810661 HTTP/1.1</font></tr> */ $result = false;
/** Hent status */ public function c_status() { // hent server info $request = new httpreq(); $request->actualhost = "kofradia.no"; $data = $request->get("/httpd-status-server", array()); $c = $data['content']; // finn antall requests pr sekund $p1 = mb_strpos($c, "CPU Usage"); if ($p1 !== false) { $p2 = mb_strpos($c, "\n", $p1) + 1; $p3 = mb_strpos($c, "\n", $p2) - 4; // finn ut cpu load $p4 = mb_strpos($c, "-", $p1) + 2; $p5 = mb_strpos($c, "%", $p4) + 1; // finn antall requests i dette øyeblikket $req = explode(" ", mb_substr($c, $p3 + 6, 10)); $req = $req[0]; $load = str_replace(array(".", "%"), array(",", " %"), mb_substr($c, $p4, $p5 - $p4)); $status = explode(" - ", mb_substr($c, $p2, $p3 - $p2)); $status[0] = explode(" ", $status[0]); $status[0] = str_replace(".", ",", $status[0][0]); $status[1] = explode(" ", $status[1]); $status[1] = str_replace(".", ",", $status[1][0]); $status[2] = explode(" ", $status[2]); $status[2] = str_replace(".", ",", $status[2][0]); } else { $load = "ERROR"; $req = "ERROR"; $status = array("ERROR", "ERROR", "ERROR"); } // minne informasjon $mem = shell_exec("free -t"); $matches = false; if (preg_match("/Mem:\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)/u", $mem, $matches)) { $mem_percent = number_format($matches[2] / $matches[1] * 100, 1, ",", " "); } else { $mem_percent = "ERROR"; } // hent antall brukere pålogget $result = \Kofradia\DB::get()->query("SELECT COUNT(IF(up_last_online > " . (time() - 1800) . ", 1, NULL)), COUNT(IF(up_last_online > " . (time() - 900) . ", 1, NULL)), COUNT(IF(up_last_online > " . (time() - 600) . ", 1, NULL)), COUNT(IF(up_last_online > " . (time() - 300) . ", 1, NULL)), COUNT(IF(up_last_online > " . (time() - 60) . ", 1, NULL)), COUNT(IF(up_last_online > " . (time() - 30) . ", 1, NULL)) FROM users_players"); $row = $result->fetch(\PDO::FETCH_NUM); $ret = "Status: Antall pålogget siste sekunder: 1800={$row[0]}, 900={$row[1]}, 600={$row[2]}, 300={$row[3]}, 60={$row[4]}, 30={$row[5]}. CPU: {$load}. Visninger/sekund: {$status[0]}. Nå: {$req}. Minnebruk: {$mem_percent}"; $this->send_output($ret); }