Repository navigation
Expand file tree
/
Copy pathsummarize.py
More file actions
534 lines (449 loc) · 25.9 KB
/
Copy pathsummarize.py
File metadata and controls
534 lines (449 loc) · 25.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
#!/usr/bin/env python3
"""
summarize.py — build every report the monitor publishes, from the data directory.
Written into the data directory (the `monitor-data` branch in CI):
STATUS.md human-readable status page, rendered by GitHub on the branch
summary.json the same data, machine-readable; also feeds the dashboard
history.json per-resource daily uptime for the last 90 days (dashboard strips)
badges/*.json shields.io endpoints for the badges on the README
README.md explains the branch to anyone who lands on it
Definitions (see monitor/README.md):
uptime = (up + challenged) / checks over the checks actually recorded
coverage = checks / expected checks expected = one per interval since the resource
was first seen, capped at 100%; missed cron
runs lower coverage, never counted as up
windows = today (UTC), 7d, 30d, 90d, 365d calendar days ending today (UTC)
Websites and APIs are separate check targets (an API's id is "<resource id>--api"):
totals counts websites, totals_api counts APIs, and each row carries kind/parent/group so the
dashboard can show a resource's website and API side by side.
Monitoring is continuous: every resource is checked every interval, indefinitely. 99% is a
reference line only, used to sort the "below target" list. Repository activity comes from
activity.json, written by activity.py earlier in the same run.
Usage:
python summarize.py --data DIR [--config monitor/resources.yml]
"""
from __future__ import annotations
import argparse
import json
import math
import sys
from datetime import date, datetime, time, timedelta, timezone
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from common import (DEFAULT_CONFIG, INTERVAL_MINUTES, N_BUCKETS, # noqa: E402
STALE_AFTER_MINUTES, activity_path, daily_path, daterange, effective_url,
events_path, hist_percentile, iso, load_json, load_resources, log, parse_iso,
runs_within, state_path, utcnow, write_json)
WINDOWS = [("today", 1), ("7d", 7), ("30d", 30), ("90d", 90), ("365d", 365)]
HISTORY_DAYS = 90
TARGET = 0.99 # reference line; sorts the "below target" list only
RECENT_EVENTS = 25
REPO = "BioComputingUP/BioComp_resource_monitor"
REPO_URL = f"https://github.com/{REPO}"
DATA_BRANCH = "monitor-data"
DATA_BRANCH_URL = f"{REPO_URL}/blob/{DATA_BRANCH}"
DASHBOARD_URL = "https://biocomputingup.github.io/BioComp_resource_monitor/"
ACTIONS_URL = f"{REPO_URL}/actions/workflows/monitor-check.yml"
def load_days(data_dir: Path, start: date, end: date) -> dict[date, dict]:
days = {}
for d in daterange(start, end):
doc = load_json(daily_path(data_dir, d))
if doc:
days[d] = doc
return days
def expected_checks(day: date, now: datetime, first_seen: datetime | None,
interval: int = INTERVAL_MINUTES) -> int:
start = datetime.combine(day, time.min, tzinfo=timezone.utc)
end = min(start + timedelta(days=1), now)
if first_seen:
start = max(start, first_seen)
if end <= start:
return 0
return math.ceil((end - start).total_seconds() / (interval * 60))
def aggregate(days: dict[date, dict], rid: str, start: date, end: date, now: datetime,
first_seen: datetime | None, interval: int = INTERVAL_MINUTES) -> dict:
agg = {"checks": 0, "up": 0, "challenged": 0, "down": 0, "latency_sum_ms": 0,
"latency_hist": [0] * N_BUCKETS, "expected": 0}
for d in daterange(start, end):
# Measure each day against the interval in force that day, so a change of schedule
# does not distort the coverage recorded for earlier days.
agg["expected"] += expected_checks(d, now, first_seen,
days.get(d, {}).get("interval_minutes", interval))
counts = days.get(d, {}).get("resources", {}).get(rid)
if not counts:
continue
for k in ("checks", "up", "challenged", "down", "latency_sum_ms"):
agg[k] += counts.get(k, 0)
for i, n in enumerate(counts.get("latency_hist", [])[:N_BUCKETS]):
agg["latency_hist"][i] += n
return agg
def rates(agg: dict) -> dict:
checks = agg["checks"]
uptime = (agg["up"] + agg["challenged"]) / checks if checks else None
expected = max(agg["expected"], 1 if checks else 0)
coverage = min(1.0, checks / expected) if expected else None
return {"uptime": uptime, "coverage": coverage, "checks": checks, "down": agg["down"],
"challenged": agg["challenged"]}
def monitoring_health(state: dict, now: datetime) -> dict:
"""Is the tracker actually running? Reported at the top of every surface."""
last_run = state.get("updated")
since_min = None
if last_run:
since_min = round((now - parse_iso(last_run)).total_seconds() / 60)
stale = since_min is None or since_min > STALE_AFTER_MINUTES
recent_runs = state.get("recent_runs", [])
return {
"last_run": last_run,
"minutes_since_last_run": since_min,
"runs_total": state.get("runs_total", 0),
"runs_last_24h": runs_within(recent_runs, now, 24),
"expected_runs_24h": 1440 // INTERVAL_MINUTES,
"recent_runs": recent_runs,
"interval_minutes": INTERVAL_MINUTES,
"stale_after_minutes": STALE_AFTER_MINUTES,
"stale": stale,
"status": "STALE" if stale else "ACTIVE",
"workflow_url": ACTIONS_URL,
}
def build_summary(resources: list[dict], data_dir: Path, now: datetime) -> dict:
today = now.date()
state = load_json(state_path(data_dir)) or {"resources": {}, "runs_total": 0}
days = load_days(data_dir, today - timedelta(days=365), today)
rows = []
for res in resources:
rid = res["id"]
st = state["resources"].get(rid, {})
first_seen = parse_iso(st["first_seen"]) if st.get("first_seen") else None
windows = {}
for name, n in WINDOWS:
windows[name] = rates(aggregate(days, rid, today - timedelta(days=n - 1), today, now, first_seen))
lat = aggregate(days, rid, today - timedelta(days=29), today, now, first_seen)
ok = lat["up"] + lat["challenged"]
rows.append({
"id": rid, "name": res.get("name", rid), "url": effective_url(res),
"repo": res.get("repo"), "kind": res.get("kind", "web"), "parent": res.get("parent"),
"group": res.get("group"),
"state": st.get("state", "unknown"), "since": st.get("since"),
"reason": st.get("reason"), "code": st.get("code"), "error": st.get("error"),
"first_seen": st.get("first_seen"),
"last_checked": st.get("last_checked"), "final_url": st.get("final_url"),
"url_review": bool(st.get("url_review")), "tls_warning": st.get("tls_warning"),
"windows": windows,
"latency_30d": {"p50": hist_percentile(lat["latency_hist"], 0.5),
"p95": hist_percentile(lat["latency_hist"], 0.95),
"mean_ms": round(lat["latency_sum_ms"] / ok) if ok else None},
})
web = [r for r in rows if r["kind"] != "api"]
api = [r for r in rows if r["kind"] == "api"]
totals = {s: sum(1 for r in web if r["state"] == s) for s in ("up", "challenged", "down", "unknown")}
totals["url_review"] = sum(1 for r in rows if r["url_review"])
totals["resources"] = len(web)
totals_api = {s: sum(1 for r in api if r["state"] == s) for s in ("up", "down", "unknown")}
totals_api["bad_payload"] = sum(1 for r in api if r["state"] == "down"
and (r["reason"] or "").startswith("bad_payload"))
totals_api["apis"] = len(api)
return {"generated": iso(now), "interval_minutes": INTERVAL_MINUTES,
"monitoring": monitoring_health(state, now),
"runs_total": state.get("runs_total", 0), "last_run": state.get("updated"),
"resource_count": len(web), "api_count": len(api), "target": TARGET,
"dashboard_url": DASHBOARD_URL, "totals": totals, "totals_api": totals_api,
"resources": rows,
"activity": build_activity(resources, data_dir)}
def build_activity(resources: list[dict], data_dir: Path) -> dict:
"""Per resource id, the snapshot activity.py wrote this run (in resources.yml order)."""
doc = load_json(activity_path(data_dir)) or {}
repos = doc.get("repos", {})
ordered = {r["id"]: {"name": r.get("name", r["id"]), **repos[r["id"]]}
for r in resources if r["id"] in repos}
return {"generated": doc.get("generated"), "repos": ordered}
def build_history(resources: list[dict], data_dir: Path, now: datetime) -> dict:
"""Per-resource daily uptime for the last HISTORY_DAYS, for the dashboard's bar strips.
uptime[i] is a percentage 0-100 (rounded, one decimal) or null when no check was recorded
that day. checks[i] is the number of checks behind it, so the dashboard can show
"no data" and "one flaky check" differently.
"""
today = now.date()
start = today - timedelta(days=HISTORY_DAYS - 1)
days = load_days(data_dir, start, today)
out = {}
for res in resources:
rid = res["id"]
up_pct, checks = [], []
for d in daterange(start, today):
c = days.get(d, {}).get("resources", {}).get(rid)
n = (c or {}).get("checks", 0)
checks.append(n)
up_pct.append(round((c["up"] + c["challenged"]) / n * 100, 1) if n else None)
out[rid] = {"uptime": up_pct, "checks": checks}
return {"generated": iso(now), "days": HISTORY_DAYS,
"start": start.isoformat(), "end": today.isoformat(), "resources": out}
def read_recent_events(data_dir: Path, limit: int = RECENT_EVENTS) -> list[dict]:
path = events_path(data_dir)
if not path.exists():
return []
lines = path.read_text(encoding="utf-8").splitlines()[-limit * 4:]
events = []
for line in lines:
try:
events.append(json.loads(line))
except json.JSONDecodeError:
continue
return events[-limit:][::-1]
# --- badges (shields.io endpoint schema) -------------------------------------
def build_badges(summary: dict) -> dict[str, dict]:
t, ta, m = summary["totals"], summary["totals_api"], summary["monitoring"]
n, n_api = summary["resource_count"], summary["api_count"]
down = t["down"] + ta["down"]
every = ("hourly" if m["interval_minutes"] == 60
else f"every {m['interval_minutes']} min" if m["interval_minutes"] < 60
else f"every {m['interval_minutes'] // 60}h")
def badge(label: str, message: str, color: str) -> dict:
return {"schemaVersion": 1, "label": label, "message": message, "color": color}
return {
"monitoring": badge("monitoring", "stale — check the workflow" if m["stale"] else f"active · {every}",
"red" if m["stale"] else "brightgreen"),
"resources": badge("resources monitored", str(n), "blue"),
"up": badge("responding", f"{t['up'] + t['challenged']}/{n}",
"brightgreen" if t["up"] + t["challenged"] >= n * 0.9 else "yellow"),
"api": badge("APIs OK", f"{ta['up']}/{n_api}",
"lightgrey" if not n_api else "brightgreen" if ta["up"] == n_api else "red"),
"down": badge("down", str(down), "brightgreen" if not down else "red"),
"url-review": badge("url review", str(t["url_review"]),
"brightgreen" if not t["url_review"] else "orange"),
"last-check": badge("last check", (m["last_run"] or "never").replace("T", " ").replace("Z", " UTC"),
"brightgreen" if not m["stale"] else "red"),
"runs-24h": badge("runs in last 24h", f"{m['runs_last_24h']}/{m['expected_runs_24h']}",
{"good": "brightgreen", "low": "yellow", "poor": "red"}[cadence(m)]),
"activity": activity_badge(summary["activity"]["repos"]),
}
def cadence(m: dict) -> str:
"""How well runs are being delivered: good (≥75% of target), low (≥33%) or poor."""
share = m["runs_last_24h"] / max(m["expected_runs_24h"], 1)
return "good" if share >= 0.75 else "low" if share >= 0.33 else "poor"
def activity_badge(repos: dict) -> dict:
n = len(repos)
pushed = sum(1 for s in repos.values() if s.get("freshness") in ("active", "recent"))
return {"schemaVersion": 1, "label": "repos pushed ≤30d", "message": f"{pushed}/{n}",
"color": "brightgreen" if n and pushed == n else "yellow" if pushed else "lightgrey"}
# --- STATUS.md ---------------------------------------------------------------
def pct(x: float | None) -> str:
return "—" if x is None else f"{x * 100:.2f}%"
def cell(text) -> str:
return str(text if text not in (None, "") else "—").replace("|", "\\|").replace("\n", " ")
def link(row: dict) -> str:
return f"[{cell(row['name'])}]({row['url']})"
def ago(minutes: int | None) -> str:
if minutes is None:
return "never"
if minutes < 60:
return f"{minutes} min ago"
if minutes < 60 * 48:
return f"{minutes // 60} h ago"
return f"{minutes // 1440} days ago"
STATE_ICON = {"up": "🟢 up", "challenged": "🟡 challenged", "down": "🔴 down", "unknown": "⚪ unknown"}
FRESHNESS_ICON = {"active": "🟢 active (<7 d)", "recent": "🟡 recent (<30 d)",
"quiet": "🔴 quiet (≥30 d)", "unknown": "⚪ unknown"}
BADGE_BASE = (f"https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/"
f"{REPO}/{DATA_BRANCH}/badges")
def minutes_since(ts: str | None, now: datetime) -> int | None:
return round((now - parse_iso(ts)).total_seconds() / 60) if ts else None
def render_activity(summary: dict) -> list[str]:
repos = summary["activity"]["repos"]
now = parse_iso(summary["generated"])
out = ["## Repository activity", "",
"`Last push` is the latest push to **any** branch; `Head commit` is the tip of the "
"default branch. The full timeline is in "
f"[activity_history.jsonl]({DATA_BRANCH_URL}/activity_history.jsonl).", ""]
if not repos:
return out + ["No repository activity recorded yet.", ""]
out += ["| Resource | Repository | Last push | Activity | Head commit |", "|---|---|---|---|---|"]
for rid, s in repos.items():
c = s.get("last_commit") or {}
sha = (c.get("sha") or "")[:7]
commit = (f"[`{sha}`]({c['url']}) {cell(c.get('message'))} — {cell(c.get('author'))}, "
f"{cell((c.get('date') or '')[:10])}" if sha and c.get("url") else "—")
repo_link = f"[{s['repo']}]({s.get('html_url') or 'https://github.com/' + s['repo']})"
if s.get("default_branch"):
repo_link += f" `{s['default_branch']}`"
err = ("" if not s.get("error") else " ⚠️ API error, showing last known" if s.get("pushed_at")
else f" ⚠️ {cell(s['error'])}")
out.append(f"| {cell(s.get('name', rid))} | {repo_link} | "
f"{cell(s.get('pushed_at'))} ({ago(minutes_since(s.get('pushed_at'), now))}) | "
f"{FRESHNESS_ICON.get(s.get('freshness'), '⚪ unknown')}{err} | {commit} |")
return out + [""]
def render_status(summary: dict, events: list[dict]) -> str:
rows = summary["resources"]
t, ta, m = summary["totals"], summary["totals_api"], summary["monitoring"]
every = (f"{m['interval_minutes']} minutes" if m["interval_minutes"] < 60
else f"hour" if m["interval_minutes"] == 60 else f"{m['interval_minutes'] // 60} hours")
out = [
"# BioComp resource monitor status",
"",
f"[]({ACTIONS_URL}) "
f"[](#all-resources) "
f"[](#all-resources) "
f"[](#needs-attention) "
f"[]({ACTIONS_URL}) "
f"[](#repository-activity)",
"",
f"## {'🔴 Monitoring is STALE' if m['stale'] else '🟢 Monitoring is ACTIVE'}",
"",
f"| | |", "|---|---|",
f"| **Monitored** | {summary['resource_count']} websites and {summary['api_count']} APIs — "
f"every one, every {every}, continuously |",
f"| **Last check** | {m['last_run'] or '—'} ({ago(m['minutes_since_last_run'])}) |",
f"| **Runs in the last 24 h** | {m['runs_last_24h']} of a target {m['expected_runs_24h']} |",
f"| **Checks recorded** | {m['runs_total']} runs since monitoring began |",
f"| **Runs on** | [GitHub Actions → monitor-check]({ACTIONS_URL}) |",
f"| **Visual dashboard** | {DASHBOARD_URL} |",
"",
]
if m["stale"]:
out += [f"> The last check was {ago(m['minutes_since_last_run'])}, more than "
f"{m['stale_after_minutes'] // 60} hours ago. Both the external trigger and the GitHub "
f"schedule have probably stopped: check the cron-job.org job and its token, and "
f"re-enable the workflow at [Actions → monitor-check]({ACTIONS_URL}) (GitHub disables "
f"schedules after 60 days of no repository activity).", ""]
out += [
f"### Right now",
"",
f"🟢 up **{t['up']}** · 🟡 challenged **{t['challenged']}** · 🔴 down **{t['down']}** · "
f"⚪ never checked **{t['unknown']}** · 🔗 check URL to review **{t['url_review']}**",
"",
f"**APIs:** 🟢 OK **{ta['up']}** of {ta['apis']} · 🔴 down **{ta['down']}**"
f" (of which 🟠 responding with the wrong payload **{ta['bad_payload']}**)",
"",
"An API counts as up only when it answers 2xx with JSON that matches its `api.expect` in "
"resources.yml; a `bad_payload:*` reason means it answered, but with the wrong content. "
"Uptime = (up + challenged) ÷ recorded checks. Coverage = recorded ÷ expected checks. "
f"{pct(summary['target'])} is a reference line only; it sorts the list below. "
f"Full definitions: [monitor/README.md]({REPO_URL}/blob/main/monitor/README.md).",
"",
"---",
"",
]
out += render_activity(summary)
out += ["---", ""]
down = sorted((r for r in rows if r["state"] == "down"), key=lambda r: r["since"] or "")
out += ["## Needs attention", "", "### 🔴 Currently down", ""]
if down:
out += [f"**{len(down)}** of {len(rows)} websites and APIs are down.", "",
"| Resource | Since (UTC) | Reason | 30d uptime |", "|---|---|---|---|"]
out += [f"| {link(r)} | {cell(r['since'])} | `{cell(r['reason'])}`"
f"{' 🔗' if r['url_review'] else ''} | {pct(r['windows']['30d']['uptime'])} |"
for r in down]
out += ["", "🔗 = the check URL returns 404/410; see below."]
else:
out.append("None — every monitored website and API is up.")
out.append("")
review = [r for r in rows if r["url_review"]]
out += ["### 🔗 Check URL needs review", ""]
if review:
out += [f"**{len(review)}** return 404/410, so the resource has moved or been retired. "
"They are counted as "
"down until the URL is corrected: set `check.url` for the resource in "
f"[monitor/resources.yml]({REPO_URL}/blob/main/monitor/resources.yml), or "
"`enabled: false` if it is genuinely gone.", "",
"| Resource | Check URL | Code |", "|---|---|---|"]
out += [f"| {cell(r['name'])} | {r['url']} | `{cell(r['reason'])}` |"
for r in review]
else:
out.append("None.")
out.append("")
below = sorted((r for r in rows if r["windows"]["30d"]["uptime"] is not None
and r["windows"]["30d"]["uptime"] < summary["target"]),
key=lambda r: r["windows"]["30d"]["uptime"])
out += [f"### 📉 Below {pct(summary['target'])} over the last 30 days", ""]
if below:
out += [f"**{len(below)}** resources, worst first.", "",
"| Resource | 30d uptime | 30d coverage | Down checks |", "|---|---|---|---|"]
out += [f"| {link(r)} | {pct(r['windows']['30d']['uptime'])} | "
f"{pct(r['windows']['30d']['coverage'])} | {r['windows']['30d']['down']} |" for r in below]
else:
out.append("None.")
out += ["", "---", ""]
out += ["## All resources", "",
f"All {summary['resource_count']} websites and {summary['api_count']} APIs, sorted by name. "
f"Sortable and searchable on the [dashboard]({DASHBOARD_URL}).", "",
"| Resource | State | Today | 7d | 30d | 90d | 365d | Coverage 30d | p95 30d |",
"|---|---|---|---|---|---|---|---|---|"]
for r in sorted(rows, key=lambda r: r["name"].lower()):
w = r["windows"]
tls = " ⚠️ TLS" if r.get("tls_warning") else ""
out.append(f"| {link(r)} | {STATE_ICON.get(r['state'], r['state'])}{tls} | "
f"{pct(w['today']['uptime'])} | {pct(w['7d']['uptime'])} | {pct(w['30d']['uptime'])} | "
f"{pct(w['90d']['uptime'])} | {pct(w['365d']['uptime'])} | {pct(w['30d']['coverage'])} | "
f"{cell(r['latency_30d']['p95'])} |")
out += ["", "---", ""]
by_id = {r["id"]: r for r in rows}
out += ["## Recent state changes", "",
"The newest entries from `events.jsonl`, the full audit trail of every state change.", ""]
if events:
out += ["| When (UTC) | Resource | Change | Detail |", "|---|---|---|---|"]
for ev in events:
name = by_id.get(ev["id"], {}).get("name", ev["id"])
change = (f"{STATE_ICON.get(ev.get('from'), ev.get('from') or 'new')} → "
f"{STATE_ICON.get(ev.get('to'), ev.get('to'))}" if ev.get("event") == "state_change"
else f"reason changed: `{cell(ev.get('from'))}` → `{cell(ev.get('to'))}`")
out.append(f"| {cell(ev['ts'])} | {cell(name)} | {change} | `{cell(ev.get('reason'))}` |")
else:
out.append("None recorded yet.")
out += ["", "---", "",
f"Generated by [monitor/scripts/summarize.py]({REPO_URL}/blob/main/monitor/scripts/summarize.py) "
f"at **{summary['generated']}**, and rewritten after every check. "
f"Machine-readable: [summary.json]({DATA_BRANCH_URL}/summary.json).", ""]
return "\n".join(out)
# --- the data branch's own README --------------------------------------------
def render_branch_readme(summary: dict) -> str:
m = summary["monitoring"]
return f"""# {DATA_BRANCH} — where the BioComp resource monitor results are deposited
**You are on the data branch.** It holds only the output of the BioComp resource monitor. The code that
produces it is in [`monitor/` on `main`]({REPO_URL}/tree/main/monitor).
## 👉 [STATUS.md](STATUS.md) — uptime of {summary['resource_count']} websites and {summary['api_count']} APIs, and repository activity
Or the visual dashboard: **{DASHBOARD_URL}**
Monitoring is **{m['status']}** · last check {m['last_run'] or '—'} · {m['runs_last_24h']} runs in the
last 24 h · {m['runs_total']} runs recorded.
## What is in here
| File | What it is |
|---|---|
| [`STATUS.md`](STATUS.md) | The status page. Rendered by GitHub, rewritten after every check. |
| [`index.html`](index.html) | The dashboard, served at {DASHBOARD_URL} |
| [`summary.json`](summary.json) | Everything in STATUS.md, machine-readable. |
| [`history.json`](history.json) | Per-resource daily uptime for the last 90 days. |
| [`state.json`](state.json) | Current state of each resource, plus the timestamps of recent runs. |
| [`events.jsonl`](events.jsonl) | Append-only audit trail of every uptime state change. |
| [`activity.json`](activity.json) | Latest push and head commit of each resource's GitHub repository. |
| [`activity_history.jsonl`](activity_history.jsonl) | Append-only: one line each time a repository's last push or head commit changes. |
| `daily/YYYY/YYYY-MM-DD.json` | Daily counters and latency histogram per resource. |
| `badges/*.json` | shields.io endpoints for the badges on the main README. |
Raw per-check rows are not kept, so this branch stays small (a few MB a year for this number of resources).
## Do not commit here by hand
Every commit comes from the [`monitor-check`]({ACTIONS_URL}) workflow, squashed to one commit per
UTC day and force-pushed. Hand edits will be overwritten. `main` is never touched by the monitor.
*Generated by `monitor/scripts/summarize.py` at {summary['generated']}.*
"""
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--config", type=Path, default=DEFAULT_CONFIG)
ap.add_argument("--data", type=Path, required=True)
args = ap.parse_args()
resources = load_resources(args.config)
now = utcnow()
summary = build_summary(resources, args.data, now)
write_json(args.data / "summary.json", summary)
write_json(args.data / "history.json", build_history(resources, args.data, now))
for name, doc in build_badges(summary).items():
write_json(args.data / "badges" / f"{name}.json", doc, indent=None)
(args.data / "STATUS.md").write_text(render_status(summary, read_recent_events(args.data)),
encoding="utf-8")
(args.data / "README.md").write_text(render_branch_readme(summary), encoding="utf-8")
t, m = summary["totals"], summary["monitoring"]
ta = summary["totals_api"]
log(f"summary: {summary['resource_count']} websites, up={t['up']} challenged={t['challenged']} "
f"down={t['down']} unknown={t['unknown']} url_review={t['url_review']}; "
f"{summary['api_count']} APIs, up={ta['up']} down={ta['down']} bad_payload={ta['bad_payload']}; "
f"monitoring={m['status']} runs_24h={m['runs_last_24h']} "
f"repos={len(summary['activity']['repos'])}")
return 0
if __name__ == "__main__":
sys.exit(main())