forked from webdevops/pagerduty-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrics_system.go
More file actions
98 lines (84 loc) · 2.7 KB
/
metrics_system.go
File metadata and controls
98 lines (84 loc) · 2.7 KB
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
package main
import (
"github.com/PagerDuty/go-pagerduty"
"github.com/prometheus/client_golang/prometheus"
"github.com/webdevops/go-common/prometheus/collector"
)
type MetricsCollectorSystem struct {
collector.Processor
prometheus struct {
license *prometheus.GaugeVec
licenseCurrent *prometheus.GaugeVec
licenseAllocationsAvailable *prometheus.GaugeVec
}
}
func (m *MetricsCollectorSystem) Setup(collector *collector.Collector) {
m.Processor.Setup(collector)
m.prometheus.license = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "pagerduty_system_license_info",
Help: "PagerDuty license",
},
[]string{
"licenseID",
"licenseType",
"licenseName",
},
)
m.Collector.RegisterMetricList("pagerduty_system_license", m.prometheus.license, true)
m.prometheus.licenseCurrent = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "pagerduty_system_license_current",
Help: "PagerDuty license current value",
},
[]string{
"licenseID",
"licenseType",
"licenseName",
},
)
m.Collector.RegisterMetricList("pagerduty_system_licenses_current", m.prometheus.licenseCurrent, true)
m.prometheus.licenseAllocationsAvailable = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "pagerduty_system_license_allocations_available",
Help: "PagerDuty license allocations available",
},
[]string{
"licenseID",
"licenseType",
"licenseName",
},
)
m.Collector.RegisterMetricList("pagerduty_system_license_allocations_available", m.prometheus.licenseAllocationsAvailable, true)
}
func (m *MetricsCollectorSystem) Reset() {
}
func (m *MetricsCollectorSystem) Collect(callback chan<- func()) {
listOpts := pagerduty.ListServiceOptions{}
listOpts.Limit = PagerdutyListLimit
listOpts.Offset = 0
licenseMetricList := m.Collector.GetMetricList("pagerduty_system_license")
licenseCurrentMetricList := m.Collector.GetMetricList("pagerduty_system_licenses_current")
licenseAllocationsAvailableMetricList := m.Collector.GetMetricList("pagerduty_system_license_allocations_available")
resp, err := PagerDutyClient.ListLicensesWithContext(m.Context())
if err != nil {
panic(err)
}
for _, license := range resp.Licenses {
licenseMetricList.AddInfo(prometheus.Labels{
"licenseID": license.ID,
"licenseType": license.Type,
"licenseName": license.Name,
})
licenseCurrentMetricList.Add(prometheus.Labels{
"licenseID": license.ID,
"licenseType": license.Type,
"licenseName": license.Name,
}, float64(license.CurrentValue))
licenseAllocationsAvailableMetricList.Add(prometheus.Labels{
"licenseID": license.ID,
"licenseType": license.Type,
"licenseName": license.Name,
}, float64(license.AllocationsAvailable))
}
}