-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
53 lines (46 loc) · 1.48 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
package main
import (
"github.com/kelseyhightower/envconfig"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
)
var (
count = prometheus.NewDesc("twilio_count", "Count by category", []string{"account", "category"}, nil)
usage = prometheus.NewDesc("twilio_usage", "Usage by category", []string{"account", "category"}, nil)
price = prometheus.NewDesc("twilio_price", "Price by category", []string{"account", "category"}, nil)
)
type config struct {
Addr string `envconfig:"TWILIO_EXPORTER_LISTEN_ADDR" default:":9860"`
AccountId string `envconfig:"TWILIO_EXPORTER_ACCOUNT_ID" required:"true"`
Sid string `envconfig:"TWILIO_EXPORTER_SID" required:"true"`
ApiKey string `envconfig:"TWILIO_EXPORTER_API_KEY" required:"true"`
}
func main() {
var conf config
err := envconfig.Process("", &conf)
if err != nil {
log.Fatal(err)
}
mc := collector{
accountId: conf.AccountId,
sid: conf.Sid,
apiKey: conf.ApiKey,
}
prometheus.MustRegister(mc)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Twilio statistics exporter</title></head>
<body>
<h1>Twilio 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.Fatal(err)
}
}