From 7cd08594f6c754fc24e1e5f2f6f6832bbd8a0929 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Mon, 9 Oct 2023 17:27:11 -0700 Subject: [PATCH] Use better host names for metric errors (#18188) Typically hosts would end up like this: ``` "hosts": [ ":9000", ":9000", ":9000", ... ``` Also add host name to errors. --- cmd/metrics-realtime.go | 25 ++++++------------------- cmd/notification.go | 2 +- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/cmd/metrics-realtime.go b/cmd/metrics-realtime.go index f8e639511..7754c3025 100644 --- a/cmd/metrics-realtime.go +++ b/cmd/metrics-realtime.go @@ -20,7 +20,6 @@ package cmd import ( "context" "fmt" - "net/http" "time" "github.com/minio/madmin-go/v3" @@ -42,18 +41,6 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma return } - byHostName := globalMinioAddr - if len(opts.hosts) > 0 { - server := getLocalServerProperty(globalEndpoints, &http.Request{ - Host: globalLocalNodeName, - }) - if _, ok := opts.hosts[server.Endpoint]; ok { - byHostName = server.Endpoint - } else { - return - } - } - if types.Contains(madmin.MetricsDisk) { m.ByDisk = make(map[string]madmin.DiskMetric) aggr := madmin.DiskMetric{ @@ -87,7 +74,7 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma } netStats, err := net.GetInterfaceNetStats(globalInternodeInterface) if err != nil { - m.Errors = append(m.Errors, err.Error()) + m.Errors = append(m.Errors, fmt.Sprintf("%s: %v (nicstats)", globalMinioAddr, err.Error())) } else { m.Aggregated.Net.NetStats = netStats } @@ -104,18 +91,18 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma } cm, err := c.Times(false) if err != nil { - m.Errors = append(m.Errors, err.Error()) + m.Errors = append(m.Errors, fmt.Sprintf("%s: %v (cputimes)", globalMinioAddr, err.Error())) } else { // not collecting per-cpu stats, so there will be only one element if len(cm) == 1 { m.Aggregated.CPU.TimesStat = &cm[0] } else { - m.Errors = append(m.Errors, fmt.Sprintf("Expected one CPU stat, got %d", len(cm))) + m.Errors = append(m.Errors, fmt.Sprintf("%s: Expected one CPU stat, got %d", globalMinioAddr, len(cm))) } } loadStat, err := load.Avg() if err != nil { - m.Errors = append(m.Errors, err.Error()) + m.Errors = append(m.Errors, fmt.Sprintf("%s: %v (loadStat)", globalMinioAddr, err.Error())) } else { m.Aggregated.CPU.LoadStat = loadStat } @@ -123,8 +110,8 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma // Add types... // ByHost is a shallow reference, so careful about sharing. - m.ByHost = map[string]madmin.Metrics{byHostName: m.Aggregated} - m.Hosts = append(m.Hosts, byHostName) + m.ByHost = map[string]madmin.Metrics{globalMinioAddr: m.Aggregated} + m.Hosts = append(m.Hosts, globalMinioAddr) return m } diff --git a/cmd/notification.go b/cmd/notification.go index 57f9db544..87b63f006 100644 --- a/cmd/notification.go +++ b/cmd/notification.go @@ -777,7 +777,7 @@ func (sys *NotificationSys) GetMetrics(ctx context.Context, t madmin.MetricType, for index, err := range g.Wait() { if err != nil { - reply[index].Errors = []string{err.Error()} + reply[index].Errors = []string{fmt.Sprintf("%s: %s (rpc)", sys.peerClients[index].String(), err.Error())} } } return reply