From 1c17ff4c995d772c97eed8c5a269f2074a9425fe Mon Sep 17 00:00:00 2001 From: Shubhendu Date: Sat, 22 Jul 2023 02:14:27 +0530 Subject: [PATCH] Enabled option to show node and bucket metrics (#4632) Earlier the command `mc admin prometheus metrics ALIAS` used to display only the cluster-level metrics. This change enables optionally to list node/bucket-specific metrics. Signed-off-by: Shubhendu Ram Tripathi --- cmd/admin-prometheus-metrics.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd/admin-prometheus-metrics.go b/cmd/admin-prometheus-metrics.go index 7035fd74..0cc3880b 100644 --- a/cmd/admin-prometheus-metrics.go +++ b/cmd/admin-prometheus-metrics.go @@ -39,24 +39,34 @@ var adminPrometheusMetricsCmd = cli.Command{ CustomHelpTemplate: `NAME: {{.HelpName}} - {{.Usage}} USAGE: - {{.HelpName}} TARGET + {{.HelpName}} TARGET [METRIC-TYPE] + +METRIC-TYPE: + valid values are ['cluster', 'node', 'bucket']. Defaults to 'cluster' if not specified. + FLAGS: {{range .VisibleFlags}}{{.}} {{end}} EXAMPLES: 1. List of metrics reported cluster wide. {{.Prompt}} {{.HelpName}} play + + 2. List of metrics reported at node level. + {{.Prompt}} {{.HelpName}} play node + + 3. List of metrics reported at bucket level. + {{.Prompt}} {{.HelpName}} play bucket `, } const ( metricsRespBodyLimit = 10 << 20 // 10 MiB - metricsEndPoint = "/minio/v2/metrics/cluster" + metricsEndPointRoot = "/minio/v2/metrics/" ) // checkSupportMetricsSyntax - validate arguments passed by a user func checkSupportMetricsSyntax(ctx *cli.Context) { - if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 { + if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 { showCommandHelpAndExit(ctx, 1) // last argument is exit code } } @@ -79,8 +89,16 @@ func printPrometheusMetrics(ctx *cli.Context) error { if e != nil { return e } + metricsSubSystem := args.Get(1) + switch metricsSubSystem { + case "node", "bucket", "cluster": + case "": + metricsSubSystem = "cluster" + default: + fatalIf(errInvalidArgument().Trace(), "invalid metric type '%v'", metricsSubSystem) + } - req, e := http.NewRequest(http.MethodGet, hostConfig.URL+metricsEndPoint, nil) + req, e := http.NewRequest(http.MethodGet, hostConfig.URL+metricsEndPointRoot+metricsSubSystem, nil) if e != nil { return e }