@@ -8,21 +8,25 @@ import (
8
8
"golift.io/cache"
9
9
)
10
10
11
+ // CacheList is a map of label to stats functions for each cache.
11
12
type CacheList map [string ]func () * cache.Stats
12
13
14
+ // CacheCollector is our input for creating metrics for our cache data.
13
15
type CacheCollector struct {
14
16
Stats CacheList
15
17
counter * prometheus.Desc
16
18
}
17
19
20
+ // Describe satisfies the Collector interface for prometheus.
18
21
func (c * CacheCollector ) Describe (ch chan <- * prometheus.Desc ) {
19
22
ch <- c .counter
20
23
}
21
24
25
+ // Collect satisfies the Collector interface for prometheus.
22
26
func (c * CacheCollector ) Collect (ch chan <- prometheus.Metric ) {
23
27
for label , stats := range c .Stats {
24
28
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" )
26
30
ch <- prometheus .MustNewConstMetric (c .counter , prometheus .CounterValue , float64 (cache .Gets ), label , "gets" )
27
31
ch <- prometheus .MustNewConstMetric (c .counter , prometheus .CounterValue , float64 (cache .Hits ), label , "hits" )
28
32
ch <- prometheus .MustNewConstMetric (c .counter , prometheus .CounterValue , float64 (cache .Misses ), label , "misses" )
@@ -36,15 +40,22 @@ func (c *CacheCollector) Collect(ch chan<- prometheus.Metric) {
36
40
}
37
41
}
38
42
43
+ // Metrics contains the exported prometheus metrics used by the application.
39
44
type Metrics struct {
40
45
QueryErrors * prometheus.CounterVec
41
46
QueryMissing * prometheus.CounterVec
42
47
QueryTime * prometheus.HistogramVec
43
48
ReqTime * prometheus.HistogramVec
44
- Cache * prometheus.CounterVec
45
49
Uptime prometheus.CounterFunc
46
50
}
47
51
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]
48
59
func GetMetrics (collector * CacheCollector ) * Metrics {
49
60
start := time .Now ()
50
61
collector .counter = prometheus .NewDesc ("authproxy_cache_counters" , "All cache counters" , []string {"cache" , "counter" }, nil )
0 commit comments