index : website | |
Archlinux32 website - obsolete | gitolite user |
summaryrefslogtreecommitdiff |
author | Erich Eckner <git@eckner.net> | 2018-06-15 13:24:07 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-06-15 13:24:07 +0200 |
commit | e1504b8394f3aa5cad02b1bfe0f9721877c2682b (patch) | |
tree | 0852ee62a49efefe1e42b9e7dfc9ecfb735f37be /mirrors/status.php | |
parent | c99916b8b22428b056f5424ae6d81fe9299a5180 (diff) |
-rw-r--r-- | mirrors/status.php | 71 |
diff --git a/mirrors/status.php b/mirrors/status.php new file mode 100644 index 0000000..7044386 --- /dev/null +++ b/mirrors/status.php @@ -0,0 +1,71 @@ +<?php + +include "lib/mysql.php"; + +$cutoff = 86400; + +mysql_run_query( + "CREATE TEMPORARY TABLE `ls` (`id` BIGINT NOT NULL, PRIMARY KEY (`id`))" +); + +mysql_run_query( + "INSERT INTO `ls` (`id`)" . + " SELECT `ms`.`id`" . + " FROM `mirror_statuses` AS `ms`" . + " WHERE NOT EXISTS (" . + "SELECT 1 FROM `mirror_statuses` AS `n_ms`" . + " WHERE `n_ms`.`url`=`ms`.`url`" . + " AND `n_ms`.`start`>`ms`.`start`" . + ") AND `ms`.`start` > UNIX_TIMESTAMP(NOW())-" . $cutoff +); + +$result = mysql_run_query( + "SELECT " . + "`l_ms`.`protocol`," . + "`l_ms`.`url`," . + "`l_ms`.`country`," . + "`l_ms`.`country_code`," . + "`l_ms`.`last_sync`," . + "`l_ms`.`start`," . + "AVG(IF(`a_ms`.`active`,(`a_ms`.`start`-`a_ms`.`last_sync`)/3600,NULL)) AS `delay`," . + "AVG(IF(`a_ms`.`active`,(`a_ms`.`stop`-`a_ms`.`start`)/3600,NULL)) AS `duration_avg`," . + "STD(IF(`a_ms`.`active`,(`a_ms`.`stop`-`a_ms`.`start`)/3600,NULL)) AS `duration_stddev`," . + "`l_ms`.`isos`," . + "`l_ms`.`ipv4`," . + "`l_ms`.`ipv6`," . + "`l_ms`.`active`," . + "AVG(IF(`a_ms`.`active`,1,0)) AS `completion`," . + "COUNT(1) AS `count`" . + " FROM `ls`" . + " JOIN `mirror_statuses` AS `l_ms` ON `ls`.`id`=`l_ms`.`id`" . + " JOIN `mirror_statuses` AS `a_ms` ON `a_ms`.`url`=`l_ms`.`url`" . + " AND `a_ms`.`start` > UNIX_TIMESTAMP(NOW())-" . $cutoff . + " GROUP BY `l_ms`.`id`" +); + +$last_check = 0; +$max_count = 0; + +while($row = $result->fetch_assoc()) { + $row["score"] = + ($row["delay"] + $row["duration_avg"] + $row["duration_stddev"]) / $row["completion"]; + $urls[] = $row; + $last_check = max ($row["start"], $last_check); + $max_count = max ($row["count"], $max_count); +} + +$content = array( + "cutoff" => $cutoff, + "check_frequency" => $cutoff/$max_count, + "num_checks" => $max_count, + "last_check" => gmdate("Y-m-d\TH:i:s.v",$last_check), //"2018-06-15T07:25:06.741Z", +// "version" => 3, + "urls" => $urls +); + +if (isset($_GET["json"])) { + header ("Content-type: application/json"); + print json_encode($content,JSON_UNESCAPED_SLASHES); +} else { + print "Unknown output format."; +} |