feat: Prometheus monitors in console and API

Closes #25

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 11:49:07 +01:00
1 parent 5e7db9c054
commit 94b519b421
8 files changed
+919 -580

No files matched your search

+38 -1
View File
@@ -466,6 +466,12 @@ type MonitorForm struct {
JSONExpect string
JSONVerify bool
Assertions []AssertionRow
PromQuery string
PromOp string
PromThreshold string
PromMode string
PromEmptyOK bool
PromVerify bool
}
// AssertionRow is one condition of a JSON check; unused rows are empty.
@@ -541,7 +547,7 @@ 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", "json", "tcp", "tls", "dns", "icmp", "heartbeat"} {
for _, t := range []string{"http", "json", "prometheus", "tcp", "tls", "dns", "icmp", "heartbeat"} {
<option value={ t } selected?={ t == f.Type }>{ i18n.T(ctx, "monitors.type_"+t) }</option>
}
</select>
@@ -572,6 +578,37 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
@checkbox(i18n.T(ctx, "monitors.verify_tls"), "config.verify_tls", f.VerifyTLS)
@headersField(f.Headers)
}
@typeFields("prometheus", f.Type) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.prom_hint") }</p>
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.prom_query") }</span>
<textarea name="config.query" rows="3" placeholder={ `up{job="api"}` } class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-xs outline-none focus:border-ink">{ f.PromQuery }</textarea>
</label>
<div class="mb-4 grid grid-cols-[6.5rem_1fr] gap-2">
<label>
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.assertion_op") }</span>
<select name="config.op" class="w-full border border-rule bg-transparent px-1 py-1.5 font-mono text-sm">
for _, op := range AssertionOps[:6] {
<option value={ op } selected?={ op == f.PromOp }>{ i18n.T(ctx, "monitors.op_"+opKey(op)) }</option>
}
</select>
</label>
<label>
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.prom_threshold") }</span>
<input name="config.threshold" data-number type="number" step="any" value={ f.PromThreshold } class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"/>
</label>
</div>
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.prom_mode") }</span>
<select name="config.mode" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
<option value="all" selected?={ f.PromMode != "any" }>{ i18n.T(ctx, "monitors.prom_mode_all") }</option>
<option value="any" selected?={ f.PromMode == "any" }>{ i18n.T(ctx, "monitors.prom_mode_any") }</option>
</select>
</label>
@checkbox(i18n.T(ctx, "monitors.prom_empty_ok"), "config.empty_ok", f.PromEmptyOK)
@checkbox(i18n.T(ctx, "monitors.verify_tls"), "config.verify_tls", f.PromVerify)
@headersField(f.Headers)
}
@typeFields("json", 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>