Skip to content

Commit 82a9b34

Browse files
committed
FEATURE | Add host to labels
1 parent e9f6a0b commit 82a9b34

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

provider/mailbox.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ type mailboxItem struct {
2020
}
2121

2222
func (mailbox Mailbox) Provide(api mailcowApi.MailcowApiClient) ([]prometheus.Collector, error) {
23-
lastLogin := *prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: "mailcow_mailbox_last_login"}, []string{"mailbox"})
24-
quotaAllowed := *prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: "mailcow_mailbox_quota_allowed"}, []string{"mailbox"})
25-
quotaUsed := *prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: "mailcow_mailbox_quota_used"}, []string{"mailbox"})
26-
messages := *prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: "mailcow_mailbox_messages"}, []string{"mailbox"})
23+
lastLogin := *prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: "mailcow_mailbox_last_login"}, []string{"host", "mailbox"})
24+
quotaAllowed := *prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: "mailcow_mailbox_quota_allowed"}, []string{"host", "mailbox"})
25+
quotaUsed := *prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: "mailcow_mailbox_quota_used"}, []string{"host", "mailbox"})
26+
messages := *prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: "mailcow_mailbox_messages"}, []string{"host", "mailbox"})
2727

2828
body := make([]mailboxItem, 0)
2929
err := api.Get("api/v1/get/mailbox/all", &body)
@@ -33,10 +33,10 @@ func (mailbox Mailbox) Provide(api mailcowApi.MailcowApiClient) ([]prometheus.Co
3333

3434
for _, m := range body {
3535
lastLoginTimestamp, _ := strconv.ParseFloat(m.LastImapLogin, 64)
36-
lastLogin.WithLabelValues(m.Username).Set(lastLoginTimestamp)
37-
quotaAllowed.WithLabelValues(m.Username).Set(float64(m.Quota))
38-
quotaUsed.WithLabelValues(m.Username).Set(float64(m.QuotaUsed))
39-
messages.WithLabelValues(m.Username).Set(float64(m.Messages))
36+
lastLogin.WithLabelValues(api.Host, m.Username).Set(lastLoginTimestamp)
37+
quotaAllowed.WithLabelValues(api.Host, m.Username).Set(float64(m.Quota))
38+
quotaUsed.WithLabelValues(api.Host, m.Username).Set(float64(m.QuotaUsed))
39+
messages.WithLabelValues(api.Host, m.Username).Set(float64(m.Messages))
4040
}
4141

4242
return []prometheus.Collector{lastLogin, quotaAllowed, quotaUsed, messages}, nil

provider/mailq.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type queueResponseItem struct {
1818
func (mailq Mailq) Provide(api mailcowApi.MailcowApiClient) ([]prometheus.Collector, error) {
1919
gauge := *prometheus.NewGaugeVec(prometheus.GaugeOpts{
2020
Name: "mailcow_mailq",
21-
}, []string{"queue", "sender"})
21+
}, []string{"host", "queue", "sender"})
2222

2323
body := make([]queueResponseItem, 0)
2424
err := api.Get("api/v1/get/mailq/all", &body)
@@ -40,7 +40,7 @@ func (mailq Mailq) Provide(api mailcowApi.MailcowApiClient) ([]prometheus.Collec
4040

4141
for queueName, senders := range queue {
4242
for sender, count := range senders {
43-
gauge.WithLabelValues(queueName, sender).Set(count)
43+
gauge.WithLabelValues(api.Host, queueName, sender).Set(count)
4444
}
4545
}
4646

provider/quarantine.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ type quarantineItem struct {
2222
func (quarantine Quarantine) Provide(api mailcowApi.MailcowApiClient) ([]prometheus.Collector, error) {
2323
countGauge := *prometheus.NewGaugeVec(prometheus.GaugeOpts{
2424
Name: "mailcow_quarantine_count",
25-
}, []string{"recipient", "is_virus"})
25+
}, []string{"host", "recipient", "is_virus"})
2626
scoreHist := *prometheus.NewHistogramVec(prometheus.HistogramOpts{
2727
Name: "mailcow_quarantine_score",
2828
Buckets: []float64{0, 10, 20, 40, 60, 80, 100},
29-
}, []string{"recipient"})
29+
}, []string{"host", "recipient"})
3030
ageHist := *prometheus.NewHistogramVec(prometheus.HistogramOpts{
3131
Name: "mailcow_quarantine_age",
3232
Help: "Age of quarantined items in seconds",
@@ -39,7 +39,7 @@ func (quarantine Quarantine) Provide(api mailcowApi.MailcowApiClient) ([]prometh
3939
(14 * 60 * 60 * 24), // 14 days
4040
(30 * 60 * 60 * 24), // 30 days
4141
},
42-
}, []string{"recipient"})
42+
}, []string{"host", "recipient"})
4343

4444
body := make([]quarantineItem, 0)
4545
err := api.Get("api/v1/get/quarantine/all", &body)
@@ -64,15 +64,15 @@ func (quarantine Quarantine) Provide(api mailcowApi.MailcowApiClient) ([]prometh
6464
}
6565

6666
age := time.Now().Unix() - q.Created
67-
ageHist.WithLabelValues(q.Recipient).Observe(float64(age))
68-
scoreHist.WithLabelValues(q.Recipient).Observe(float64(q.Score))
67+
ageHist.WithLabelValues(api.Host, q.Recipient).Observe(float64(age))
68+
scoreHist.WithLabelValues(api.Host, q.Recipient).Observe(float64(q.Score))
6969
}
7070

7171
for recipient, count := range virus {
72-
countGauge.WithLabelValues(recipient, "1").Set(float64(count))
72+
countGauge.WithLabelValues(api.Host, recipient, "1").Set(float64(count))
7373
}
7474
for recipient, count := range notVirus {
75-
countGauge.WithLabelValues(recipient, "0").Set(float64(count))
75+
countGauge.WithLabelValues(api.Host, recipient, "0").Set(float64(count))
7676
}
7777

7878
return []prometheus.Collector{

0 commit comments

Comments
 (0)