From e1504b8394f3aa5cad02b1bfe0f9721877c2682b Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Fri, 15 Jun 2018 13:24:07 +0200 Subject: mirrors/status.php new, only understands ?json, currently --- mirrors/status.php | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 mirrors/status.php 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 @@ +`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."; +} -- cgit v1.2.3-70-g09d2