-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
51 lines (43 loc) · 1.82 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
package main
import (
"net/http"
"github.com/Wing924/logstash-exporter/collector"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/version"
"github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
)
func main() {
var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9649").String()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
logstashScrapeURI = kingpin.Flag("logstash.scrape-uri", "URI on which to scrape logstash.").Default("http://localhost:9600").String()
logstashTimeout = kingpin.Flag("logstash.timeout", "Timeout for trying to get stats from logstash.").Default("5s").Duration()
)
kingpin.HelpFlag.Short('h')
kingpin.Version(version.Print("logstash-exporter"))
kingpin.Parse()
logrus.WithFields(logrus.Fields{
"version": version.Info(),
"build": version.BuildContext(),
}).Info("Starting logstash-exporter")
exporter, err := collector.NewCollector(*logstashScrapeURI, *logstashTimeout)
if err != nil {
logrus.WithError(err).Fatal("failed to create exporter")
}
prometheus.MustRegister(exporter)
prometheus.MustRegister(version.NewCollector("logstash_exporter"))
http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`<html>
<head><title>Logstash Collector</title></head>
<body>
<h1>Logstash Collector</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
logrus.WithField("address", *listenAddress).Info("listening...")
logrus.Fatal(http.ListenAndServe(*listenAddress, nil))
}