diff --git a/README.md b/README.md index 7851dcb1..bf4a8ae0 100644 --- a/README.md +++ b/README.md @@ -409,9 +409,14 @@ latency: - `sparrow_latency_duration_seconds` - Type: Gauge - - Description: Latency with status information of targets + - Description: Latency with status information of targets. This metric is DEPRECATED. Use `sparrow_latency_seconds`. - Labelled with `target` and `status` +- `sparrow_latency_seconds` + - Type: Gauge + - Description: Latency information of targets + - Labelled with `target` + - `sparrow_latency_count` - Type: Counter - Description: Count of latency checks done diff --git a/pkg/checks/latency/latency.go b/pkg/checks/latency/latency.go index af04096e..f128da24 100644 --- a/pkg/checks/latency/latency.go +++ b/pkg/checks/latency/latency.go @@ -71,9 +71,10 @@ type result struct { // metrics defines the metric collectors of the latency check type metrics struct { - duration *prometheus.GaugeVec - count *prometheus.CounterVec - histogram *prometheus.HistogramVec + duration *prometheus.GaugeVec + totalDuration *prometheus.GaugeVec + count *prometheus.CounterVec + histogram *prometheus.HistogramVec } // Run starts the latency check @@ -149,13 +150,22 @@ func newMetrics() metrics { duration: prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "sparrow_latency_duration_seconds", - Help: "Latency with status information of targets", + Help: "DEPRECATED Latency with status information of targets. Use sparrow_latency_seconds.", }, []string{ "target", "status", }, ), + totalDuration: prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "sparrow_latency_seconds", + Help: "Latency for each target", + }, + []string{ + "target", + }, + ), count: prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "sparrow_latency_count", @@ -181,6 +191,7 @@ func newMetrics() metrics { func (l *Latency) GetMetricCollectors() []prometheus.Collector { return []prometheus.Collector{ l.metrics.duration, + l.metrics.totalDuration, l.metrics.count, l.metrics.histogram, } @@ -231,7 +242,11 @@ func (l *Latency) check(ctx context.Context) map[string]result { lo.Debug("Successfully got latency status of target") mu.Lock() defer mu.Unlock() + + l.metrics.duration.DeletePartialMatch(prometheus.Labels{"target": target}) l.metrics.duration.WithLabelValues(target, strconv.Itoa(results[target].Code)).Set(results[target].Total) + l.metrics.totalDuration.WithLabelValues(target).Set(results[target].Total) + l.metrics.count.WithLabelValues(target).Inc() l.metrics.histogram.WithLabelValues(target).Observe(results[target].Total) l.metrics.count.WithLabelValues(target).Inc() }()