-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
56 lines (49 loc) · 2.14 KB
/
main.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
package main
import (
"github.com/kelseyhightower/envconfig"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
)
var (
sent = prometheus.NewDesc("mandrill_sent_total", "Total number of sent mails.", []string{"username"}, nil)
hardBounces = prometheus.NewDesc("mandrill_hard_bounces", "Number of mails bounced hard", []string{"username"}, nil)
softBounces = prometheus.NewDesc("mandrill_soft_bounces", "Number of mails bounced soft", []string{"username"}, nil)
rejects = prometheus.NewDesc("mandrill_rejects", "Number of mails rejected", []string{"username"}, nil)
complaints = prometheus.NewDesc("mandrill_complaints", "Number of complaints", []string{"username"}, nil)
unsubs = prometheus.NewDesc("mandrill_unsubs", "Number of unsubscribes", []string{"username"}, nil)
opens = prometheus.NewDesc("mandrill_opens", "Number of mails opened", []string{"username"}, nil)
clicks = prometheus.NewDesc("mandrill_clicks", "Number of clicks inside mails", []string{"username"}, nil)
unique_opens = prometheus.NewDesc("mandrill_unique_opens", "Unique number of mails opened", []string{"username"}, nil)
unique_clicks = prometheus.NewDesc("mandrill_unique_clicks", "Unique number of clicks", []string{"username"}, nil)
)
type config struct {
Addr string `envconfig:"MANDRILL_EXPORTER_EXPORTER_LISTEN_ADDR" default:":9861"`
MandrillApiKey string `envconfig:"MANDRILL_EXPORTER_API_KEY" required:"true"`
}
func main() {
var conf config
err := envconfig.Process("", &conf)
if err != nil {
log.Fatal(err)
}
mc := collector{
apiKey: conf.MandrillApiKey,
}
prometheus.MustRegister(mc)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Mandrill stats Exporter</title></head>
<body>
<h1>Madrill statistics Exporter</h1>
<p><a href='metrics'>Metrics</a></p>
</body>
</html>`))
})
http.Handle("/metrics", promhttp.Handler())
err = http.ListenAndServe(conf.Addr, nil)
if err != nil {
log.Println(err)
}
}