Show how each domain has behaved over a day, a week, a month and a year, not just now
This commit is contained in:
@@ -30,9 +30,10 @@
|
||||
// majority of the traffic it reports and bury whatever real use these hosts get.
|
||||
//
|
||||
// Bounded storage, decided up front.
|
||||
// Per domain: lifetime counters, the last 60 samples for the strip, 48 hourly buckets and
|
||||
// 30 daily ones. That is a fixed size — a per-minute probe kept as raw samples would be
|
||||
// fifty thousand rows a day and the file would be the problem instead of the answer.
|
||||
// Per domain: lifetime counters, the last 60 samples for the strip, 48 hourly buckets,
|
||||
// 30 daily ones and 12 monthly ones. That is a fixed size — a per-minute probe kept as raw
|
||||
// samples would be fifty thousand rows a day and the file would be the problem instead of
|
||||
// the answer. Each tier is what one view on the Proxies tab draws: 24h, 7d, 30d, 12 months.
|
||||
//
|
||||
// The domain list follows NPM, not a hand-kept list in conf.
|
||||
// A host added in the Proxies tab starts being probed without anyone remembering to add it
|
||||
@@ -65,6 +66,10 @@ const VV_UPTIME_UA = 'Varaverk-Uptime/1.0';
|
||||
const VV_SAMPLES_KEEP = 60; // one hour at a one-minute cadence
|
||||
const VV_HOURS_KEEP = 48;
|
||||
const VV_DAYS_KEEP = 30;
|
||||
// A year as twelve monthly buckets rather than 365 daily ones. The yearly view is a shape — which
|
||||
// months were bad — not a date lookup, and rolling the day buckets out to 365 would grow the file
|
||||
// twelvefold to answer the same question at a resolution nothing displays.
|
||||
const VV_MONTHS_KEEP = 12;
|
||||
const VV_EVENTS_KEEP = 20;
|
||||
|
||||
$dryRun = in_array('--dry-run', $argv, true);
|
||||
@@ -138,14 +143,15 @@ if ($status || $events) {
|
||||
strtoupper($e['to']), $e['detail'] ?? '');
|
||||
exit(0);
|
||||
}
|
||||
printf("%-34s %-6s %8s %8s %8s %s\n", 'domain', 'state', '1h', '24h', '30d', 'since');
|
||||
printf("%-34s %-6s %8s %8s %8s %8s %s\n", 'domain', 'state', '24h', '7d', '30d', '1y', 'since');
|
||||
foreach ($doms as $d => $r) {
|
||||
$h = vv_uptime_window($r['hours'] ?? [], 1);
|
||||
$h24 = vv_uptime_window($r['hours'] ?? [], 24);
|
||||
$d30 = vv_uptime_window($r['days'] ?? [], 30);
|
||||
printf("%-34s %-6s %8s %8s %8s %s\n", substr($d, 0, 34), $r['state'] ?? '-',
|
||||
$h === null ? '-' : $h . '%', $h24 === null ? '-' : $h24 . '%',
|
||||
$d30 === null ? '-' : $d30 . '%',
|
||||
$h24 = vv_uptime_window($r['hours'] ?? [], 24);
|
||||
$d7 = vv_uptime_window($r['days'] ?? [], 7);
|
||||
$d30 = vv_uptime_window($r['days'] ?? [], 30);
|
||||
$y1 = vv_uptime_window($r['months'] ?? [], 12);
|
||||
printf("%-34s %-6s %8s %8s %8s %8s %s\n", substr($d, 0, 34), $r['state'] ?? '-',
|
||||
$h24 === null ? '-' : $h24 . '%', $d7 === null ? '-' : $d7 . '%',
|
||||
$d30 === null ? '-' : $d30 . '%', $y1 === null ? '-' : $y1 . '%',
|
||||
!empty($r['last_change']) ? date('m-d H:i', $r['last_change']) : '-');
|
||||
}
|
||||
printf("\n%d domains, last pass %s\n", count($doms),
|
||||
@@ -233,6 +239,7 @@ try {
|
||||
$doms = $store['domains'] ?? [];
|
||||
$hourKey = date('YmdH', $now);
|
||||
$dayKey = date('Ymd', $now);
|
||||
$monKey = date('Ym', $now);
|
||||
|
||||
foreach ($handles as $d => $ch) {
|
||||
$errno = curl_errno($ch);
|
||||
@@ -249,7 +256,7 @@ try {
|
||||
|
||||
$r = $doms[$d] ?? ['checks' => 0, 'up' => 0, 'down' => 0, 'state' => null,
|
||||
'last_change' => null, 'samples' => [], 'hours' => [], 'days' => [],
|
||||
'events' => [], 'since' => $now];
|
||||
'months' => [], 'events' => [], 'since' => $now];
|
||||
$r['checks']++;
|
||||
$up ? $r['up']++ : $r['down']++;
|
||||
$r['last_code'] = $code;
|
||||
@@ -274,7 +281,9 @@ try {
|
||||
if (count($r['samples']) > VV_SAMPLES_KEEP)
|
||||
$r['samples'] = array_slice($r['samples'], -VV_SAMPLES_KEEP);
|
||||
|
||||
foreach ([['hours', $hourKey, VV_HOURS_KEEP], ['days', $dayKey, VV_DAYS_KEEP]] as [$k, $key, $keep]) {
|
||||
foreach ([['hours', $hourKey, VV_HOURS_KEEP],
|
||||
['days', $dayKey, VV_DAYS_KEEP],
|
||||
['months', $monKey, VV_MONTHS_KEEP]] as [$k, $key, $keep]) {
|
||||
$b = $r[$k][$key] ?? ['u' => 0, 't' => 0];
|
||||
$b['t']++;
|
||||
if ($up) $b['u']++;
|
||||
|
||||
Reference in New Issue
Block a user