-
Notifications
You must be signed in to change notification settings - Fork 2
/
metrics.go
70 lines (56 loc) · 1.68 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
package main
import (
"log"
"os"
"github.com/prometheus/client_golang/prometheus"
)
var (
checkPassing *prometheus.GaugeVec
checkExecutionTime *prometheus.SummaryVec
currentStatusCode prometheus.Gauge
dynamicLabels = []string{"check_id"}
)
func init() {
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("Unable to determine own hostname: %s", err)
}
co := prometheus.GaugeOpts{
Subsystem: "elb_instance_status",
ConstLabels: prometheus.Labels{"hostname": hostname},
}
co.Name = "check_passing"
co.Help = "Bit showing whether the check PASSed (=1) or FAILed (=0), WARNs are also reported as FAILs"
cp := prometheus.NewGaugeVec(co, dynamicLabels)
co.Name = "status_code"
co.Help = "Contains the current HTTP status code the ELB is seeing"
csc := prometheus.NewGauge(co)
cet := prometheus.NewSummaryVec(prometheus.SummaryOpts{
Namespace: co.Namespace,
Subsystem: co.Subsystem,
ConstLabels: co.ConstLabels,
Name: "check_execution_time",
Help: "Timespan in µs the execution of the check took",
}, dynamicLabels)
if err := prometheus.Register(cp); err != nil {
if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
checkPassing = are.ExistingCollector.(*prometheus.GaugeVec)
} else {
panic(err)
}
}
if err := prometheus.Register(csc); err != nil {
if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
currentStatusCode = are.ExistingCollector.(prometheus.Gauge)
} else {
panic(err)
}
}
if err := prometheus.Register(cet); err != nil {
if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
checkExecutionTime = are.ExistingCollector.(*prometheus.SummaryVec)
} else {
panic(err)
}
}
}