forked from prometheus-community/elasticsearch_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (48 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
54
55
package main
import (
"flag"
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"time"
"github.com/prometheus/client_golang/prometheus"
)
const (
namespace = "elasticsearch"
indexHTML = `
<html>
<head>
<title>Elasticsearch Exporter</title>
</head>
<body>
<h1>Elasticsearch Exporter</h1>
<p>
<a href='%s'>Metrics</a>
</p>
</body>
</html>`
)
func main() {
var (
listenAddress = flag.String("web.listen-address", ":9108", "Address to listen on for web interface and telemetry.")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
esURI = flag.String("es.uri", "http://localhost:9200", "HTTP API address of an Elasticsearch node.")
esTimeout = flag.Duration("es.timeout", 5*time.Second, "Timeout for trying to get stats from Elasticsearch.")
esAllNodes = flag.Bool("es.all", false, "Export stats for all nodes in the cluster.")
)
flag.Parse()
nodesStatsURI := *esURI + "/_nodes/_local/stats"
if *esAllNodes {
nodesStatsURI = *esURI + "/_nodes/stats"
}
clusterHealthURI := *esURI + "/_cluster/health"
exporter := NewExporter(nodesStatsURI, clusterHealthURI, *esTimeout, *esAllNodes)
prometheus.MustRegister(exporter)
log.Println("Starting Server:", *listenAddress)
http.Handle(*metricsPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(fmt.Sprintf(indexHTML, *metricsPath)))
})
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}