/
prometheus.go
97 lines (86 loc) · 2.33 KB
/
prometheus.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
package prometheus
import (
"net/http"
"runtime"
"strconv"
"github.com/ahilsend/vaultify/pkg"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
buildInfo = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "vaultify_build_info",
Help: "Build information like version and commit",
},
[]string{"version", "goversion", "commit_hash"},
)
authLeaseRenewed = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "vaultify_auth_lease_renewed",
Help: "Counter for renewed auth leases",
},
[]string{"role", "warnings"},
)
authLeaseFailed = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "vaultify_auth_lease_renewal_failed",
Help: "Counter for renewed auth leases",
},
[]string{"role"},
)
secretLeaseRenewed = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "vaultify_secret_lease_renewed",
Help: "Counter for renewed secrets leases",
},
[]string{"role", "secret", "warnings"},
)
secretLeaseFailed = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "vaultify_secret_lease_renewal_failed",
Help: "Counter for renewed secrets leases",
},
[]string{"role", "secret"},
)
)
func init() {
// Register the metrics
prometheus.MustRegister(buildInfo)
prometheus.MustRegister(authLeaseRenewed)
prometheus.MustRegister(authLeaseFailed)
prometheus.MustRegister(secretLeaseRenewed)
prometheus.MustRegister(secretLeaseFailed)
buildInfo.With(prometheus.Labels{
"version": pkg.Version,
"commit_hash": pkg.CommitHash,
"goversion": runtime.Version(),
}).Inc()
}
func IncAuthLeaseRenewed(role string, hasWarnings bool) {
authLeaseRenewed.With(prometheus.Labels{
"role": role,
"warnings": strconv.FormatBool(hasWarnings),
}).Inc()
}
func IncAuthLeaseFailed(role string) {
authLeaseFailed.With(prometheus.Labels{
"role": role,
}).Inc()
}
func IncSecretLeaseRenewed(role string, secret string, hasWarnings bool) {
secretLeaseRenewed.With(prometheus.Labels{
"role": role,
"secret": secret,
"warnings": strconv.FormatBool(hasWarnings),
}).Inc()
}
func IncSecretLeaseFailed(role string, secret string) {
secretLeaseFailed.With(prometheus.Labels{
"role": role,
"secret": secret,
}).Inc()
}
func RegisterHandler(metricsPath string) {
http.Handle(metricsPath, promhttp.Handler())
}