From ae6c01bd674f14a6e1e474989279b1d3bc203e28 Mon Sep 17 00:00:00 2001 From: Helmi Rifai Date: Sat, 16 Mar 2019 16:19:05 +0200 Subject: [PATCH] Adds QueueUsage to prometheus metrics (same as /api/stat/app) (#401) Exposes gorush_queue_usage metric to be used in prometheus so monitor internal queues Useful to make sure we are coping well with traffic --- gorush/metrics.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gorush/metrics.go b/gorush/metrics.go index 0137890..74e0922 100644 --- a/gorush/metrics.go +++ b/gorush/metrics.go @@ -14,6 +14,7 @@ type Metrics struct { IosError *prometheus.Desc AndroidSuccess *prometheus.Desc AndroidError *prometheus.Desc + QueueUsage *prometheus.Desc } // NewMetrics returns a new Metrics with all prometheus.Desc initialized @@ -45,6 +46,11 @@ func NewMetrics() Metrics { "Number of android fail count", nil, nil, ), + QueueUsage: prometheus.NewDesc( + namespace+"queue_usage", + "Length of internal queue", + nil, nil, + ), } } @@ -55,6 +61,7 @@ func (c Metrics) Describe(ch chan<- *prometheus.Desc) { ch <- c.IosError ch <- c.AndroidSuccess ch <- c.AndroidError + ch <- c.QueueUsage } // Collect returns the metrics with values @@ -84,4 +91,9 @@ func (c Metrics) Collect(ch chan<- prometheus.Metric) { prometheus.GaugeValue, float64(StatStorage.GetAndroidError()), ) + ch <- prometheus.MustNewConstMetric( + c.QueueUsage, + prometheus.GaugeValue, + float64(len(QueueNotification)), + ) }