-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.go
46 lines (35 loc) · 876 Bytes
/
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 (
"log"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
addr string
endpoint string
)
func main() {
loadEnv()
c := newCollector(endpoint)
err := prometheus.Register(c)
if err != nil {
log.Fatal(err)
}
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(addr, nil))
}
func loadEnv() {
addr = getEnvOr("YARN_PROMETHEUS_LISTEN_ADDR", ":9113")
scheme := getEnvOr("YARN_PROMETHEUS_ENDPOINT_SCHEME", "http")
host := getEnvOr("YARN_PROMETHEUS_ENDPOINT_HOST", "localhost")
port := getEnvOr("YARN_PROMETHEUS_ENDPOINT_PORT", "8088")
endpoint = scheme + "://" + host + ":" + port + "/"
}
func getEnvOr(key string, defaultValue string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return defaultValue
}