Fix exporter failing to start without config flag
Signed-off-by: Ben Reedy <breed808@breed808.com>
This commit is contained in:
parent
f623c0ed89
commit
f616589c5f
|
@ -154,8 +154,6 @@ An example configuration file can be found [here](docs/example_config.yml).
|
||||||
|
|
||||||
#### Configuration file notes
|
#### Configuration file notes
|
||||||
|
|
||||||
If the `--config.file` flag is not specified, `windows_exporter` will look for a file located at `%programfiles\windows_exporter\config.yml` by default. If no file is found, CLI flags are processed as per normal.
|
|
||||||
|
|
||||||
Configuration file values can be mixed with CLI flags. E.G.
|
Configuration file values can be mixed with CLI flags. E.G.
|
||||||
|
|
||||||
`.\windows_exporter.exe --collectors.enabled=cpu,logon`
|
`.\windows_exporter.exe --collectors.enabled=cpu,logon`
|
||||||
|
|
30
exporter.go
30
exporter.go
|
@ -273,8 +273,8 @@ func main() {
|
||||||
app = kingpin.New("windows_exporter", "")
|
app = kingpin.New("windows_exporter", "")
|
||||||
configFile = app.Flag(
|
configFile = app.Flag(
|
||||||
"config.file",
|
"config.file",
|
||||||
"YAML configuration file to use. Values set in this file will override flags.",
|
"YAML configuration file to use. Values set in this file will be overriden by CLI flags.",
|
||||||
).Default(os.ExpandEnv("$ProgramFiles\\windows_exporter\\config.yml")).String()
|
).String()
|
||||||
listenAddress = app.Flag(
|
listenAddress = app.Flag(
|
||||||
"telemetry.addr",
|
"telemetry.addr",
|
||||||
"host:port for exporter.",
|
"host:port for exporter.",
|
||||||
|
@ -311,18 +311,20 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("%v\n", err)
|
log.Fatalf("%v\n", err)
|
||||||
}
|
}
|
||||||
resolver, err := config.NewResolver(*configFile)
|
if *configFile != "" {
|
||||||
if err != nil {
|
resolver, err := config.NewResolver(*configFile)
|
||||||
log.Fatalf("could not load config file: %v\n", err)
|
if err != nil {
|
||||||
}
|
log.Fatalf("could not load config file: %v\n", err)
|
||||||
err = resolver.Bind(app, os.Args[1:])
|
}
|
||||||
if err != nil {
|
err = resolver.Bind(app, os.Args[1:])
|
||||||
log.Fatalf("%v\n", err)
|
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:])
|
// Parse flags once more to include those discovered in configuration file(s).
|
||||||
if err != nil {
|
_, err = app.Parse(os.Args[1:])
|
||||||
log.Fatalf("%v\n", err)
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if *printCollectors {
|
if *printCollectors {
|
||||||
|
|
Loading…
Reference in New Issue