forked from kbudde/rabbitmq_exporter
/
main.go
46 lines (39 loc) · 1.15 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
package main
import (
"net/http"
"strings"
log "github.com/Sirupsen/logrus"
"github.com/prometheus/client_golang/prometheus"
)
func initLogger() {
if strings.ToUpper(config.OutputFormat) == "JSON" {
log.SetFormatter(&log.JSONFormatter{})
} else {
// The TextFormatter is default, you don't actually have to do this.
log.SetFormatter(&log.TextFormatter{})
}
}
func main() {
initConfig()
initLogger()
exporter := newExporter()
prometheus.MustRegister(exporter)
http.Handle("/metrics", prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>RabbitMQ Exporter</title></head>
<body>
<h1>RabbitMQ Exporter</h1>
<p><a href='/metrics'>Metrics</a></p>
</body>
</html>`))
})
log.WithFields(log.Fields{
"PUBLISH_PORT": config.PublishPort,
"RABBIT_URL": config.RabbitURL,
"RABBIT_USER": config.RabbitUsername,
"OUTPUT_FORMAT": config.OutputFormat,
// "RABBIT_PASSWORD": config.RABBIT_PASSWORD,
}).Info("Starting RabbitMQ exporter")
log.Fatal(http.ListenAndServe(":"+config.PublishPort, nil))
}