Skip to content

Commit b4f85cf

Browse files
committed
wip
1 parent 8d180e0 commit b4f85cf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

pkg/metrics/metrics.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ type Metrics struct {
3434
JsonRpcRequestDuration *prometheus.HistogramVec
3535
// JsonRpcRequestSloSeconds exports constant SLO thresholds for JSON-RPC requests.
3636
JsonRpcRequestSloSeconds *prometheus.GaugeVec
37+
// EndpointAvailability tracks whether an endpoint is reachable (1.0 = available, 0.0 = unavailable).
38+
EndpointAvailability *prometheus.GaugeVec
39+
// EndpointErrors tracks endpoint connection errors by type.
40+
EndpointErrors *prometheus.CounterVec
3741

3842
// internal tracking to ensure we only record increasing DA heights
3943
latestHeaderDaHeight uint64
@@ -164,6 +168,22 @@ func NewWithRegistry(namespace string, registerer prometheus.Registerer) *Metric
164168
},
165169
[]string{"chain_id", "percentile"},
166170
),
171+
EndpointAvailability: factory.NewGaugeVec(
172+
prometheus.GaugeOpts{
173+
Namespace: namespace,
174+
Name: "endpoint_availability",
175+
Help: "endpoint availability status (1.0 = available, 0.0 = unavailable)",
176+
},
177+
[]string{"chain_id", "endpoint"},
178+
),
179+
EndpointErrors: factory.NewCounterVec(
180+
prometheus.CounterOpts{
181+
Namespace: namespace,
182+
Name: "endpoint_errors_total",
183+
Help: "total number of endpoint connection errors by type",
184+
},
185+
[]string{"chain_id", "endpoint", "error_type"},
186+
),
167187
ranges: make(map[string][]*blockRange),
168188
lastBlockArrivalTime: make(map[string]time.Time),
169189
}
@@ -431,3 +451,18 @@ func (m *Metrics) InitializeJsonRpcSloThresholds(chainID string) {
431451
m.JsonRpcRequestSloSeconds.WithLabelValues(chainID, "p95").Set(0.4)
432452
m.JsonRpcRequestSloSeconds.WithLabelValues(chainID, "p99").Set(0.5)
433453
}
454+
455+
// RecordEndpointAvailability records whether an endpoint is reachable
456+
// available should be true if endpoint is reachable, false otherwise
457+
func (m *Metrics) RecordEndpointAvailability(chainID, endpoint string, available bool) {
458+
value := 0.0
459+
if available {
460+
value = 1.0
461+
}
462+
m.EndpointAvailability.WithLabelValues(chainID, endpoint).Set(value)
463+
}
464+
465+
// RecordEndpointError records an endpoint connection error with its type
466+
func (m *Metrics) RecordEndpointError(chainID, endpoint, errorType string) {
467+
m.EndpointErrors.WithLabelValues(chainID, endpoint, errorType).Inc()
468+
}

0 commit comments

Comments
 (0)