summaryrefslogtreecommitdiffstats
path: root/internal/metrics
diff options
context:
space:
mode:
authorbndw <ben@bdw.to>2026-02-15 08:22:03 -0800
committerbndw <ben@bdw.to>2026-02-15 08:22:03 -0800
commit71f7a444398275923246e1bc8283938a63a8267a (patch)
treee4e3a0721ae5c697f6592daacf28f79fd442dc0c /internal/metrics
parent77bb5b2469e6813bed3ffc0be5ed4933a437a969 (diff)
feat: add metrics for blocked events
Track and display blocked event counts with per-kind breakdown. - Add events_blocked_total counter with kind label - Add RecordBlockedEvent method to metrics - Display blocked count in dashboard Storage section - Call metric when rejecting non-core protocol kinds Allows monitoring spam patterns and verifying kind filter effectiveness. Raw metrics show breakdown by kind (e.g., kind=20001, kind=30311).
Diffstat (limited to 'internal/metrics')
-rw-r--r--internal/metrics/dashboard.html7
-rw-r--r--internal/metrics/metrics.go17
2 files changed, 24 insertions, 0 deletions
diff --git a/internal/metrics/dashboard.html b/internal/metrics/dashboard.html
index 9538ac6..1fa1ddf 100644
--- a/internal/metrics/dashboard.html
+++ b/internal/metrics/dashboard.html
@@ -199,6 +199,10 @@
199 <span class="metric-label">Deletions</span> 199 <span class="metric-label">Deletions</span>
200 <span class="metric-value" id="event_deletions">0</span> 200 <span class="metric-value" id="event_deletions">0</span>
201 </div> 201 </div>
202 <div class="metric">
203 <span class="metric-label">Blocked</span>
204 <span class="metric-value" id="events_blocked">0</span>
205 </div>
202 </div> 206 </div>
203 207
204 <div class="card"> 208 <div class="card">
@@ -317,6 +321,9 @@
317 document.getElementById('event_deletions').textContent = 321 document.getElementById('event_deletions').textContent =
318 sumMetric(metrics, `${prefix}_relay_event_deletions_total`); 322 sumMetric(metrics, `${prefix}_relay_event_deletions_total`);
319 323
324 document.getElementById('events_blocked').textContent =
325 sumMetric(metrics, `${prefix}_relay_events_blocked_total`);
326
320 const durationSum = sumMetric(metrics, `${prefix}_relay_request_duration_seconds_sum`); 327 const durationSum = sumMetric(metrics, `${prefix}_relay_request_duration_seconds_sum`);
321 const durationCount = sumMetric(metrics, `${prefix}_relay_request_duration_seconds_count`); 328 const durationCount = sumMetric(metrics, `${prefix}_relay_request_duration_seconds_count`);
322 const avgLatencyMs = durationCount > 0 ? (durationSum / durationCount * 1000) : 0; 329 const avgLatencyMs = durationCount > 0 ? (durationSum / durationCount * 1000) : 0;
diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go
index 74f9ffb..dea0748 100644
--- a/internal/metrics/metrics.go
+++ b/internal/metrics/metrics.go
@@ -2,6 +2,7 @@ package metrics
2 2
3import ( 3import (
4 _ "embed" 4 _ "embed"
5 "fmt"
5 "net/http" 6 "net/http"
6 7
7 "github.com/prometheus/client_golang/prometheus" 8 "github.com/prometheus/client_golang/prometheus"
@@ -30,6 +31,7 @@ type Metrics struct {
30 eventsTotal prometheus.Gauge 31 eventsTotal prometheus.Gauge
31 dbSizeBytes prometheus.Gauge 32 dbSizeBytes prometheus.Gauge
32 eventDeletionsTotal prometheus.Counter 33 eventDeletionsTotal prometheus.Counter
34 eventsBlockedTotal *prometheus.CounterVec
33 35
34 // Config 36 // Config
35 config *Config 37 config *Config
@@ -195,6 +197,16 @@ func New(config *Config) *Metrics {
195 }, 197 },
196 ) 198 )
197 199
200 m.eventsBlockedTotal = promauto.NewCounterVec(
201 prometheus.CounterOpts{
202 Namespace: config.Namespace,
203 Subsystem: config.Subsystem,
204 Name: "events_blocked_total",
205 Help: "Total events blocked by kind filter",
206 },
207 []string{"kind"},
208 )
209
198 return m 210 return m
199} 211}
200 212
@@ -274,6 +286,11 @@ func (m *Metrics) RecordEventDeletion() {
274 m.eventDeletionsTotal.Inc() 286 m.eventDeletionsTotal.Inc()
275} 287}
276 288
289// RecordBlockedEvent records an event blocked by kind filter.
290func (m *Metrics) RecordBlockedEvent(kind int32) {
291 m.eventsBlockedTotal.WithLabelValues(fmt.Sprintf("%d", kind)).Inc()
292}
293
277// RequestStatus represents the status of a request for metrics. 294// RequestStatus represents the status of a request for metrics.
278type RequestStatus string 295type RequestStatus string
279 296