feat: heartbeat monitors pinged by cron jobs and scripts
A heartbeat monitor has a secret ping URL instead of a target and regions. Jobs call it with GET, HEAD or POST after each run, or /fail with an optional message. When no ping arrives within the interval plus a grace period, a failure is recorded and evaluated like a checker result, so confirmations, maintenance and notifications apply. One API replica at a time checks deadlines. The URL is shown only to members who may edit the monitor, since it can report the job healthy. Closes #27 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
04eff67e56
commit
5a76702dba
14 files changed
+1241
-587
No files matched your search
@@ -179,6 +179,17 @@
|
||||
fs.hidden = !active;
|
||||
fs.disabled = !active;
|
||||
}
|
||||
// [data-hide-for] holds fields a type does without, e.g. heartbeats
|
||||
// have neither target nor regions.
|
||||
for (const el of sel.form.querySelectorAll("[data-hide-for]")) {
|
||||
const hide = el.dataset.hideFor.split(" ").includes(sel.value);
|
||||
el.hidden = hide;
|
||||
if (el.tagName === "FIELDSET") el.disabled = hide;
|
||||
for (const input of el.querySelectorAll("input[required], input[data-required]")) {
|
||||
input.required = !hide;
|
||||
input.dataset.required = "";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("change", async (ev) => {
|
||||
|
||||
@@ -246,6 +246,8 @@ type MonitorDetailView struct {
|
||||
CanWrite bool
|
||||
// Maintenance lists current and upcoming maintenance.
|
||||
Maintenance []MaintenanceItem
|
||||
// PingURL is set for heartbeat monitors the viewer may change.
|
||||
PingURL string
|
||||
}
|
||||
|
||||
// MaintenanceItem is one occurrence of planned maintenance.
|
||||
@@ -265,7 +267,13 @@ templ MonitorDetail(p Page, me Me, v MonitorDetailView) {
|
||||
@statusDot(v.Row.Status)
|
||||
<span>{ v.Row.Name }</span>
|
||||
</h1>
|
||||
<p class="mt-1 font-mono text-xs text-muted">{ v.Row.Type } · { v.Row.Target } · { v.Interval }</p>
|
||||
<p class="mt-1 font-mono text-xs text-muted">
|
||||
{ i18n.T(ctx, "monitors.type_"+v.Row.Type) }
|
||||
if v.Row.Target != "" {
|
||||
{ " · " + v.Row.Target }
|
||||
}
|
||||
{ " · " + v.Interval }
|
||||
</p>
|
||||
</div>
|
||||
if v.CanWrite {
|
||||
<a href={ templ.SafeURL("/monitors/" + v.Row.ID + "/edit") } class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "sso.action.edit") }</a>
|
||||
@@ -306,6 +314,9 @@ templ MonitorDetail(p Page, me Me, v MonitorDetailView) {
|
||||
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "monitors.by_region_hint") }</p>
|
||||
</section>
|
||||
}
|
||||
if v.PingURL != "" {
|
||||
@pingSection(v.PingURL)
|
||||
}
|
||||
if len(v.Maintenance) > 0 {
|
||||
<section class="mb-10">
|
||||
@sectionHeading("maintenance.title")
|
||||
@@ -447,6 +458,7 @@ type MonitorForm struct {
|
||||
DNSExpect string
|
||||
TLSMinDays int
|
||||
TLSServerName string
|
||||
GraceSeconds int
|
||||
}
|
||||
|
||||
templ typeFields(typ, current string) {
|
||||
@@ -504,13 +516,19 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
|
||||
<label class="mb-4 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.type") }</span>
|
||||
<select name="type" data-type-select class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
|
||||
for _, t := range []string{"http", "tcp", "tls", "dns", "icmp"} {
|
||||
for _, t := range []string{"http", "tcp", "tls", "dns", "icmp", "heartbeat"} {
|
||||
<option value={ t } selected?={ t == f.Type }>{ i18n.T(ctx, "monitors.type_"+t) }</option>
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
@valueField(i18n.T(ctx, "monitors.target"), "target", f.Target, "https://example.com", true)
|
||||
<p class="-mt-3 mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.target_hint") }</p>
|
||||
<div data-hide-for="heartbeat" hidden?={ f.Type == "heartbeat" }>
|
||||
@valueField(i18n.T(ctx, "monitors.target"), "target", f.Target, "https://example.com", f.Type != "heartbeat")
|
||||
<p class="-mt-3 mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.target_hint") }</p>
|
||||
</div>
|
||||
@typeFields("heartbeat", f.Type) {
|
||||
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.heartbeat_hint") }</p>
|
||||
@numberField(i18n.T(ctx, "monitors.grace"), "config.grace_seconds", f.GraceSeconds, 0, 86400, i18n.T(ctx, "monitors.grace_hint"))
|
||||
}
|
||||
@typeFields("http", f.Type) {
|
||||
<label class="mb-4 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.method") }</span>
|
||||
@@ -547,9 +565,11 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
|
||||
</div>
|
||||
<div>
|
||||
@numberField(i18n.T(ctx, "monitors.interval"), "interval_seconds", f.IntervalSeconds, f.MinInterval, 86400, i18n.T(ctx, "monitors.interval_hint", "Min", f.MinInterval))
|
||||
@numberField(i18n.T(ctx, "monitors.timeout"), "timeout_ms", f.TimeoutMS, 100, 60000, "")
|
||||
<div data-hide-for="heartbeat" hidden?={ f.Type == "heartbeat" }>
|
||||
@numberField(i18n.T(ctx, "monitors.timeout"), "timeout_ms", f.TimeoutMS, 100, 60000, "")
|
||||
</div>
|
||||
@numberField(i18n.T(ctx, "monitors.confirmations"), "confirmations", f.Confirmations, 1, 10, i18n.T(ctx, "monitors.confirmations_hint"))
|
||||
<fieldset class="mb-4">
|
||||
<fieldset class="mb-4" data-hide-for="heartbeat" hidden?={ f.Type == "heartbeat" } disabled?={ f.Type == "heartbeat" }>
|
||||
<legend class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.regions") }</legend>
|
||||
<p class="mb-2 text-xs text-muted">{ i18n.T(ctx, "monitors.regions_hint") }</p>
|
||||
for _, r := range f.Regions {
|
||||
@@ -753,3 +773,12 @@ func partialTitle(ctx context.Context, partial bool) string {
|
||||
}
|
||||
return i18n.T(ctx, "monitors.range_not_enough")
|
||||
}
|
||||
|
||||
templ pingSection(url string) {
|
||||
<section class="mb-10">
|
||||
@sectionHeading("monitors.ping_url")
|
||||
<p class="mb-3 max-w-2xl text-sm text-muted">{ i18n.T(ctx, "monitors.ping_intro") }</p>
|
||||
<pre class="overflow-x-auto border border-rule px-3 py-2 font-mono text-xs leading-relaxed">{ "curl -fsS -m 10 --retry 3 " + url + "\n" }{ "curl -fsS -m 10 --retry 3 --data-raw \"$output\" " + url + "/fail" }</pre>
|
||||
<p class="mt-2 max-w-2xl text-xs text-muted">{ i18n.T(ctx, "monitors.ping_secret") }</p>
|
||||
</section>
|
||||
}
|
||||
+744
-565
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user