-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstaclustr_exporter.go
83 lines (70 loc) · 2.97 KB
/
instaclustr_exporter.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"flag"
"fmt"
"net/http"
"os"
"time"
"github.com/fcgravalos/instaclustr_exporter/collector"
"github.com/fcgravalos/instaclustr_exporter/common"
"github.com/fcgravalos/instaclustr_exporter/instaclustr"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/version"
)
func homeHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>InstaClustr Exporter</title></head>
<body>
<h1>InstaClustr Exporter</h1>
<p><a href="/metrics">Metrics</a></p>
</body>
</html>`))
}
// NewExporter creates the InstaClustr Exporter
func NewExporter(telemetryPath string, serverOpts common.ServerOptions, instaclustrCfg instaclustr.Config) *common.Server {
exp := collector.NewExporter(instaclustrCfg)
prometheus.MustRegister(exp)
// start httpServer
s := common.NewServer("instaclustr_exporter", serverOpts)
router := mux.NewRouter()
router.HandleFunc("/", homeHandler).Methods("GET")
router.HandleFunc(serverOpts.ShutdownURL, s.ShutDownHandler).Methods("GET")
router.HandleFunc(serverOpts.LivenessProbeURL, s.LivenessProbeHandler).Methods("GET")
router.Handle(telemetryPath, prometheus.Handler()).Methods("GET")
s.HTTPServer.Handler = router
return s
}
func main() {
var (
serverOpts common.ServerOptions
instaclustrCfg instaclustr.Config
showVersion = flag.Bool("version", false, "Print version information.")
telemetryPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
)
flag.StringVar(&serverOpts.ListenAddress, "web.listen-address", ":9279", "Address to listen on for web interface and telemetry.")
flag.StringVar(&serverOpts.LivenessProbeURL, "web.liveness-probe-url", "/health", "URL for health-checks")
flag.StringVar(&serverOpts.ShutdownURL, "web.shutdown-url", "/shutdown", "URL for health-checks")
flag.DurationVar(&serverOpts.ReadTimeOut, "web.read-timeout", 10*time.Second, "Read/Write Timeout")
flag.DurationVar(&serverOpts.WriteTimeOut, "web.write-timeout", 10*time.Second, "Read/Write Timeout")
flag.StringVar(&instaclustrCfg.User, "instaclustr.user", "", "User for InstaClustr API")
flag.StringVar(&instaclustrCfg.ProvisioningAPIKey, "instaclustr.provisioning-apikey", "", "Key for the provisioning API")
flag.StringVar(&instaclustrCfg.MonitoringAPIKey, "instaclustr.monitoring-apikey", "", "Key for the provisioning API")
flag.Parse()
if *showVersion {
fmt.Println(version.Print("instaclustr_exporter"))
os.Exit(0)
}
// Make environment variables to take precedence over configuration flags
if os.Getenv("INSTACLUSTR_USER") != "" {
instaclustrCfg.User = os.Getenv("INSTACLUSTR_USER")
}
if os.Getenv("PROVISIONING_API_KEY") != "" {
instaclustrCfg.ProvisioningAPIKey = os.Getenv("PROVISIONING_API_KEY")
}
if os.Getenv("MONITORING_API_KEY") != "" {
instaclustrCfg.MonitoringAPIKey = os.Getenv("MONITORING_API_KEY")
}
s := NewExporter(*telemetryPath, serverOpts, instaclustrCfg)
s.Start()
}