mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
fix: byHost realTime metrics API (#17681)
This commit is contained in:
parent
6426b74770
commit
a99cd825ab
@ -19,6 +19,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/minio/madmin-go/v3"
|
||||
@ -38,8 +39,14 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma
|
||||
return
|
||||
}
|
||||
|
||||
byHostName := globalMinioAddr
|
||||
if len(opts.hosts) > 0 {
|
||||
if _, ok := opts.hosts[globalMinioAddr]; !ok {
|
||||
server := getLocalServerProperty(globalEndpoints, &http.Request{
|
||||
Host: globalLocalNodeName,
|
||||
})
|
||||
if _, ok := opts.hosts[server.Endpoint]; ok {
|
||||
byHostName = server.Endpoint
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -85,8 +92,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{globalMinioAddr: m.Aggregated}
|
||||
m.Hosts = append(m.Hosts, globalMinioAddr)
|
||||
m.ByHost = map[string]madmin.Metrics{byHostName: m.Aggregated}
|
||||
m.Hosts = append(m.Hosts, byHostName)
|
||||
|
||||
return m
|
||||
}
|
||||
|
@ -214,6 +214,9 @@ func (client *peerRESTClient) GetMetrics(ctx context.Context, t madmin.MetricTyp
|
||||
for disk := range opts.disks {
|
||||
values.Set(peerRESTDisk, disk)
|
||||
}
|
||||
for host := range opts.hosts {
|
||||
values.Add(peerRESTHost, host)
|
||||
}
|
||||
values.Set(peerRESTJobID, opts.jobID)
|
||||
values.Set(peerRESTDepID, opts.depID)
|
||||
|
||||
|
@ -99,6 +99,7 @@ const (
|
||||
peerRESTStorageClass = "storage-class"
|
||||
peerRESTMetricsTypes = "types"
|
||||
peerRESTDisk = "disk"
|
||||
peerRESTHost = "host"
|
||||
peerRESTJobID = "job-id"
|
||||
peerRESTDepID = "depID"
|
||||
peerRESTStartRebalance = "start-rebalance"
|
||||
|
@ -453,6 +453,12 @@ func (s *peerRESTServer) GetMetricsHandler(w http.ResponseWriter, r *http.Reques
|
||||
for _, disk := range r.Form[peerRESTDisk] {
|
||||
diskMap[disk] = struct{}{}
|
||||
}
|
||||
|
||||
hostMap := make(map[string]struct{})
|
||||
for _, host := range r.Form[peerRESTHost] {
|
||||
hostMap[host] = struct{}{}
|
||||
}
|
||||
|
||||
jobID := r.Form.Get(peerRESTJobID)
|
||||
depID := r.Form.Get(peerRESTDepID)
|
||||
|
||||
@ -461,6 +467,7 @@ func (s *peerRESTServer) GetMetricsHandler(w http.ResponseWriter, r *http.Reques
|
||||
|
||||
info := collectLocalMetrics(types, collectMetricsOpts{
|
||||
disks: diskMap,
|
||||
hosts: hostMap,
|
||||
jobID: jobID,
|
||||
depID: depID,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user