forked from 1player/ironport-prometheus-exporter
/
exporter.go
138 lines (122 loc) · 2.91 KB
/
exporter.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package main
import (
"github.com/prometheus/client_golang/prometheus"
"log"
"strings"
)
const namespace = "ironport"
type Exporter struct {
statusURL string
skipCertVerify bool
authUsername string
authPassword string
up prometheus.Gauge
metrics map[string]prometheus.Gauge
}
func buildMetrics(names []string) map[string]prometheus.Gauge {
m := make(map[string]prometheus.Gauge)
for _, name := range names {
m[name] = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: name,
Help: name,
})
}
return m
}
func NewExporter(statusURL string, skipCertVerify bool, userPass string) (*Exporter, error) {
var authUsername, authPassword string
// Split userPass into user and password
pieces := strings.SplitN(userPass, ":", 2)
if len(pieces) == 2 {
authUsername = pieces[0]
authPassword = pieces[1]
}
return &Exporter{
statusURL: statusURL,
skipCertVerify: skipCertVerify,
authUsername: authUsername,
authPassword: authPassword,
up: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "up",
Help: "Was the last Ironport scrape successful.",
}),
metrics: buildMetrics([]string{
"inj_msgs",
"inj_recips",
"gen_bounce_recips",
"rejected_recips",
"dropped_msgs",
"soft_bounced_evts",
"completed_recips",
"hard_bounced_recips",
"dns_hard_bounced_recips",
"5xx_hard_bounced_recips",
"filter_hard_bounced_recips",
"expired_hard_bounced_recips",
"other_hard_bounced_recips",
"delivered_recips",
"deleted_recips",
"global_unsub_hits",
"ram_utilization",
"total_utilization",
"cpu_utilization",
"av_utilization",
"case_utilization",
"bm_utilization",
"disk_utilization",
"resource_conservation",
"log_used",
"log_available",
"conn_in",
"conn_out",
"active_recips",
"unattempted_recips",
"attempted_recips",
"msgs_in_work_queue",
"dests_in_memory",
"kbytes_used",
"kbytes_free",
"msgs_in_policy_virus_outbreak_quarantine",
"kbytes_in_policy_virus_outbreak_quarantine",
"reporting_utilization",
"quarantine_utilization",
}),
}, nil
}
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
ch <- e.up.Desc()
}
func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
e.scrape()
ch <- e.up
// Collect metrics
for _, metric := range e.metrics {
ch <- metric
}
}
func (e *Exporter) scrape() {
status, err := fetchStatus(e.statusURL, e.skipCertVerify, e.authUsername, e.authPassword)
if err != nil {
log.Println("Error scraping IronPort status page: ", err)
e.up.Set(0)
return
}
e.up.Set(1)
// Process metrics
for _, counter := range status.Counters {
metric, ok := e.metrics[counter.Name]
if !ok {
continue
}
metric.Set(float64(counter.Lifetime))
}
for _, gauge := range status.Gauges {
metric, ok := e.metrics[gauge.Name]
if !ok {
continue
}
metric.Set(float64(gauge.Current))
}
}