From f5a5f8086c19ba6a4c6eafe89acca806334fa427 Mon Sep 17 00:00:00 2001 From: Julien Brochet Date: Fri, 4 Sep 2020 20:48:46 +0200 Subject: [PATCH] Add version cli argument --- README.md | 2 ++ exporter.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index ae8ec642..c25d7436 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,8 @@ Usage of ./nginx-prometheus-exporter: An address or unix domain socket path to listen on for web interface and telemetry. The default value can be overwritten by LISTEN_ADDRESS environment variable. (default ":9113") -web.telemetry-path string A path under which to expose metrics. The default value can be overwritten by TELEMETRY_PATH environment variable. (default "/metrics") + -version + Display the NGINX exporter version. (default false) ``` ### Exported Metrics diff --git a/exporter.go b/exporter.go index 88a8806c..68391362 100644 --- a/exporter.go +++ b/exporter.go @@ -264,6 +264,9 @@ For NGINX, the stub_status page must be available through the URI. For NGINX Plu nginxRetries = flag.Uint("nginx.retries", defaultNginxRetries, "A number of retries the exporter will make on start to connect to the NGINX stub_status page/NGINX Plus API before exiting with an error. The default value can be overwritten by NGINX_RETRIES environment variable.") + displayVersion = flag.Bool("version", + false, + "Display the NGINX exporter version.") // Custom command-line flags timeout = createPositiveDurationFlag("nginx.timeout", @@ -282,6 +285,11 @@ For NGINX, the stub_status page must be available through the URI. For NGINX Plu func main() { flag.Parse() + if *displayVersion { + fmt.Printf("NGINX Prometheus Exporter Version=%v GitCommit=%v\n", version, gitCommit) + os.Exit(0) + } + log.Printf("Starting NGINX Prometheus Exporter Version=%v GitCommit=%v", version, gitCommit) registry := prometheus.NewRegistry()