Skip to content

Commit fa0aa41

Browse files
committed
set cache size as gauge instead of counter
1 parent 33c0973 commit fa0aa41

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

docs/api_docs.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,26 @@ const docTemplateapi = `{
162162
}
163163
}
164164
},
165+
"/metrics": {
166+
"get": {
167+
"description": "Retreive internal application metrics.",
168+
"produces": [
169+
"application/json"
170+
],
171+
"tags": [
172+
"stats"
173+
],
174+
"summary": "Return auth proxy metrics in open metrics format",
175+
"responses": {
176+
"200": {
177+
"description": "Auth Proxy Prometheus metrics",
178+
"schema": {
179+
"type": "object"
180+
}
181+
}
182+
}
183+
}
184+
},
165185
"/reload": {
166186
"get": {
167187
"description": "Re-reads the config file and updates the no-auth/no-api-key-required paths.",

pkg/exp/metrics.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,25 @@ import (
88
"golift.io/cache"
99
)
1010

11+
// CacheList is a map of label to stats functions for each cache.
1112
type CacheList map[string]func() *cache.Stats
1213

14+
// CacheCollector is our input for creating metrics for our cache data.
1315
type CacheCollector struct {
1416
Stats CacheList
1517
counter *prometheus.Desc
1618
}
1719

20+
// Describe satisfies the Collector interface for prometheus.
1821
func (c *CacheCollector) Describe(ch chan<- *prometheus.Desc) {
1922
ch <- c.counter
2023
}
2124

25+
// Collect satisfies the Collector interface for prometheus.
2226
func (c *CacheCollector) Collect(ch chan<- prometheus.Metric) {
2327
for label, stats := range c.Stats {
2428
cache := stats()
25-
ch <- prometheus.MustNewConstMetric(c.counter, prometheus.CounterValue, float64(cache.Size), label, "size")
29+
ch <- prometheus.MustNewConstMetric(c.counter, prometheus.GaugeValue, float64(cache.Size), label, "size")
2630
ch <- prometheus.MustNewConstMetric(c.counter, prometheus.CounterValue, float64(cache.Gets), label, "gets")
2731
ch <- prometheus.MustNewConstMetric(c.counter, prometheus.CounterValue, float64(cache.Hits), label, "hits")
2832
ch <- prometheus.MustNewConstMetric(c.counter, prometheus.CounterValue, float64(cache.Misses), label, "misses")
@@ -36,15 +40,22 @@ func (c *CacheCollector) Collect(ch chan<- prometheus.Metric) {
3640
}
3741
}
3842

43+
// Metrics contains the exported prometheus metrics used by the application.
3944
type Metrics struct {
4045
QueryErrors *prometheus.CounterVec
4146
QueryMissing *prometheus.CounterVec
4247
QueryTime *prometheus.HistogramVec
4348
ReqTime *prometheus.HistogramVec
44-
Cache *prometheus.CounterVec
4549
Uptime prometheus.CounterFunc
4650
}
4751

52+
// GetMetrics sets up metrics on startup.
53+
// @Description Retreive internal application metrics.
54+
// @Summary Return auth proxy metrics in open metrics format
55+
// @Tags stats
56+
// @Produce json
57+
// @Success 200 {object} any "Auth Proxy Prometheus metrics"
58+
// @Router /metrics [get]
4859
func GetMetrics(collector *CacheCollector) *Metrics {
4960
start := time.Now()
5061
collector.counter = prometheus.NewDesc("authproxy_cache_counters", "All cache counters", []string{"cache", "counter"}, nil)

0 commit comments

Comments
 (0)