From e8775539ae04fb66a918872a7b6585311a2e8d9f Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Thu, 25 Nov 2021 07:35:43 -0800 Subject: [PATCH] Add option to specify prometheus server address --- cmd/asynqmon/main.go | 9 ++++++--- handler.go | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/asynqmon/main.go b/cmd/asynqmon/main.go index ccc6ec3..bca45e9 100644 --- a/cmd/asynqmon/main.go +++ b/cmd/asynqmon/main.go @@ -33,6 +33,7 @@ var ( flagMaxPayloadLength int flagMaxResultLength int flagEnableMetricsExporter bool + flagPrometheusServerAddr string ) func init() { @@ -47,6 +48,7 @@ func init() { flag.IntVar(&flagMaxPayloadLength, "max-payload-length", getEnvOrDefaultInt("MAX_PAYLOAD_LENGTH", 200), "maximum number of utf8 characters printed in the payload cell in the Web UI") flag.IntVar(&flagMaxResultLength, "max-result-length", getEnvOrDefaultInt("MAX_RESULT_LENGTH", 200), "maximum number of utf8 characters printed in the result cell in the Web UI") flag.BoolVar(&flagEnableMetricsExporter, "enable-metrics-exporter", getEnvOrDefaultBool("ENABLE_METRICS_EXPORTER", false), "enable prometheus metrics exporter to expose queue metrics") + flag.StringVar(&flagPrometheusServerAddr, "prometheus-server-addr", getEnvDefaultString("PROMETHEUS_SERVER_ADDR", ""), "address of prometheus server to query time series") } // TODO: Write test and refactor this code. @@ -108,9 +110,10 @@ func main() { } h := asynqmon.New(asynqmon.Options{ - RedisConnOpt: redisConnOpt, - PayloadFormatter: asynqmon.PayloadFormatterFunc(formatPayload), - ResultFormatter: asynqmon.ResultFormatterFunc(formatResult), + RedisConnOpt: redisConnOpt, + PayloadFormatter: asynqmon.PayloadFormatterFunc(formatPayload), + ResultFormatter: asynqmon.ResultFormatterFunc(formatResult), + PrometheusAddress: flagPrometheusServerAddr, }) defer h.Close() diff --git a/handler.go b/handler.go index a14f4d6..5c297f3 100644 --- a/handler.go +++ b/handler.go @@ -34,6 +34,12 @@ type Options struct { // // This field is optional. ResultFormatter ResultFormatter + + // PrometheusAddress specifies the address of the Prometheus to connect to. + // + // This field is optional. If this field is set, asynqmon will query the Prometheus server + // to get the time series data about queue metrics and show them in the web UI. + PrometheusAddress string } // HTTPHandler is a http.Handler for asynqmon application.