mirror of
https://github.com/minio/minio.git
synced 2025-04-27 21:35:05 -04:00
fix: noHost for collectLocalMetric (#19457)
This commit is contained in:
parent
a481825ae1
commit
ed64e91f06
@ -20,6 +20,8 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/madmin-go/v3"
|
"github.com/minio/madmin-go/v3"
|
||||||
@ -41,6 +43,22 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byHostName := globalMinioAddr
|
||||||
|
if len(opts.hosts) > 0 {
|
||||||
|
server := getLocalServerProperty(globalEndpoints, &http.Request{
|
||||||
|
Host: globalLocalNodeName,
|
||||||
|
}, false)
|
||||||
|
if _, ok := opts.hosts[server.Endpoint]; ok {
|
||||||
|
byHostName = server.Endpoint
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(byHostName, ":") && !strings.HasPrefix(globalLocalNodeName, ":") {
|
||||||
|
byHostName = globalLocalNodeName
|
||||||
|
}
|
||||||
|
|
||||||
if types.Contains(madmin.MetricsDisk) {
|
if types.Contains(madmin.MetricsDisk) {
|
||||||
m.ByDisk = make(map[string]madmin.DiskMetric)
|
m.ByDisk = make(map[string]madmin.DiskMetric)
|
||||||
aggr := madmin.DiskMetric{
|
aggr := madmin.DiskMetric{
|
||||||
@ -74,7 +92,7 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma
|
|||||||
}
|
}
|
||||||
netStats, err := net.GetInterfaceNetStats(globalInternodeInterface)
|
netStats, err := net.GetInterfaceNetStats(globalInternodeInterface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.Errors = append(m.Errors, fmt.Sprintf("%s: %v (nicstats)", globalMinioAddr, err.Error()))
|
m.Errors = append(m.Errors, fmt.Sprintf("%s: %v (nicstats)", byHostName, err.Error()))
|
||||||
} else {
|
} else {
|
||||||
m.Aggregated.Net.NetStats = netStats
|
m.Aggregated.Net.NetStats = netStats
|
||||||
}
|
}
|
||||||
@ -83,7 +101,7 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma
|
|||||||
m.Aggregated.Mem = &madmin.MemMetrics{
|
m.Aggregated.Mem = &madmin.MemMetrics{
|
||||||
CollectedAt: UTCNow(),
|
CollectedAt: UTCNow(),
|
||||||
}
|
}
|
||||||
m.Aggregated.Mem.Info = madmin.GetMemInfo(GlobalContext, globalMinioAddr)
|
m.Aggregated.Mem.Info = madmin.GetMemInfo(GlobalContext, byHostName)
|
||||||
}
|
}
|
||||||
if types.Contains(madmin.MetricsCPU) {
|
if types.Contains(madmin.MetricsCPU) {
|
||||||
m.Aggregated.CPU = &madmin.CPUMetrics{
|
m.Aggregated.CPU = &madmin.CPUMetrics{
|
||||||
@ -91,25 +109,25 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma
|
|||||||
}
|
}
|
||||||
cm, err := c.Times(false)
|
cm, err := c.Times(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.Errors = append(m.Errors, fmt.Sprintf("%s: %v (cpuTimes)", globalMinioAddr, err.Error()))
|
m.Errors = append(m.Errors, fmt.Sprintf("%s: %v (cpuTimes)", byHostName, err.Error()))
|
||||||
} else {
|
} else {
|
||||||
// not collecting per-cpu stats, so there will be only one element
|
// not collecting per-cpu stats, so there will be only one element
|
||||||
if len(cm) == 1 {
|
if len(cm) == 1 {
|
||||||
m.Aggregated.CPU.TimesStat = &cm[0]
|
m.Aggregated.CPU.TimesStat = &cm[0]
|
||||||
} else {
|
} else {
|
||||||
m.Errors = append(m.Errors, fmt.Sprintf("%s: Expected one CPU stat, got %d", globalMinioAddr, len(cm)))
|
m.Errors = append(m.Errors, fmt.Sprintf("%s: Expected one CPU stat, got %d", byHostName, len(cm)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cpuCount, err := c.Counts(true)
|
cpuCount, err := c.Counts(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.Errors = append(m.Errors, fmt.Sprintf("%s: %v (cpuCount)", globalMinioAddr, err.Error()))
|
m.Errors = append(m.Errors, fmt.Sprintf("%s: %v (cpuCount)", byHostName, err.Error()))
|
||||||
} else {
|
} else {
|
||||||
m.Aggregated.CPU.CPUCount = cpuCount
|
m.Aggregated.CPU.CPUCount = cpuCount
|
||||||
}
|
}
|
||||||
|
|
||||||
loadStat, err := load.Avg()
|
loadStat, err := load.Avg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.Errors = append(m.Errors, fmt.Sprintf("%s: %v (loadStat)", globalMinioAddr, err.Error()))
|
m.Errors = append(m.Errors, fmt.Sprintf("%s: %v (loadStat)", byHostName, err.Error()))
|
||||||
} else {
|
} else {
|
||||||
m.Aggregated.CPU.LoadStat = loadStat
|
m.Aggregated.CPU.LoadStat = loadStat
|
||||||
}
|
}
|
||||||
@ -117,8 +135,8 @@ func collectLocalMetrics(types madmin.MetricType, opts collectMetricsOpts) (m ma
|
|||||||
// Add types...
|
// Add types...
|
||||||
|
|
||||||
// ByHost is a shallow reference, so careful about sharing.
|
// ByHost is a shallow reference, so careful about sharing.
|
||||||
m.ByHost = map[string]madmin.Metrics{globalMinioAddr: m.Aggregated}
|
m.ByHost = map[string]madmin.Metrics{byHostName: m.Aggregated}
|
||||||
m.Hosts = append(m.Hosts, globalMinioAddr)
|
m.Hosts = append(m.Hosts, byHostName)
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user