-
-
Notifications
You must be signed in to change notification settings - Fork 588
/
monitor.go
61 lines (56 loc) · 1.59 KB
/
monitor.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
package observer
import (
"time"
blog "github.com/letsencrypt/boulder/log"
p "github.com/letsencrypt/boulder/observer/probes"
"github.com/prometheus/client_golang/prometheus"
)
// monitor contains the parsed, normalized, and validated configuration
// describing a given oberver monitor
type monitor struct {
name string
valid bool
period time.Duration
probe string
prober p.Prober
logger blog.Logger
metric prometheus.Registerer
}
// start creates a ticker channel then spins off a prober goroutine for
// each period specified in the monitor config and a timeout inferred
// from that period. This is not perfect, it means that the effective
// deadline for a prober goroutine will be TTL + time-to-schedule, but
// it's close enough for our purposes
func (m monitor) start() *time.Ticker {
ticker := time.NewTicker(m.period)
logInfo := func(status string, took string) {
m.logger.Infof(
"status=[%s] probe=[%s] duration=[%s] monitor=[%s]",
status, m.probe, took, m.name)
}
go func() {
for {
select {
case <-ticker.C:
success, took := m.prober.Do(m.period)
if !success {
statObservations.WithLabelValues(m.name, m.probe, "false").Add(1)
logInfo("failure", took.String())
}
statObservations.WithLabelValues(m.name, m.probe, "true").Add(1)
logInfo("success", took.String())
}
}
}()
return ticker
}
func (m monitor) New(c MonConf, log blog.Logger, prom prometheus.Registerer) *monitor {
m.name = c.getName()
m.valid = c.Valid
m.period = c.Period.Duration
m.probe = c.Probe
m.prober = c.getProber()
m.logger = log
m.metric = prom
return &m
}