-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
58 lines (51 loc) · 1.17 KB
/
metrics.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type metricsProcessor struct {
em entriesManager
nbContainers *prometheus.GaugeVec
}
func newMetricsProcessor(em entriesManager) *metricsProcessor {
nbContainers := promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ghosts_nb_containers",
Help: "The total number of created containers",
},
[]string{
"category",
},
)
return &metricsProcessor{em, nbContainers}
}
func (h *metricsProcessor) init() error {
entries, err := h.em.get()
if err != nil {
return err
}
for _, entry := range entries {
h.nbContainers.WithLabelValues(entry.Category[0]).Inc()
}
return nil
}
func (h *metricsProcessor) startEvent(id string) error {
entries, err := h.em.get(id)
if err != nil {
return err
}
for _, entry := range entries {
h.nbContainers.WithLabelValues(entry.Category[0]).Inc()
}
return nil
}
func (h *metricsProcessor) dieEvent(id string) error {
entries, err := h.em.get(id)
if err != nil {
return err
}
for _, entry := range entries {
h.nbContainers.WithLabelValues(entry.Category[0]).Dec()
}
return nil
}