-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
57 lines (48 loc) · 1.52 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"
"github.com/jamesalbert/facepunch_rust_exporter/v2/exporter"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
var (
BuildVersion = ""
BuildDate = ""
BuildCommitSha = ""
)
func getEnv(key string, defaultVal string) string {
if envVal, ok := os.LookupEnv(key); ok {
return envVal
}
return defaultVal
}
func main() {
var (
rustAddr = flag.String("rust.addr", getEnv("RUST_ADDR", ""), "Address of the Rust server to scrape")
rustPwd = flag.String("rcon.password", getEnv("RCON_PASSWORD", ""), "Password of the Rust server rcon")
listenAddress = flag.String("web.listen-address", getEnv("EXPORTER_WEB_LISTEN_ADDRESS", ":1337"), "Address to listen on for web interface and telemetry.")
metricPath = flag.String("web.telemetry-path", getEnv("EXPORTER_WEB_TELEMETRY_PATH", "/metrics"), "Path under which to expose metrics.")
namespace = "facepunch_rust"
)
flag.Parse()
registry := prometheus.NewRegistry()
exp, err := exporter.NewFacepunchRustExporter(*rustAddr, exporter.Options{
Password: *rustPwd,
MetricsPath: *metricPath,
Namespace: namespace,
Registry: registry,
BuildInfo: exporter.BuildInfo{
Version: BuildVersion,
CommitSha: BuildCommitSha,
Date: BuildDate,
},
})
if err != nil {
log.Fatal(err)
}
log.Infof("Providing metrics at %s%s", *listenAddress, *metricPath)
log.Debugf("Configured rust addr: %#v", *rustAddr)
log.Fatal(http.ListenAndServe(*listenAddress, exp))
}