-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
129 lines (118 loc) · 3.45 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2019 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package multiwatcher
import (
"github.com/prometheus/client_golang/prometheus"
)
const metricsNamespace = "juju_multiwatcher"
// Collector is a prometheus.Collector that collects metrics about
// multiwatcher worker.
type Collector struct {
worker *Worker
watcherCount prometheus.Gauge
restartCount prometheus.Gauge
storeSize prometheus.Gauge
queueSize prometheus.Gauge
queueAge prometheus.Gauge
append prometheus.Summary
dupe prometheus.Counter
process prometheus.Summary
}
// NewMetricsCollector returns a new Collector.
func NewMetricsCollector(worker *Worker) *Collector {
return &Collector{
worker: worker,
watcherCount: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "watcher_count",
Help: "The number of multiwatcher type watchers there are.",
},
),
restartCount: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "restart_count",
Help: "The number of times the all watcher has been restarted.",
},
),
storeSize: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "store_size",
Help: "The number of entities in the store.",
},
),
queueSize: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "queue_size",
Help: "The number of entries in the queue to process.",
},
),
queueAge: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "queue_age",
Help: "The age in seconds of the oldest queue entry.",
},
),
append: prometheus.NewSummary(prometheus.SummaryOpts{
Namespace: metricsNamespace,
Name: "append",
Help: "Time to append a queue entry in ms.",
Objectives: map[float64]float64{
0.5: 0.05,
0.9: 0.01,
0.99: 0.001,
},
}),
dupe: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: metricsNamespace,
Name: "dupe",
Help: "Count of duplicate watcher notifications already in queue.",
}),
process: prometheus.NewSummary(prometheus.SummaryOpts{
Namespace: metricsNamespace,
Name: "process",
Help: "Time to process a queue entry in ms.",
Objectives: map[float64]float64{
0.5: 0.05,
0.9: 0.01,
0.99: 0.001,
},
}),
}
}
// Describe is part of the prometheus.Collector interface.
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
c.watcherCount.Describe(ch)
c.restartCount.Describe(ch)
c.storeSize.Describe(ch)
c.queueSize.Describe(ch)
c.queueAge.Describe(ch)
c.append.Describe(ch)
c.dupe.Describe(ch)
c.process.Describe(ch)
}
// Collect is part of the prometheus.Collector interface.
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
// The report deals with the synchronization requirements.
report := c.worker.Report()
floatValue := func(key string) float64 {
return float64(report[key].(int))
}
c.watcherCount.Set(floatValue(reportWatcherKey))
c.restartCount.Set(floatValue(reportRestartKey))
c.storeSize.Set(floatValue(reportStoreKey))
c.queueSize.Set(floatValue(reportQueueSizeKey))
c.queueAge.Set(report[reportQueueAgeKey].(float64))
c.watcherCount.Collect(ch)
c.restartCount.Collect(ch)
c.storeSize.Collect(ch)
c.queueSize.Collect(ch)
c.queueAge.Collect(ch)
c.append.Collect(ch)
c.dupe.Collect(ch)
c.process.Collect(ch)
}