@@ -16,29 +16,29 @@ var (
16
16
Name : "mailbox_count" ,
17
17
})
18
18
19
- // activeSessions tracks the active session count for mailbox
19
+ // activeSessions tracks the active session count for mailbox.
20
20
activeSessions = prometheus .NewGauge (prometheus.GaugeOpts {
21
21
Namespace : "hashmail" ,
22
22
Name : "mailbox_active_sessions" ,
23
23
Help : "Number of active sessions" ,
24
24
})
25
25
26
- // standbySessions tracks the standby session count for mailbox
26
+ // standbySessions tracks the standby session count for mailbox.
27
27
standbySessions = prometheus .NewGauge (prometheus.GaugeOpts {
28
28
Namespace : "hashmail" ,
29
29
Name : "mailbox_standby_sessions" ,
30
30
Help : "Number of standby sessions" ,
31
31
})
32
32
33
- // inUseSessions tracks the in-use session count for mailbox
33
+ // inUseSessions tracks the in-use session count for mailbox.
34
34
inUseSessions = prometheus .NewGauge (prometheus.GaugeOpts {
35
35
Namespace : "hashmail" ,
36
36
Name : "mailbox_inuse_sessions" ,
37
37
Help : "Number of in-use sessions" ,
38
38
})
39
39
)
40
40
41
- // streamActivityTracker handles the calculation of session statistics
41
+ // streamActivityTracker handles the calculation of session statistics.
42
42
var streamActivityTracker = newStreamActivity ()
43
43
44
44
// PrometheusConfig is the set of configuration data that specifies if
@@ -56,7 +56,9 @@ type PrometheusConfig struct {
56
56
// StartPrometheusExporter registers all relevant metrics with the Prometheus
57
57
// library, then launches the HTTP server that Prometheus will hit to scrape
58
58
// our metrics.
59
- func StartPrometheusExporter (cfg * PrometheusConfig ) error {
59
+ func StartPrometheusExporter (cfg * PrometheusConfig ,
60
+ shutdown <- chan struct {}) error {
61
+
60
62
// If we're not active, then there's nothing more to do.
61
63
if ! cfg .Enabled {
62
64
return nil
@@ -68,16 +70,23 @@ func StartPrometheusExporter(cfg *PrometheusConfig) error {
68
70
prometheus .MustRegister (standbySessions )
69
71
prometheus .MustRegister (inUseSessions )
70
72
71
- // Periodically update session classification metrics from internal tracker
73
+ // Periodically update session classification metrics from internal tracker.
72
74
go func () {
73
75
ticker := time .NewTicker (10 * time .Second )
74
76
defer ticker .Stop ()
75
77
76
- for range ticker .C {
77
- active , standby , inuse := streamActivityTracker .ClassifyAndReset ()
78
- activeSessions .Set (float64 (active ))
79
- standbySessions .Set (float64 (standby ))
80
- inUseSessions .Set (float64 (inuse ))
78
+ for {
79
+ select {
80
+ case <- ticker .C :
81
+ active , standby , inuse :=
82
+ streamActivityTracker .ClassifyAndReset ()
83
+ activeSessions .Set (float64 (active ))
84
+ standbySessions .Set (float64 (standby ))
85
+ inUseSessions .Set (float64 (inuse ))
86
+ case <- shutdown :
87
+ log .Infof ("Shutting down Prometheus session metrics updater" )
88
+ return
89
+ }
81
90
}
82
91
}()
83
92
0 commit comments