header(); $ui->template_open(); $ui->message("Statistics", "These statistics are generated on-the-fly from the latest uptime data. If you notice anything that looks bogus, please let me know."); $ui->statsbar(); $ui->template_close(); $ui->footer(); break; ################################### # All Hosts ################################### case "all": $ui->header("The Uptimes Project - All Hosts"); $ui->template_open(); $ui->message("All Hosts", ""); $ui->statsbar(); if (!isset($s)) $s = 0; $result = $db->query("SELECT COUNT(h.id) as count FROM hosts h, uptimes u WHERE h.auth_id = u.auth_id AND h.last_heard = u.reported"); $tmp = $result[0]; $hostcount = $tmp->count; $pages = ceil($hostcount / 30); // What should we order by? $sortfield = trim(@$_GET["f"]); $sorttype = trim(@$_GET["t"]); if ($sortfield == "") $sortfield = "h.name"; if ($sorttype == "") $sorttype = "ASC"; $hosts = $db->query("SELECT h.id, h.name, p.os, p.oslevel, p.cpu, p.uptime, p.cpu_load, p.idle, u.user FROM hosts h, uptimes p, users u WHERE u.id = h.user_id AND h.auth_id = p.auth_id AND p.reported = h.last_heard ORDER BY $sortfield $sorttype LIMIT $s, 30"); print "\n"; if ($hostcount > 30) { if ($s > 29) print " \n"; else print " \n"; print " \n"; if ($hostcount > ($s + 30)) print " \n"; else print " \n"; } print " \n"; $class = "roweven"; foreach($hosts as $foo) { if ($class == "roweven") $class = "rowodd"; else $class = "roweven"; print " \n"; } if ($hostcount > 30) { if ($s > 29) print " \n"; else print " \n"; print " \n"; if ($hostcount > ($s + 30)) print " \n"; else print " \n"; } print "
« Prev
 \n"; for($i = 0; $i < $pages; $i++) print " ".($i + 1)."\n"; print " Next »
 
\n"; printSortLinks("Hostname", "h.name", $sortfield, $sorttype); print " \n"; printSortLinks("Owner", "u.user", $sortfield, $sorttype); print " \n"; printSortLinks("OS", "p.os", $sortfield, $sorttype); print " \n"; printSortLinks("CPU", "p.cpu", $sortfield, $sorttype); print " \n"; printSortLinks("Uptime", "p.uptime", $sortfield, $sorttype); print " \n"; printSortLinks("Load", "p.cpu_load", $sortfield, $sorttype); print " \n"; printSortLinks("Idle", "p.idle", $sortfield, $sorttype); print "
\n"; print " id."\">".wordwrap(sh($foo->name), 20, "
", 1)."
\n"; print "
\n"; print " ".$foo->user."\n"; print " \n"; print " ".$foo->os." ".$foo->oslevel."\n"; print " \n"; print " ".$foo->cpu."\n"; print " \n"; print " ".parseUptime($foo->uptime)."\n"; print " \n"; if ($foo->cpu_load != "") print " ".$foo->cpu_load."%\n"; print " \n"; if ($foo->idle != "") print " ".$foo->idle."%\n"; print "
« Prev
 \n"; for($i = 0; $i < $pages; $i++) print " ".($i + 1)."\n"; print " Next »
 
\n"; $ui->template_close(); $ui->footer(); break; ################################### # Active Hosts ################################### case "active": $ui->header("The Uptimes Project - Active Hosts"); $ui->template_open(); $ui->message("Active Hosts", ""); $ui->statsbar(); if (!isset($s)) $s = 0; $result = $db->query("SELECT DISTINCT h.id FROM hosts h, uptimes u WHERE h.bogus = 0 AND u.uptime > 0 AND reported > ".(time() - 600)." AND h.auth_id = u.auth_id"); $hostcount = count($result); $pages = ceil($hostcount / 30); $hosts = $db->query("SELECT DISTINCT h.id AS host_id, user_id, name, h.auth_id AS auth_id, h.last_heard AS last_heard, u.os AS os, u.oslevel AS oslevel, u.cpu AS cpu, u.uptime AS uptime, u.cpu_load AS cpu_load, u.idle AS idle FROM hosts h, uptimes u WHERE h.bogus = 0 AND h.auth_id = u.auth_id AND reported > ".(time() - 600)." ORDER BY u.uptime DESC LIMIT $s, 30"); print "\n"; if ($hostcount > 30) { if ($s > 29) print " \n"; else print " \n"; print " \n"; if ($hostcount > ($s + 30)) print " \n"; else print " \n"; } print " \n"; $i=$s; $class = "roweven"; foreach($hosts as $foo) { if ($class == "roweven") $class = "rowodd"; else $class = "roweven"; $result = $db->query("SELECT * FROM users WHERE id = ".$foo->user_id." LIMIT 1"); $user = $result[0]; $i++; print " \n"; } if ($hostcount > 30) { if ($s > 29) print " \n"; else print " \n"; print " \n"; if ($hostcount > ($s + 30)) print " \n"; else print " \n"; } print "
« Prev
 \n"; for($i = 0; $i < $pages; $i++) print " ".($i + 1)."\n"; print " Next »
 
\n"; print " #\n"; print " \n"; print " Hostname\n"; print " \n"; print " Owner\n"; print " \n"; print " OS\n"; print " \n"; print " CPU\n"; print " \n"; print " Uptime\n"; print " \n"; print " Load\n"; print " \n"; print " Idle\n"; print "
\n"; print " $i.\n"; print " \n"; print " host_id."\">".stripslashes($foo->name)."\n"; print " \n"; print " $user->user\n"; print " \n"; print " ".$foo->os." ".stripslashes($foo->oslevel)."\n"; print " \n"; print " ".stripslashes($foo->cpu)."\n"; print " \n"; print " ".parseUptime($foo->uptime)."\n"; print " \n"; if ($foo->cpu_load != "") print " ".$foo->cpu_load."%\n"; print " \n"; if ($foo->idle != "") print " ".$foo->idle."%\n"; print "
« Prev
 \n"; for($i = 0; $i < $pages; $i++) print " ".($i + 1)."\n"; print " Next »
 
\n"; $ui->template_close(); $ui->footer(); break; ################################### # General Site Stats ################################### case "general": $total = $db->query("SELECT COUNT(id) AS count FROM hosts"); $total = $total[0]->count; $active = $db->query("SELECT COUNT(id) AS count FROM hosts WHERE last_heard > (".time()." - 600)"); $active = $active[0]->count; $average = $db->query("SELECT (SUM(uptime) / COUNT(id)) AS average, SUM(uptime) AS total FROM uptimes"); $totaluptime = $average[0]->total; $average = $average[0]->average; $record = $db->query("SELECT uptime, os, oslevel, cpu FROM uptimes ORDER BY uptime DESC LIMIT 1"); $record = $record[0]; $ui->header("The Uptimes Project - General Site Statistics"); $ui->template_open(); $ui->message("General Site Statistics", ""); $ui->statsbar(); ?> Total Hosts:
Active Hosts:
Record Uptime: uptime)?> (os." ".$record->oslevel.", ".$record->cpu?>)
Overall Average Uptime:
Total Combined Uptime:

Average Uptime by OS
OS Popularity template_close(); $ui->footer(); break; ################################### # OS Breakdown ################################### case "os": $ui->header("The Uptimes Project - OS Breakdown"); $ui->template_open(); $ui->message("OS Breakdown", ""); $ui->statsbar(); if (!isset($s)) $s = 0; ?> query("SELECT DISTINCT os FROM uptimes WHERE os <> '' ORDER BY os"); $fuckthisshit = array(); $i = 0; $class = "roweven"; foreach($oses as $foo) { if ($class == "roweven") $class = "rowodd"; else $class = "roweven"; if (!in_array($foo->os, $fuckthisshit)) { array_push($fuckthisshit, $foo->os); $result = $db->query("SELECT uptime FROM uptimes WHERE os = '".$foo->os."' ORDER BY uptime DESC LIMIT 1"); $uptimes = $result[0]; $result = $db->query("SELECT AVG(uptime) AS uptime, AVG(cpu_load) AS cpu_load FROM uptimes WHERE os = '".$foo->os."'"); $avg = $result[0]; $result = $db->query("SELECT DISTINCT auth_id FROM uptimes WHERE os = '".$foo->os."' AND reported > ".(time() - 600)); $total = count($result); ?> \n"; $ui->template_close(); $ui->footer(); break; ################################### # CPU Breakdown ################################### case "cpu": $ui->header("The Uptimes Project - CPU Breakdown"); $ui->template_open(); $ui->message("CPU Breakdown", ""); $ui->statsbar(); if (!isset($s)) $s = 0; print "
OS Active Hosts Highest Uptime Average Uptime Average CPU Load
os?> uptime)?> uptime)?> cpu_load, 2)?>%
\n"; print " \n"; $cpus = $db->query("SELECT cpu, uptime FROM uptimes WHERE cpu <> '' GROUP BY cpu ORDER BY uptime DESC LIMIT 30"); $fuckthisshit = array(); $i = 0; $class = "roweven"; foreach($cpus as $foo) { if ($class == "roweven") $class = "rowodd"; else $class = "roweven"; if (!in_array($foo->cpu, $fuckthisshit)) { array_push($fuckthisshit, $foo->cpu); print " \n"; $i++; } } print "
\n"; print " CPU\n"; print " \n"; print " Highest Uptime\n"; print "
\n"; print " ".stripslashes($foo->cpu)."\n"; print " \n"; print " ".parseUptime($foo->uptime)."\n"; print "
\n"; $ui->template_close(); $ui->footer(); break; ################################### # Client Breakdown ################################### case "client": $ui->header("The Uptimes Project - Client Breakdown"); $ui->template_open(); $ui->message("Client Breakdown", ""); $ui->statsbar(); if (!isset($s)) $s = 0; print "\n"; print " \n"; $clients = $db->query("SELECT client, COUNT(client) AS count FROM uptimes u, hosts h WHERE u.auth_id = h.auth_id AND h.bogus = 0 AND reported > ".(time() - 600)." GROUP BY client ORDER BY client"); $class="roweven"; foreach($clients as $foo) { if ($class == "roweven") $class = "rowodd"; else $class = "roweven"; print " \n"; } print "
\n"; print " Client Name\n"; print " \n"; print " Active Hosts\n"; print "
\n"; print " ".sh($foo->client)."\n"; print " \n"; print " $foo->count\n"; print "
\n"; $ui->template_close(); $ui->footer(); break; default: echo "Wow. You certainly should never see this. Something must have gone horribly wrong."; break; } ?>