...
1 package k8s
2
3 import (
4 "fmt"
5
6 "github.com/prometheus/client_golang/prometheus"
7 "k8s.io/client-go/tools/cache"
8 )
9
10 type promGauges struct {
11 gauges []prometheus.GaugeFunc
12 }
13
14 func (p *promGauges) addInformerSize(kind string, labels prometheus.Labels, inf cache.SharedIndexInformer) {
15 p.gauges = append(p.gauges, prometheus.NewGaugeFunc(prometheus.GaugeOpts{
16 Name: fmt.Sprintf("%s_cache_size", kind),
17 Help: fmt.Sprintf("Number of items in the client-go %s cache", kind),
18 ConstLabels: labels,
19 }, func() float64 {
20 return float64(len(inf.GetStore().ListKeys()))
21 }))
22 }
23
24 func (p *promGauges) unregister() {
25 for _, gauge := range p.gauges {
26 prometheus.Unregister(gauge)
27 }
28 }
29
View as plain text