-
Notifications
You must be signed in to change notification settings - Fork 26
/
collector.go
44 lines (36 loc) · 1.01 KB
/
collector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package proxy
import (
"fmt"
"github.com/enix/kube-image-keeper/internal/metrics"
"github.com/prometheus/client_golang/prometheus"
)
const subsystem = "proxy"
type Collector struct {
httpCall *prometheus.CounterVec
info prometheus.Collector
}
func NewCollector() *Collector {
return &Collector{
httpCall: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: metrics.Namespace,
Subsystem: subsystem,
Name: "http_requests_total",
Help: "How many HTTP calls have been handled",
},
[]string{"registry", "statusCode", "cacheHit"},
),
info: metrics.NewInfo(subsystem),
}
}
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
c.httpCall.Describe(ch)
c.info.Describe(ch)
}
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
c.httpCall.Collect(ch)
c.info.Collect(ch)
}
func (c *Collector) IncHTTPCall(registry string, statusCode int, cacheHit bool) {
c.httpCall.WithLabelValues(registry, fmt.Sprintf("%d", statusCode), fmt.Sprintf("%t", cacheHit)).Inc()
}