mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-08 05:56:37 +00:00
Add initial support for YAML configuration files
Signed-off-by: Ben Reedy <breed808@breed808.com>
This commit is contained in:
28
exporter.go
28
exporter.go
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"github.com/StackExchange/wmi"
|
||||
"github.com/prometheus-community/windows_exporter/collector"
|
||||
"github.com/prometheus-community/windows_exporter/config"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/prometheus/common/log"
|
||||
@@ -269,7 +270,11 @@ func initWbem() {
|
||||
|
||||
func main() {
|
||||
var (
|
||||
app = kingpin.New("windows_exporter", "")
|
||||
app = kingpin.New("windows_exporter", "")
|
||||
configFile = app.Flag(
|
||||
"config.file",
|
||||
"YAML configuration file to use. Values set in this file will override flags.",
|
||||
).Default(os.ExpandEnv("$ProgramFiles\\windows_exporter\\config.yml")).String()
|
||||
listenAddress = app.Flag(
|
||||
"telemetry.addr",
|
||||
"host:port for exporter.",
|
||||
@@ -299,7 +304,26 @@ func main() {
|
||||
log.AddFlags(app)
|
||||
app.Version(version.Print("windows_exporter"))
|
||||
app.HelpFlag.Short('h')
|
||||
app.Parse(os.Args[1:])
|
||||
|
||||
// Load values from configuration file(s). Executable flags must first be parsed, in order
|
||||
// to load the specified file(s).
|
||||
_, err := app.Parse(os.Args[1:])
|
||||
if err != nil {
|
||||
log.Fatalf("%v\n", err)
|
||||
}
|
||||
resolver, err := config.NewResolver(*configFile)
|
||||
if err != nil {
|
||||
log.Fatalf("could not load config file: %v\n", err)
|
||||
}
|
||||
err = resolver.Bind(app, os.Args[1:])
|
||||
if err != nil {
|
||||
log.Fatalf("%v\n", err)
|
||||
}
|
||||
// Parse flags once more to include those discovered in configuration file(s).
|
||||
_, err = app.Parse(os.Args[1:])
|
||||
if err != nil {
|
||||
log.Fatalf("%v\n", err)
|
||||
}
|
||||
|
||||
if *printCollectors {
|
||||
collectors := collector.Available()
|
||||
|
||||
Reference in New Issue
Block a user