Fix collector flags not being registered

Signed-off-by: Calle Pettersson <carlpett@users.noreply.github.com>
This commit is contained in:
Calle Pettersson
2020-11-07 07:56:39 +01:00
committed by Ben Reedy
parent 2fbd0464dc
commit cdbb27d0b4

View File

@@ -270,61 +270,55 @@ func initWbem() {
func main() { func main() {
var ( var (
app = kingpin.New("windows_exporter", "") configFile = kingpin.Flag(
configFile = app.Flag(
"config.file", "config.file",
"YAML configuration file to use. Values set in this file will be overriden by CLI flags.", "YAML configuration file to use. Values set in this file will be overriden by CLI flags.",
).String() ).String()
listenAddress = app.Flag( listenAddress = kingpin.Flag(
"telemetry.addr", "telemetry.addr",
"host:port for exporter.", "host:port for exporter.",
).Default(":9182").String() ).Default(":9182").String()
metricsPath = app.Flag( metricsPath = kingpin.Flag(
"telemetry.path", "telemetry.path",
"URL path for surfacing collected metrics.", "URL path for surfacing collected metrics.",
).Default("/metrics").String() ).Default("/metrics").String()
maxRequests = app.Flag( maxRequests = kingpin.Flag(
"telemetry.max-requests", "telemetry.max-requests",
"Maximum number of concurrent requests. 0 to disable.", "Maximum number of concurrent requests. 0 to disable.",
).Default("5").Int() ).Default("5").Int()
enabledCollectors = app.Flag( enabledCollectors = kingpin.Flag(
"collectors.enabled", "collectors.enabled",
"Comma-separated list of collectors to use. Use '[defaults]' as a placeholder for all the collectors enabled by default."). "Comma-separated list of collectors to use. Use '[defaults]' as a placeholder for all the collectors enabled by default.").
Default(defaultCollectors).String() Default(defaultCollectors).String()
printCollectors = app.Flag( printCollectors = kingpin.Flag(
"collectors.print", "collectors.print",
"If true, print available collectors and exit.", "If true, print available collectors and exit.",
).Bool() ).Bool()
timeoutMargin = app.Flag( timeoutMargin = kingpin.Flag(
"scrape.timeout-margin", "scrape.timeout-margin",
"Seconds to subtract from the timeout allowed by the client. Tune to allow for overhead or high loads.", "Seconds to subtract from the timeout allowed by the client. Tune to allow for overhead or high loads.",
).Default("0.5").Float64() ).Default("0.5").Float64()
) )
log.AddFlags(app) log.AddFlags(kingpin.CommandLine)
app.Version(version.Print("windows_exporter")) kingpin.Version(version.Print("windows_exporter"))
app.HelpFlag.Short('h') kingpin.HelpFlag.Short('h')
// Load values from configuration file(s). Executable flags must first be parsed, in order // Load values from configuration file(s). Executable flags must first be parsed, in order
// to load the specified file(s). // to load the specified file(s).
_, err := app.Parse(os.Args[1:]) kingpin.Parse()
if err != nil {
log.Fatalf("%v\n", err)
}
if *configFile != "" { if *configFile != "" {
resolver, err := config.NewResolver(*configFile) resolver, err := config.NewResolver(*configFile)
if err != nil { if err != nil {
log.Fatalf("could not load config file: %v\n", err) log.Fatalf("could not load config file: %v\n", err)
} }
err = resolver.Bind(app, os.Args[1:]) err = resolver.Bind(kingpin.CommandLine, os.Args[1:])
if err != nil { if err != nil {
log.Fatalf("%v\n", err) log.Fatalf("%v\n", err)
} }
// Parse flags once more to include those discovered in configuration file(s). // Parse flags once more to include those discovered in configuration file(s).
_, err = app.Parse(os.Args[1:]) kingpin.Parse()
if err != nil {
log.Fatalf("%v\n", err)
}
} }
if *printCollectors { if *printCollectors {