diff options
| author | bndw <ben@bdw.to> | 2026-02-15 08:22:03 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-15 08:22:03 -0800 |
| commit | 71f7a444398275923246e1bc8283938a63a8267a (patch) | |
| tree | e4e3a0721ae5c697f6592daacf28f79fd442dc0c /internal/metrics/metrics.go | |
| parent | 77bb5b2469e6813bed3ffc0be5ed4933a437a969 (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/metrics.go')
| -rw-r--r-- | internal/metrics/metrics.go | 17 |
1 files changed, 17 insertions, 0 deletions
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 | ||
| 3 | import ( | 3 | import ( |
| 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. | ||
| 290 | func (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. |
| 278 | type RequestStatus string | 295 | type RequestStatus string |
| 279 | 296 | ||
