-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (48 loc) · 1.45 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
57
package main
import (
"flag"
"net/http"
"os"
"os/signal"
"syscall"
log "github.com/Sirupsen/logrus"
"github.com/prometheus/client_golang/prometheus"
)
func init() {
flag.Parse()
parsedLevel, err := log.ParseLevel(*rawLevel)
if err != nil {
log.Fatal(err)
}
logLevel = parsedLevel
}
var logLevel log.Level = log.InfoLevel
var bindAddr = flag.String("bind-addr", ":9169", "bind address for the metrics server")
var metricsPath = flag.String("metrics-path", "/metrics", "path to metrics endpoint")
var kafkaAddr = flag.String("kafka", "localhost:9092", "host:port for kafka socket")
var rawLevel = flag.String("log-level", "info", "log level")
func main() {
log.SetLevel(logLevel)
log.Info("Starting kafka_exporter")
go serveMetrics()
exitChannel := make(chan os.Signal)
signal.Notify(exitChannel, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
exitSignal := <-exitChannel
log.WithFields(log.Fields{"signal": exitSignal}).Infof("Caught %s signal, exiting", exitSignal)
}
func serveMetrics() {
log.Infof("Starting metric http endpoint on %s", *bindAddr)
http.Handle(*metricsPath, prometheus.Handler())
http.HandleFunc("/", rootHandler)
log.Fatal(http.ListenAndServe(*bindAddr, nil))
}
func rootHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<html>
<head><title>Kafka Exporter</title></head>
<body>
<h1>Kafka Exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
}