Skip to content

Commit

Permalink
Adds QueueUsage to prometheus metrics (same as /api/stat/app) (#401)
Browse files Browse the repository at this point in the history
Exposes gorush_queue_usage metric to be used in prometheus so monitor internal queues

Useful to make sure we are coping well with traffic
  • Loading branch information
HelmiRifai authored and appleboy committed Mar 16, 2019
1 parent 758d4d6 commit ae6c01b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gorush/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
),
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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)),
)
}

0 comments on commit ae6c01b

Please sign in to comment.