Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Environment Variable options to flags managed in exporter-toolkit #607

Merged
merged 9 commits into from
Jan 25, 2024
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ usage: nginx-prometheus-exporter [<flags>]
Flags:
-h, --[no-]help Show context-sensitive help (also try --help-long and --help-man).
--web.listen-address=:9113 ...
Addresses on which to expose metrics and web interface. Repeatable for multiple addresses.
--web.config.file="" Path to configuration file that can enable TLS or authentication. See: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md
Addresses on which to expose metrics and web interface. Repeatable for multiple addresses. ($LISTEN_ADDRESS)
--web.config.file="" Path to configuration file that can enable TLS or authentication. See: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md ($CONFIG_FILE)
--web.telemetry-path="/metrics"
Path under which to expose metrics. ($TELEMETRY_PATH)
--[no-]nginx.plus Start the exporter for NGINX Plus. By default, the exporter is started for NGINX. ($NGINX_PLUS)
Expand Down
16 changes: 16 additions & 0 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ var (

// Custom command-line flags
timeout = createPositiveDurationFlag(kingpin.Flag("nginx.timeout", "A timeout for scraping metrics from NGINX or NGINX Plus.").Default("5s").Envar("TIMEOUT").HintOptions("5s", "10s", "30s", "1m", "5m"))

// Flags from external modules which need environment variables added
overrideEnvVars = map[string]string{
"web.listen-address": "LISTEN_ADDRESS",
"web.systemd-socket": "SYSTEMD_SOCKET",
oseoin marked this conversation as resolved.
Show resolved Hide resolved
"web.config.file": "CONFIG_FILE",
}
)

const exporterName = "nginx_exporter"
Expand All @@ -114,6 +121,15 @@ func main() {
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print(exporterName))
kingpin.HelpFlag.Short('h')

// add environment variable options to flags
for k, v := range overrideEnvVars {
f := kingpin.CommandLine.GetFlag(k)
if f != nil {
f.Envar(v)
}
}

kingpin.Parse()
logger := promlog.New(promlogConfig)

Expand Down
Loading