mirror of
https://github.com/minio/minio.git
synced 2025-05-22 01:53:55 -04:00
fix errors in metrics code on macos (#19965)
- do not load proc fs metrics in case of macos - null-check TimeStat before accessing
This commit is contained in:
parent
fae563b85d
commit
e200808ab7
@ -1688,7 +1688,7 @@ func getMinioProcMetrics() *MetricsGroupV2 {
|
|||||||
cacheInterval: 10 * time.Second,
|
cacheInterval: 10 * time.Second,
|
||||||
}
|
}
|
||||||
mg.RegisterRead(func(ctx context.Context) (metrics []MetricV2) {
|
mg.RegisterRead(func(ctx context.Context) (metrics []MetricV2) {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == globalWindowsOSName || runtime.GOOS == globalMacOSName {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,15 +55,17 @@ func loadCPUMetrics(ctx context.Context, m MetricValues, c *metricsCache) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
ts := cpuMetrics.TimesStat
|
ts := cpuMetrics.TimesStat
|
||||||
tot := ts.User + ts.System + ts.Idle + ts.Iowait + ts.Nice + ts.Steal
|
if ts != nil {
|
||||||
cpuUserVal := math.Round(ts.User/tot*100*100) / 100
|
tot := ts.User + ts.System + ts.Idle + ts.Iowait + ts.Nice + ts.Steal
|
||||||
m.Set(sysCPUUser, cpuUserVal)
|
cpuUserVal := math.Round(ts.User/tot*100*100) / 100
|
||||||
cpuSystemVal := math.Round(ts.System/tot*100*100) / 100
|
m.Set(sysCPUUser, cpuUserVal)
|
||||||
m.Set(sysCPUSystem, cpuSystemVal)
|
cpuSystemVal := math.Round(ts.System/tot*100*100) / 100
|
||||||
cpuNiceVal := math.Round(ts.Nice/tot*100*100) / 100
|
m.Set(sysCPUSystem, cpuSystemVal)
|
||||||
m.Set(sysCPUNice, cpuNiceVal)
|
cpuNiceVal := math.Round(ts.Nice/tot*100*100) / 100
|
||||||
cpuStealVal := math.Round(ts.Steal/tot*100*100) / 100
|
m.Set(sysCPUNice, cpuNiceVal)
|
||||||
m.Set(sysCPUSteal, cpuStealVal)
|
cpuStealVal := math.Round(ts.Steal/tot*100*100) / 100
|
||||||
|
m.Set(sysCPUSteal, cpuStealVal)
|
||||||
|
}
|
||||||
|
|
||||||
// metrics-resource.go runs a job to collect resource metrics including their Avg values and
|
// metrics-resource.go runs a job to collect resource metrics including their Avg values and
|
||||||
// stores them in resourceMetricsMap. We can use it to get the Avg values of CPU idle and IOWait.
|
// stores them in resourceMetricsMap. We can use it to get the Avg values of CPU idle and IOWait.
|
||||||
|
@ -156,11 +156,13 @@ func loadProcessMetrics(ctx context.Context, m MetricValues, c *metricsCache) er
|
|||||||
m.Set(processUptimeSeconds, time.Since(globalBootTime).Seconds())
|
m.Set(processUptimeSeconds, time.Since(globalBootTime).Seconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := procfs.Self()
|
if runtime.GOOS != globalWindowsOSName && runtime.GOOS != globalMacOSName {
|
||||||
if err != nil {
|
p, err := procfs.Self()
|
||||||
metricsLogIf(ctx, err)
|
if err != nil {
|
||||||
} else {
|
metricsLogIf(ctx, err)
|
||||||
loadProcFSMetrics(ctx, p, m)
|
} else {
|
||||||
|
loadProcFSMetrics(ctx, p, m)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if globalIsDistErasure && globalLockServer != nil {
|
if globalIsDistErasure && globalLockServer != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user