Files
Klaus PostandGitHub 16758d3d16 mnav: Add "by time" aggregated (#641)
* mnav: Add "by time" aggregated

For many the main access point is last_day -> Operation -> time_selection -> stats.

That means there is no way to investigate a certain time period and you have to navigate back 2
levels to see other operations for that time segment.

This adds last_day -> _by_time -> time segment -> operations (with summary) -> stats to multiple types.

* 1. apiView.opLeaf (line ~475) now retains segTime/interval instead of discarding them (_, _), passing them into
  APIEndpointNode — matching the KMS opLeaf which forwards both.
  2. APIEndpointNode gained segmentTime time.Time and interval int fields.
  3. APIEndpointNode.GetLeafData() now renders a "Time Segment" entry (only when segmentTime/interval are set),
  formatted as HH:MM -> HH:MM using the interval to compute the end — the KMS kmsActionLeafNode style. Other callers
  that construct APIEndpointNode without those fields (last-minute, aggregated totals) leave them zero, so the entry is
  omitted there, preserving prior output.

  I followed the KMS pattern (segTime + interval → time range) rather than RPC's absolute-timestamp form, because opLeaf
  supplies both values and the range form is consistent with this file's existing formatAPITimeSegmentDesc.

* The finding was valid and I fixed it. DiskLastDayAllNode.GetChildren (and GetChild, which had the identical flaw and
  must stay consistent with it) aggregated cross-operation segments via a shared slot index: it picked a reference
  operation (the one with the most segments), then summed seg.Segments[i] from every operation at that same index i.
  When operations have different FirstTime values, index i maps to different wall-clock times per operation, so the
  per-segment totals and time labels were misaligned.

  Fix (mnav/disk.go): both methods now call totalSegmented(node.segmented) — the same timestamp-alignment helper the
  _by_time view uses. Segmented.Add places each operation on a unified timeline by FirstTime, so total.Segments[i] is
  the correct cross-operation sum for that timestamp. The "Total" entry now uses total.Total(). Output format (names,
  descriptions, labels) is unchanged; this also makes _ALL consistent with _by_time.

* Update empty

* Time formatting

* Forward interval
2026-08-04 16:54:11 +02:00

2578 lines
88 KiB
Go

// Copyright (c) 2015-2026 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package mnav
import (
"fmt"
"sort"
"strconv"
"strings"
"time"
"github.com/dustin/go-humanize"
"github.com/minio/madmin-go/v4"
)
// DiskMetricsNavigator provides enhanced navigation for disk metrics
type DiskMetricsNavigator struct {
disk *madmin.DiskMetric
parent MetricNode
path string
opts madmin.MetricsOptions
}
func (node *DiskMetricsNavigator) GetOpts() madmin.MetricsOptions {
opts := getNodeOpts(node)
opts.DriveSetIdx = append(opts.DriveSetIdx, node.opts.DriveSetIdx...)
opts.DrivePoolIdx = append(opts.DrivePoolIdx, node.opts.DrivePoolIdx...)
opts.Disks = append(opts.Disks, node.opts.Disks...)
return opts
}
// NewDiskMetricsNavigator creates a new enhanced disk metrics navigator
func NewDiskMetricsNavigator(disk *madmin.DiskMetric, parent MetricNode, path string, opts madmin.MetricsOptions) *DiskMetricsNavigator {
opts.Type |= madmin.MetricsDisk
opts.Flags |= madmin.MetricsSMART
return &DiskMetricsNavigator{disk: disk, parent: parent, path: path, opts: opts}
}
func (node *DiskMetricsNavigator) GetChildren() []MetricChild {
if node.disk == nil {
return []MetricChild{}
}
var children []MetricChild
// Always available basic operations
children = append(children, MetricChild{Name: "ops_last_minute", Description: "Last minute drive operations by type"})
children = append(children, MetricChild{Name: "ops_last_day", Description: "Last day segmented drive operations"})
children = append(children, MetricChild{Name: "ops_lifetime", Description: "Lifetime drive operations by type"})
// IO statistics - always available as they use the whole disk object
children = append(children, MetricChild{Name: "io_last_minute", Description: "Last minute IO statistics (real-time)"})
children = append(children, MetricChild{Name: "io_last_day", Description: "Daily IO statistics (historical)"})
// Space information - always available as it's a direct field
children = append(children, MetricChild{Name: "space", Description: "Drive space information"})
// Optional features - only add if data exists
if node.disk.HealingInfo != nil {
children = append(children, MetricChild{Name: "healing", Description: "Drive healing information"})
}
if node.disk.Cache != nil {
children = append(children, MetricChild{Name: "cache", Description: "Drive cache statistics"})
}
if node.disk.SMART != nil {
children = append(children, MetricChild{Name: "smart", Description: "S.M.A.R.T. health information"})
}
return children
}
func (node *DiskMetricsNavigator) GetLeafData() map[string]string {
if node.disk == nil {
return map[string]string{"Error": "drive metrics not available"}
}
data := map[string]string{}
// Disk Overview
data["00:Info"] = fmt.Sprintf("Collected at %s",
node.disk.CollectedAt.Format("2006-01-02 15:04:05"))
// Disk Health Status
totalDisks := node.disk.NDisks
healthyDisks := totalDisks - node.disk.Offline - node.disk.Hanging - node.disk.Healing
if totalDisks > 0 {
healthPercent := float64(healthyDisks) / float64(totalDisks) * 100.0
data["Drive Health"] = fmt.Sprintf("%d healthy, %d total (%.1f%% healthy)",
healthyDisks, totalDisks, healthPercent)
if node.disk.Offline > 0 {
data["Offline Drives"] = fmt.Sprintf("%d drives offline", node.disk.Offline)
}
if node.disk.Hanging > 0 {
data["Hanging Drives"] = fmt.Sprintf("%d drives hanging", node.disk.Hanging)
}
if node.disk.Healing > 0 {
data["Healing Drives"] = fmt.Sprintf("%d drives healing", node.disk.Healing)
}
}
// Location Information
var locationParts []string
if node.disk.PoolIdx != nil {
locationParts = append(locationParts, fmt.Sprintf("Pool %d", *node.disk.PoolIdx))
}
if node.disk.SetIdx != nil {
locationParts = append(locationParts, fmt.Sprintf("Set %d", *node.disk.SetIdx))
}
if node.disk.DiskIdx != nil {
locationParts = append(locationParts, fmt.Sprintf("Drive %d", *node.disk.DiskIdx))
}
if len(locationParts) > 0 {
data["Location"] = strings.Join(locationParts, ", ")
}
if len(node.disk.FSType) == 1 {
for k := range node.disk.FSType {
data["Filesystem"] = k
}
} else if len(node.disk.FSType) > 1 {
parts := make([]string, 0, len(node.disk.FSType))
for k, v := range node.disk.FSType {
parts = append(parts, fmt.Sprintf("%s (%d)", k, v))
}
sort.Strings(parts)
data["Filesystem"] = strings.Join(parts, ", ")
}
// Storage Space Summary
if node.disk.Space.N > 0 {
totalSpace := node.disk.Space.Free.Total + node.disk.Space.Used.Total
if totalSpace > 0 {
usagePercent := float64(node.disk.Space.Used.Total) / float64(totalSpace) * 100.0
data["Storage Usage"] = fmt.Sprintf("%s used, %s free (%.1f%% used)",
humanize.Bytes(node.disk.Space.Used.Total),
humanize.Bytes(node.disk.Space.Free.Total),
usagePercent)
}
if node.disk.Space.N > 1 {
data["Space Distribution"] = fmt.Sprintf("Min: %s free, Max: %s free across %d drives",
humanize.Bytes(node.disk.Space.Free.Min),
humanize.Bytes(node.disk.Space.Free.Max),
node.disk.Space.N)
}
// Inode usage
totalInodes := node.disk.Space.UsedInodes.Total + node.disk.Space.FreeInodes.Total
if totalInodes > 0 {
inodePercent := float64(node.disk.Space.UsedInodes.Total) / float64(totalInodes) * 100.0
data["Inode Usage"] = fmt.Sprintf("%s used, %s free (%.1f%% used)",
humanize.Comma(int64(node.disk.Space.UsedInodes.Total)),
humanize.Comma(int64(node.disk.Space.FreeInodes.Total)),
inodePercent)
}
}
// Disk State Issues
if len(node.disk.State) > 0 {
var totalIssues int
for _, count := range node.disk.State {
totalIssues += count
}
if totalIssues > 0 {
data["State Issues"] = fmt.Sprintf("%d issues across %d state types",
totalIssues, len(node.disk.State))
}
}
// OPERATIONS SUMMARY - Last minute totals
if len(node.disk.LastMinute) > 0 {
var totalOps uint64
var totalBytes uint64
var totalTime float64
for _, action := range node.disk.LastMinute {
totalOps += action.Count
totalBytes += action.Bytes
totalTime += action.AccTime
}
if totalOps > 0 && totalTime > 0 {
opsPerSec := float64(totalOps) / totalTime
mbPerSec := float64(totalBytes) / totalTime / (1024 * 1024)
data["Operations"] = fmt.Sprintf("%.1f OPS/sec, %.2f MB/s (last minute totals)", opsPerSec, mbPerSec)
} else if totalOps > 0 {
data["Operations"] = fmt.Sprintf("%s operations (last minute)", humanize.Comma(int64(totalOps)))
}
}
// IO SUMMARY - From last minute IO stats
minute := &node.disk.IOStatsMinute
if minute.N > 0 {
timeframeSeconds := 60.0
// Calculate total IOs and bytes
totalIOs := minute.ReadIOs + minute.WriteIOs + minute.DiscardIOs + minute.FlushIOs
totalSectors := minute.ReadSectors + minute.WriteSectors + minute.DiscardSectors
totalBytes := totalSectors * 512 // 512 bytes per sector
if totalIOs > 0 {
iosPerSec := float64(totalIOs) / timeframeSeconds
mbPerSec := float64(totalBytes) / timeframeSeconds / (1024 * 1024)
data["IO Summary"] = fmt.Sprintf("%.1f IO/sec, %.2f MB/s (%d drives)", iosPerSec, mbPerSec, minute.N)
}
}
// Cache summary (if drive caching is enabled).
if c := node.disk.Cache; c != nil {
if c.Capacity > 0 {
data["Cache Capacity"] = humanize.Bytes(uint64(c.Capacity))
}
if reqs := c.Hits + c.Misses; reqs > 0 {
data["Cache Hit Rate"] = fmt.Sprintf("%.1f%%", float64(c.Hits)/float64(reqs)*100)
}
}
// Additional Features
var features []string
if node.disk.Cache != nil {
features = append(features, "cache stats")
}
if node.disk.HealingInfo != nil {
features = append(features, "healing info")
}
if node.disk.IOStats != nil {
features = append(features, "legacy IO stats")
}
if len(features) > 0 {
data["Available Features"] = strings.Join(features, ", ")
}
return data
}
func (node *DiskMetricsNavigator) GetMetricType() madmin.MetricType {
return node.opts.Type
}
func (node *DiskMetricsNavigator) GetMetricFlags() madmin.MetricFlags {
return node.opts.Flags
}
func (node *DiskMetricsNavigator) GetParent() MetricNode {
return node.parent
}
func (node *DiskMetricsNavigator) GetPath() string {
return node.path
}
func (node *DiskMetricsNavigator) ShouldPauseRefresh() bool {
return false
}
func (node *DiskMetricsNavigator) GetChild(name string) (MetricNode, error) {
if node.disk == nil {
return nil, fmt.Errorf("no drive data available")
}
switch name {
case "ops_last_minute":
return NewDiskLastMinuteNode(node.disk.LastMinute, node, fmt.Sprintf("%s/ops_last_minute", node.path)), nil
case "ops_last_day":
return NewDiskLastDayNode(node.disk.LastDaySegmented, node, fmt.Sprintf("%s/ops_last_day", node.path)), nil
case "ops_lifetime":
return NewDiskLifetimeOpsNode(node.disk.LifetimeOps, node, fmt.Sprintf("%s/ops_lifetime", node.path)), nil
case "io_last_minute":
return NewDiskIOMinuteStatsNode(node.disk, node, fmt.Sprintf("%s/io_last_minute", node.path)), nil
case "io_last_day":
return NewDiskIODailyStatsNode(node.disk, node, fmt.Sprintf("%s/io_last_day", node.path)), nil
case "space":
return NewDiskSpaceNode(&node.disk.Space, node, fmt.Sprintf("%s/space", node.path)), nil
case "healing":
return NewDiskHealingNode(node.disk.HealingInfo, node, fmt.Sprintf("%s/healing", node.path)), nil
case "cache":
return NewDiskCacheNode(node.disk.Cache, node, fmt.Sprintf("%s/cache", node.path)), nil
case "smart":
return NewDiskSMARTNode(node.disk.SMART, node, fmt.Sprintf("%s/smart", node.path)), nil
default:
return nil, fmt.Errorf("child not found: %s", name)
}
}
// DiskSpaceNode handles navigation for disk space information
type DiskSpaceNode struct {
space *madmin.DriveSpaceInfo
parent MetricNode
path string
}
func (node *DiskSpaceNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskSpaceNode(space *madmin.DriveSpaceInfo, parent MetricNode, path string) *DiskSpaceNode {
return &DiskSpaceNode{space: space, parent: parent, path: path}
}
func (node *DiskSpaceNode) GetChildren() []MetricChild {
return []MetricChild{}
}
func (node *DiskSpaceNode) GetLeafData() map[string]string {
if node.space == nil {
return map[string]string{"Status": "No space info available"}
}
data := map[string]string{}
// Space Overview
data["Drives"] = fmt.Sprintf("%d drives", node.space.N)
totalCapacity := node.space.Used.Total + node.space.Free.Total
if totalCapacity > 0 {
usagePercent := float64(node.space.Used.Total) / float64(totalCapacity) * 100
data["Total capacity"] = fmt.Sprintf("%s (used: %s, free: %s)",
humanize.Bytes(totalCapacity),
humanize.Bytes(node.space.Used.Total),
humanize.Bytes(node.space.Free.Total))
// Calculate inode usage percentage
totalInodes := node.space.UsedInodes.Total + node.space.FreeInodes.Total
var inodeUsageText string
if totalInodes > 0 {
inodeUsagePercent := float64(node.space.UsedInodes.Total) / float64(totalInodes) * 100
inodeUsageText = fmt.Sprintf(", %.1f%% inodes", inodeUsagePercent)
} else {
inodeUsageText = ", 0.0% inodes"
}
data["Usage"] = fmt.Sprintf("%.1f%% space%s", usagePercent, inodeUsageText)
}
// Space Distribution
if node.space.Used.Total > 0 {
data["Used space"] = fmt.Sprintf("%s (min: %s, max: %s per drive)",
humanize.Bytes(node.space.Used.Total),
humanize.Bytes(node.space.Used.Min),
humanize.Bytes(node.space.Used.Max))
}
if node.space.Free.Total > 0 {
data["Free space"] = fmt.Sprintf("%s (min: %s, max: %s per drive)",
humanize.Bytes(node.space.Free.Total),
humanize.Bytes(node.space.Free.Min),
humanize.Bytes(node.space.Free.Max))
}
// Inode Usage
if node.space.UsedInodes.Total > 0 {
data["Used inodes"] = fmt.Sprintf("%s total (min: %s, max: %s per drive)",
humanize.Comma(int64(node.space.UsedInodes.Total)),
humanize.Comma(int64(node.space.UsedInodes.Min)),
humanize.Comma(int64(node.space.UsedInodes.Max)))
}
if node.space.FreeInodes.Total > 0 {
data["Free inodes"] = fmt.Sprintf("%s total (min: %s, max: %s per drive)",
humanize.Comma(int64(node.space.FreeInodes.Total)),
humanize.Comma(int64(node.space.FreeInodes.Min)),
humanize.Comma(int64(node.space.FreeInodes.Max)))
}
return data
}
func (node *DiskSpaceNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskSpaceNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskSpaceNode) GetParent() MetricNode { return node.parent }
func (node *DiskSpaceNode) GetPath() string { return node.path }
func (node *DiskSpaceNode) ShouldPauseRefresh() bool {
return false
}
func (node *DiskSpaceNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("drive space is a leaf node - no children available")
}
// DiskLifetimeOpsNode handles navigation for lifetime disk operations
type DiskLifetimeOpsNode struct {
ops map[string]madmin.DiskAction
parent MetricNode
path string
}
func (node *DiskLifetimeOpsNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func (node *DiskLifetimeOpsNode) ShouldPauseRefresh() bool {
return false
}
func NewDiskLifetimeOpsNode(ops map[string]madmin.DiskAction, parent MetricNode, path string) *DiskLifetimeOpsNode {
return &DiskLifetimeOpsNode{ops: ops, parent: parent, path: path}
}
func (node *DiskLifetimeOpsNode) GetChildren() []MetricChild {
// Return no children - display operations as leaf data instead
return []MetricChild{}
}
func (node *DiskLifetimeOpsNode) GetLeafData() map[string]string {
if node.ops == nil {
return map[string]string{"Operation Types": "0"}
}
data := map[string]string{}
// Calculate totals across all operations first
var totalCount, totalBytes uint64
var totalTime float64
for _, action := range node.ops {
totalCount += action.Count
totalBytes += action.Bytes
totalTime += action.AccTime
}
// Add overall summary
if totalCount > 0 && totalTime > 0 {
avgTime := totalTime / float64(totalCount) * 1000 // Convert to milliseconds
rps := float64(totalCount) / totalTime
if totalBytes > 0 {
avgSize := float64(totalBytes) / float64(totalCount)
data["00:TOTAL"] = fmt.Sprintf("avg time: %.2fms, avg size: %s, rps: %.2f, n: %s",
avgTime, humanize.Bytes(uint64(avgSize)), rps, humanize.Comma(int64(totalCount)))
} else {
data["00:TOTAL"] = fmt.Sprintf("avg time: %.2fms, rps: %.2f, n: %s",
avgTime, rps, humanize.Comma(int64(totalCount)))
}
}
// Format each operation with statistics
operations := make([]string, 0, len(node.ops))
for opType := range node.ops {
operations = append(operations, opType)
}
sort.Strings(operations)
for _, opType := range operations {
action := node.ops[opType]
if action.Count > 0 && action.AccTime > 0 {
avgTime := action.AccTime / float64(action.Count) * 1000 // Convert to milliseconds
rps := float64(action.Count) / action.AccTime
if action.Bytes > 0 {
avgSize := float64(action.Bytes) / float64(action.Count)
minTime := action.MinTime * 1000 // Convert to milliseconds
maxTime := action.MaxTime * 1000 // Convert to milliseconds
data[opType] = fmt.Sprintf("avg time: %.2fms, avg size: %s, rps: %.2f, min: %.1fms max: %.1fs, n: %s",
avgTime, humanize.Bytes(uint64(avgSize)), rps, minTime, maxTime, humanize.Comma(int64(action.Count)))
} else {
minTime := action.MinTime * 1000 // Convert to milliseconds
maxTime := action.MaxTime * 1000 // Convert to milliseconds
data[opType] = fmt.Sprintf("avg time: %.2fms, rps: %.2f, min: %.1fms max: %.1fs, n: %s",
avgTime, rps, minTime, maxTime, humanize.Comma(int64(action.Count)))
}
} else {
data[opType] = fmt.Sprintf("Count: %s", humanize.Comma(int64(action.Count)))
}
}
return data
}
func (node *DiskLifetimeOpsNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskLifetimeOpsNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskLifetimeOpsNode) GetParent() MetricNode { return node.parent }
func (node *DiskLifetimeOpsNode) GetPath() string { return node.path }
func (node *DiskLifetimeOpsNode) GetChild(name string) (MetricNode, error) {
if action, exists := node.ops[name]; exists {
return NewDiskActionNode(name, &action, node, fmt.Sprintf("%s/%s", node.path, name)), nil
}
return nil, fmt.Errorf("drive operation not found: %s", name)
}
// DiskLastMinuteNode handles navigation for last minute disk operations
type DiskLastMinuteNode struct {
ops map[string]madmin.DiskAction
parent MetricNode
path string
}
func (node *DiskLastMinuteNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskLastMinuteNode(ops map[string]madmin.DiskAction, parent MetricNode, path string) *DiskLastMinuteNode {
return &DiskLastMinuteNode{ops: ops, parent: parent, path: path}
}
func (node *DiskLastMinuteNode) GetChildren() []MetricChild {
// Return no children - display operations as leaf data instead
return []MetricChild{}
}
func (node *DiskLastMinuteNode) GetLeafData() map[string]string {
if node.ops == nil {
return map[string]string{"Operation Types": "0"}
}
data := map[string]string{}
// Calculate totals across all operations first
var totalCount, totalBytes uint64
var totalTime float64
for _, action := range node.ops {
totalCount += action.Count
totalBytes += action.Bytes
totalTime += action.AccTime
}
// Add overall summary
if totalCount > 0 && totalTime > 0 {
avgTime := totalTime / float64(totalCount) * 1000 // Convert to milliseconds
rps := float64(totalCount) / totalTime
if totalBytes > 0 {
avgSize := float64(totalBytes) / float64(totalCount)
data["00:TOTAL"] = fmt.Sprintf("avg time: %.2fms, avg size: %s, rps: %.2f, n: %s",
avgTime, humanize.Bytes(uint64(avgSize)), rps, humanize.Comma(int64(totalCount)))
} else {
data["00:Total"] = fmt.Sprintf("avg time: %.2fms, rps: %.2f, n: %s",
avgTime, rps, humanize.Comma(int64(totalCount)))
}
}
// Format each operation with statistics
operations := make([]string, 0, len(node.ops))
for opType := range node.ops {
operations = append(operations, opType)
}
sort.Strings(operations)
for _, opType := range operations {
action := node.ops[opType]
if action.Count > 0 {
avgTime := action.AccTime / float64(action.Count) * 1000 // Convert to milliseconds
rps := float64(action.Count) / action.AccTime
if action.Bytes > 0 {
avgSize := float64(action.Bytes) / float64(action.Count)
minTime := action.MinTime * 1000 // Convert to milliseconds
maxTime := action.MaxTime * 1000 // Convert to milliseconds
data[opType] = fmt.Sprintf("avg time: %.2fms, avg size: %s, rps: %.2f, min: %.1fms max: %.1fs, n: %s",
avgTime, humanize.Bytes(uint64(avgSize)), rps, minTime, maxTime, humanize.Comma(int64(action.Count)))
} else {
minTime := action.MinTime * 1000 // Convert to milliseconds
maxTime := action.MaxTime * 1000 // Convert to milliseconds
data[opType] = fmt.Sprintf("avg time: %.2fms, rps: %.2f, min: %.1fms max: %.1fs, n: %s",
avgTime, rps, minTime, maxTime, humanize.Comma(int64(action.Count)))
}
} else {
data[opType] = fmt.Sprintf("Count: %s", humanize.Comma(int64(action.Count)))
}
}
return data
}
func (node *DiskLastMinuteNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskLastMinuteNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskLastMinuteNode) GetParent() MetricNode { return node.parent }
func (node *DiskLastMinuteNode) GetPath() string { return node.path }
func (node *DiskLastMinuteNode) ShouldPauseRefresh() bool {
return false
}
func (node *DiskLastMinuteNode) GetChild(name string) (MetricNode, error) {
if action, exists := node.ops[name]; exists {
return NewDiskActionNode(name, &action, node, fmt.Sprintf("%s/%s", node.path, name)), nil
}
return nil, fmt.Errorf("drive operation not found: %s", name)
}
// diskView adapts drive ops_last_day data to the generic _by_time navigation.
func diskView(ops map[string]madmin.SegmentedDiskActions) segView[madmin.DiskAction, *madmin.DiskAction] {
return segView[madmin.DiskAction, *madmin.DiskAction]{
ops: ops,
metricType: madmin.MetricsDisk,
metricFlags: madmin.MetricsDayStats,
empty: func(a *madmin.DiskAction) bool { return a.Count == 0 },
segDesc: diskSegmentDesc,
opDesc: diskOpDesc,
opLeaf: func(op string, a madmin.DiskAction, _ time.Time, _ int, parent MetricNode, path string) MetricNode {
return &DiskLastDayAllLeafNode{action: a, label: op, parent: parent, path: path}
},
sumLeaf: func(a madmin.DiskAction, _ time.Time, _ int, parent MetricNode, path string) MetricNode {
return &DiskLastDayAllLeafNode{action: a, label: "All operations", parent: parent, path: path}
},
}
}
func diskSegmentDesc(total madmin.DiskAction, _ int, segTime, end time.Time) string {
day := "Today "
if !sameLocalDay(segTime, time.Now()) {
day = "Yesterday "
}
avg := ""
if total.Count > 0 && total.AccTime > 0 {
avg = fmt.Sprintf(", %.1fms avg", (total.AccTime/float64(total.Count))*1000)
}
return fmt.Sprintf("%s%s -> %s (%d ops%s)", day, segTime.Local().Format("15:04"), end.Local().Format("15:04"), total.Count, avg)
}
func diskOpDesc(_ string, a madmin.DiskAction, _ int) string {
avg := ""
if a.Count > 0 && a.AccTime > 0 {
avg = fmt.Sprintf(", %.1fms avg", (a.AccTime/float64(a.Count))*1000)
}
return fmt.Sprintf("%d ops%s", a.Count, avg)
}
// DiskLastDayNode handles navigation for segmented last day operations
type DiskLastDayNode struct {
segmented map[string]madmin.SegmentedDiskActions
parent MetricNode
path string
}
func (node *DiskLastDayNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskLastDayNode(segmented map[string]madmin.SegmentedDiskActions, parent MetricNode, path string) *DiskLastDayNode {
return &DiskLastDayNode{segmented: segmented, parent: parent, path: path}
}
func (node *DiskLastDayNode) GetChildren() []MetricChild {
if node.segmented == nil {
return []MetricChild{}
}
children := make([]MetricChild, 0, len(node.segmented)+2)
// Time-first entry, then the aggregated per-operation _ALL.
children = append(children,
MetricChild{Name: byTimeName, Description: "Browse by time segment (all operations)"},
MetricChild{
Name: "_ALL",
Description: "All operations combined, time segmented",
},
)
// Collect operation types with their total counts
type operationInfo struct {
name string
totalOps uint64
totalBytes uint64
totalTime float64
}
var operations []operationInfo
// Add each operation type that has data as a child
for operationType, segmented := range node.segmented {
// Calculate total stats for this operation type
var totalOps, totalBytes uint64
var totalTime float64
for _, segment := range segmented.Segments {
totalOps += segment.Count
totalBytes += segment.Bytes
totalTime += segment.AccTime
}
// Only include operation types that have activity
if totalOps > 0 {
operations = append(operations, operationInfo{
name: operationType,
totalOps: totalOps,
totalBytes: totalBytes,
totalTime: totalTime,
})
}
}
// Sort operations alphabetically by name
sort.Slice(operations, func(i, j int) bool {
return operations[i].name < operations[j].name
})
// Create children from sorted operations
for _, op := range operations {
// Build stats description in the requested format
var description string
if op.totalOps > 0 && op.totalTime > 0 {
avgTime := (op.totalTime / float64(op.totalOps)) * 1000 // Convert to milliseconds
rps := float64(op.totalOps) / op.totalTime
if op.totalBytes > 0 {
avgSize := float64(op.totalBytes) / float64(op.totalOps)
description = fmt.Sprintf("avg: %.2fms, avg sz: %s, rps: %.2f, ops: %s",
avgTime,
humanize.Bytes(uint64(avgSize)),
rps,
humanize.Comma(int64(op.totalOps)))
} else {
description = fmt.Sprintf("avg: %.2fms, rps: %.2f, ops: %s",
avgTime,
rps,
humanize.Comma(int64(op.totalOps)))
}
} else {
description = fmt.Sprintf("ops: %s", humanize.Comma(int64(op.totalOps)))
}
children = append(children, MetricChild{
Name: op.name,
Description: description,
})
}
return children
}
func (node *DiskLastDayNode) GetLeafData() map[string]string {
if node.segmented == nil {
return map[string]string{"Total": "No operation data"}
}
data := map[string]string{}
// Calculate day totals across all operations and segments
var totalCount, totalBytes uint64
var totalTime float64
for _, segmented := range node.segmented {
for _, segment := range segmented.Segments {
totalCount += segment.Count
totalBytes += segment.Bytes
totalTime += segment.AccTime
}
}
// Add single total stat line
if totalCount > 0 && totalTime > 0 {
avgTime := totalTime / float64(totalCount) * 1000 // Convert to milliseconds
rps := float64(totalCount) / totalTime
if totalBytes > 0 {
avgSize := float64(totalBytes) / float64(totalCount)
data["Total"] = fmt.Sprintf("avg: %.2fms, avg sz: %s, rps: %.2f, ops: %s",
avgTime,
humanize.Bytes(uint64(avgSize)),
rps,
humanize.Comma(int64(totalCount)))
} else {
data["Total"] = fmt.Sprintf("avg: %.2fms, rps: %.2f, ops: %s",
avgTime,
rps,
humanize.Comma(int64(totalCount)))
}
} else {
data["Total"] = fmt.Sprintf("ops: %s", humanize.Comma(int64(totalCount)))
}
return data
}
func (node *DiskLastDayNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskLastDayNode) GetMetricFlags() madmin.MetricFlags { return madmin.MetricsDayStats }
func (node *DiskLastDayNode) GetParent() MetricNode { return node.parent }
func (node *DiskLastDayNode) GetPath() string { return node.path }
func (node *DiskLastDayNode) ShouldPauseRefresh() bool {
return true
}
func (node *DiskLastDayNode) GetChild(name string) (MetricNode, error) {
if node.segmented == nil {
return nil, fmt.Errorf("no segmented data available")
}
if name == byTimeName {
return newByTimeNode(diskView(node.segmented), node, node.path+"/"+byTimeName), nil
}
if name == "_ALL" {
return NewDiskLastDayAllNode(node.segmented, node, fmt.Sprintf("%s/_ALL", node.path)), nil
}
// Look for the requested operation type
if segmented, exists := node.segmented[name]; exists {
return NewDiskLastDayOperationNode(name, segmented, node, fmt.Sprintf("%s/%s", node.path, name)), nil
}
return nil, fmt.Errorf("operation type not found: %s", name)
}
// DiskIOStatsNode handles navigation for disk IO statistics
type DiskIOStatsNode struct {
disk *madmin.DiskMetric
parent MetricNode
path string
}
func (node *DiskIOStatsNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskIOStatsNode(disk *madmin.DiskMetric, parent MetricNode, path string) *DiskIOStatsNode {
return &DiskIOStatsNode{disk: disk, parent: parent, path: path}
}
func (node *DiskIOStatsNode) GetChildren() []MetricChild {
return []MetricChild{
{Name: "minute", Description: "Last minute IO statistics (real-time)"},
{Name: "daily", Description: "Daily aggregated IO statistics"},
}
}
func (node *DiskIOStatsNode) GetLeafData() map[string]string {
if node.disk == nil {
return map[string]string{"Error": "drive metrics not available"}
}
data := map[string]string{}
// Quick overview of minute stats
minute := &node.disk.IOStatsMinute
if minute.N > 0 {
totalIOs := minute.ReadIOs + minute.WriteIOs + minute.DiscardIOs + minute.FlushIOs
data["Last Minute"] = fmt.Sprintf("%s total IOs from %d drives",
humanize.Comma(int64(totalIOs)), minute.N)
if minute.TotalTicks > 0 {
utilPercent := float64(minute.TotalTicks) / (60.0 * 1000.0) * 100.0
data["Utilization"] = fmt.Sprintf("%.1f%% average utilization",
utilPercent/float64(minute.N))
}
} else {
data["Last Minute"] = "No recent IO activity data available"
}
return data
}
func (node *DiskIOStatsNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskIOStatsNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskIOStatsNode) GetParent() MetricNode { return node.parent }
func (node *DiskIOStatsNode) GetPath() string { return node.path }
func (node *DiskIOStatsNode) ShouldPauseRefresh() bool {
return false
}
func (node *DiskIOStatsNode) GetChild(name string) (MetricNode, error) {
switch name {
case "minute":
return NewDiskIOMinuteStatsNode(node.disk, node, fmt.Sprintf("%s/minute", node.path)), nil
case "daily":
return NewDiskIODailyStatsNode(node.disk, node, fmt.Sprintf("%s/daily", node.path)), nil
default:
return nil, fmt.Errorf("drive io component not found: %s", name)
}
}
// DiskIOMinuteStatsNode handles last minute IO statistics
type DiskIOMinuteStatsNode struct {
disk *madmin.DiskMetric
parent MetricNode
path string
}
func (node *DiskIOMinuteStatsNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskIOMinuteStatsNode(disk *madmin.DiskMetric, parent MetricNode, path string) *DiskIOMinuteStatsNode {
return &DiskIOMinuteStatsNode{disk: disk, parent: parent, path: path}
}
func (node *DiskIOMinuteStatsNode) GetChildren() []MetricChild { return []MetricChild{} }
func (node *DiskIOMinuteStatsNode) GetLeafData() map[string]string {
if node.disk == nil {
return map[string]string{"Error": "drive metrics not available"}
}
data := map[string]string{}
// Process minute IO stats (60 second timeframe)
minute := &node.disk.IOStatsMinute
if minute.N > 0 {
timeframeSeconds := 60.0 // Last minute stats
data["00:Info"] = fmt.Sprintf("Aggregated from %d drives over %.0f seconds",
minute.N, timeframeSeconds)
// Format IO operation totals and rates
formatIOStats(data, "Read", minute.ReadIOs, minute.ReadMerges, minute.ReadSectors,
minute.ReadTicks, minute.N, timeframeSeconds)
formatIOStats(data, "Write", minute.WriteIOs, minute.WriteMerges, minute.WriteSectors,
minute.WriteTicks, minute.N, timeframeSeconds)
formatIOStats(data, "Discard", minute.DiscardIOs, minute.DiscardMerges, minute.DiscardSectors,
minute.DiscardTicks, minute.N, timeframeSeconds)
formatIOStats(data, "Flush", minute.FlushIOs, 0, 0,
minute.FlushTicks, minute.N, timeframeSeconds)
// Add device utilization metrics
if minute.TotalTicks > 0 {
utilPercent := float64(minute.TotalTicks) / (timeframeSeconds * 1000.0) * 100.0
avgUtilPerDrive := utilPercent / float64(minute.N)
data["Device Utilization"] = fmt.Sprintf("%.1f%% total, %.1f%% avg per drive",
utilPercent, avgUtilPerDrive)
}
if minute.ReqTicks > 0 {
avgQueueTime := float64(minute.ReqTicks) / float64(minute.ReadIOs+minute.WriteIOs+minute.DiscardIOs+minute.FlushIOs)
data["Avg Queue Time"] = fmt.Sprintf("%.2fms per request", avgQueueTime)
}
if minute.CurrentIOs > 0 {
data["Current IOs"] = fmt.Sprintf("%s in flight, %.1f avg per drive",
humanize.Comma(int64(minute.CurrentIOs)), float64(minute.CurrentIOs)/float64(minute.N))
}
}
if len(data) == 0 {
return map[string]string{"Status": "No last minute IO statistics available"}
}
return data
}
func (node *DiskIOMinuteStatsNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskIOMinuteStatsNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskIOMinuteStatsNode) GetParent() MetricNode { return node.parent }
func (node *DiskIOMinuteStatsNode) GetPath() string { return node.path }
func (node *DiskIOMinuteStatsNode) ShouldPauseRefresh() bool {
return false
}
func (node *DiskIOMinuteStatsNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("minute IO stats is a leaf node")
}
// DiskIODailyStatsNode handles daily IO statistics
type DiskIODailyStatsNode struct {
disk *madmin.DiskMetric
parent MetricNode
path string
}
func (node *DiskIODailyStatsNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskIODailyStatsNode(disk *madmin.DiskMetric, parent MetricNode, path string) *DiskIODailyStatsNode {
return &DiskIODailyStatsNode{disk: disk, parent: parent, path: path}
}
func (node *DiskIODailyStatsNode) GetChildren() []MetricChild {
if node.disk == nil || len(node.disk.IOStatsDay.Segments) == 0 {
return []MetricChild{}
}
var children []MetricChild
// Add "_ALL" entry first for aggregated view, then "Total"
children = append(children,
MetricChild{Name: "_ALL", Description: "All IO types combined, time segmented"},
MetricChild{Name: "Total", Description: "Total IO statistics across all time segments"},
)
dailyStats := &node.disk.IOStatsDay
// Add time segments, most recent first (filter out empty segments)
for i := len(dailyStats.Segments) - 1; i >= 0; i-- {
segmentTime := dailyStats.FirstTime.Add(time.Duration(i*dailyStats.Interval) * time.Second)
endTime := segmentTime.Add(time.Duration(dailyStats.Interval) * time.Second)
segmentName := segmentTime.UTC().Format("15:04Z")
segment := dailyStats.Segments[i]
totalIOs := segment.ReadIOs + segment.WriteIOs + segment.DiscardIOs + segment.FlushIOs
if totalIOs == 0 {
continue
}
day := "Today "
if !sameLocalDay(segmentTime, time.Now()) {
day = "Yesterday "
}
intervalSecs := float64(dailyStats.Interval)
readIOPS := float64(segment.ReadIOs) / intervalSecs
writeIOPS := float64(segment.WriteIOs) / intervalSecs
desc := fmt.Sprintf("%s%s -> %s, r:%.1f w:%.1f IOPS",
day, segmentTime.Local().Format("15:04"), endTime.Local().Format("15:04"),
readIOPS, writeIOPS)
totalTicks := segment.ReadTicks + segment.WriteTicks + segment.DiscardTicks + segment.FlushTicks
if totalTicks > 0 && totalIOs > 0 {
avgMs := float64(totalTicks) / float64(totalIOs)
desc += fmt.Sprintf(", %.2fms avg", avgMs)
}
children = append(children, MetricChild{
Name: segmentName,
Description: desc,
})
}
return children
}
func (node *DiskIODailyStatsNode) GetLeafData() map[string]string {
if node.disk == nil {
return map[string]string{"Error": "drive metrics not available"}
}
data := map[string]string{}
// Process daily segmented IO stats
dailyStats := &node.disk.IOStatsDay
if len(dailyStats.Segments) > 0 {
// Aggregate all daily segments into totals
var totalReadIOs, totalWriteIOs, totalDiscardIOs, totalFlushIOs uint64
var totalReadSectors, totalWriteSectors, totalDiscardSectors uint64
var totalReadTicks, totalWriteTicks, totalDiscardTicks, totalFlushTicks uint64
var totalReadMerges, totalWriteMerges, totalDiscardMerges uint64
var totalTicks, totalReqTicks uint64
var segmentCount int
var numDrives int
for _, seg := range dailyStats.Segments {
totalReadIOs += seg.ReadIOs
totalWriteIOs += seg.WriteIOs
totalDiscardIOs += seg.DiscardIOs
totalFlushIOs += seg.FlushIOs
totalReadSectors += seg.ReadSectors
totalWriteSectors += seg.WriteSectors
totalDiscardSectors += seg.DiscardSectors
totalReadTicks += seg.ReadTicks
totalWriteTicks += seg.WriteTicks
totalDiscardTicks += seg.DiscardTicks
totalFlushTicks += seg.FlushTicks
totalReadMerges += seg.ReadMerges
totalWriteMerges += seg.WriteMerges
totalDiscardMerges += seg.DiscardMerges
totalTicks += seg.TotalTicks
totalReqTicks += seg.ReqTicks
if seg.N > numDrives {
numDrives = seg.N
}
segmentCount++
}
timeframeSeconds := float64(segmentCount * 3600) // Each segment represents 1 hour, convert to seconds
data["00:Info"] = fmt.Sprintf("Aggregated from %d drives over %d hour segments",
numDrives, segmentCount)
// Format IO operation totals and rates (similar to minute stats)
formatIOStats(data, "Read", totalReadIOs, totalReadMerges, totalReadSectors,
totalReadTicks, numDrives, timeframeSeconds)
formatIOStats(data, "Write", totalWriteIOs, totalWriteMerges, totalWriteSectors,
totalWriteTicks, numDrives, timeframeSeconds)
formatIOStats(data, "Discard", totalDiscardIOs, totalDiscardMerges, totalDiscardSectors,
totalDiscardTicks, numDrives, timeframeSeconds)
formatIOStats(data, "Flush", totalFlushIOs, 0, 0,
totalFlushTicks, numDrives, timeframeSeconds)
// Add device utilization metrics
if totalTicks > 0 && numDrives > 0 {
utilPercent := float64(totalTicks) / (timeframeSeconds * 1000.0) * 100.0
avgUtilPerDrive := utilPercent / float64(numDrives)
data["Device Utilization"] = fmt.Sprintf("%.1f%% total, %.1f%% avg per drive",
utilPercent, avgUtilPerDrive)
}
if totalReqTicks > 0 {
totalIOs := totalReadIOs + totalWriteIOs + totalDiscardIOs + totalFlushIOs
if totalIOs > 0 {
avgQueueTime := float64(totalReqTicks) / float64(totalIOs)
data["Avg Queue Time"] = fmt.Sprintf("%.2fms per request", avgQueueTime)
}
}
} else {
data["Status"] = "No daily IO statistics available"
data["Note"] = "Daily IO segments may not be collected yet or MetricsDayStats flag not enabled"
}
return data
}
func (node *DiskIODailyStatsNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskIODailyStatsNode) GetMetricFlags() madmin.MetricFlags { return madmin.MetricsDayStats }
func (node *DiskIODailyStatsNode) GetParent() MetricNode { return node.parent }
func (node *DiskIODailyStatsNode) GetPath() string { return node.path }
func (node *DiskIODailyStatsNode) ShouldPauseRefresh() bool {
return true
}
func (node *DiskIODailyStatsNode) GetChild(name string) (MetricNode, error) {
if node.disk == nil {
return nil, fmt.Errorf("no drive metrics available")
}
dailyStats := &node.disk.IOStatsDay
if name == "_ALL" {
return NewDiskIOLastDayAllNode(dailyStats, node, fmt.Sprintf("%s/_ALL", node.path)), nil
}
// Handle "Total" entry
if name == "Total" {
return &DiskIOTotalNode{
dailyStats: *dailyStats,
parent: node,
path: fmt.Sprintf("%s/Total", node.path),
}, nil
}
// Handle time segments - find by time format (with UTC indicator)
for i := len(dailyStats.Segments) - 1; i >= 0; i-- {
segmentTime := dailyStats.FirstTime.Add(time.Duration(i*dailyStats.Interval) * time.Second)
if segmentTime.UTC().Format("15:04Z") == name {
return NewDiskIOTimeSegmentNode(dailyStats.Segments[i], segmentTime, dailyStats.Interval, node, fmt.Sprintf("%s/%s", node.path, name)), nil
}
}
return nil, fmt.Errorf("time segment not found: %s", name)
}
// DiskHealingNode handles navigation for disk healing information
type DiskHealingNode struct {
healing *madmin.DriveHealInfo
parent MetricNode
path string
}
func (node *DiskHealingNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskHealingNode(healing *madmin.DriveHealInfo, parent MetricNode, path string) *DiskHealingNode {
return &DiskHealingNode{healing: healing, parent: parent, path: path}
}
func (node *DiskHealingNode) GetChildren() []MetricChild { return []MetricChild{} }
func (node *DiskHealingNode) GetLeafData() map[string]string {
if node.healing == nil {
return map[string]string{"Status": "No healing activity"}
}
data := map[string]string{}
// Healing Status
if node.healing.Finished {
data["Status"] = "Healing completed"
} else {
data["Status"] = "Healing in progress"
}
// Progress Information
if node.healing.ItemsHealed > 0 {
data["Items healed"] = humanize.Comma(int64(node.healing.ItemsHealed))
}
if node.healing.ItemsFailed > 0 {
data["Items failed"] = humanize.Comma(int64(node.healing.ItemsFailed))
}
// Success Rate
totalItems := node.healing.ItemsHealed + node.healing.ItemsFailed
if totalItems > 0 {
successRate := float64(node.healing.ItemsHealed) / float64(totalItems) * 100
data["Success rate"] = fmt.Sprintf("%.1f%%", successRate)
data["Total processed"] = humanize.Comma(int64(totalItems))
}
// Timing Information
if !node.healing.Started.IsZero() {
data["Started"] = node.healing.Started.Format("15:04:05")
// Calculate duration
endTime := node.healing.Updated
if endTime.IsZero() || !node.healing.Finished {
endTime = time.Now()
}
if !endTime.IsZero() {
duration := endTime.Sub(node.healing.Started)
data["Duration"] = formatDuration(duration)
}
}
if !node.healing.Updated.IsZero() {
data["Last updated"] = node.healing.Updated.Format("15:04:05")
}
// Heal ID (technical info)
if node.healing.HealID != "" {
data["Heal ID"] = node.healing.HealID
}
return data
}
func (node *DiskHealingNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskHealingNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskHealingNode) GetParent() MetricNode { return node.parent }
func (node *DiskHealingNode) GetPath() string { return node.path }
func (node *DiskHealingNode) ShouldPauseRefresh() bool {
return false
}
func (node *DiskHealingNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("drive healing is a leaf node")
}
// DiskLastDayAllNode shows time-segmented totals across all operation types.
type DiskLastDayAllNode struct {
segmented map[string]madmin.SegmentedDiskActions
parent MetricNode
path string
}
func NewDiskLastDayAllNode(segmented map[string]madmin.SegmentedDiskActions, parent MetricNode, path string) *DiskLastDayAllNode {
return &DiskLastDayAllNode{segmented: segmented, parent: parent, path: path}
}
func (node *DiskLastDayAllNode) GetOpts() madmin.MetricsOptions { return getNodeOpts(node) }
func (node *DiskLastDayAllNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskLastDayAllNode) GetMetricFlags() madmin.MetricFlags { return madmin.MetricsDayStats }
func (node *DiskLastDayAllNode) GetParent() MetricNode { return node.parent }
func (node *DiskLastDayAllNode) GetPath() string { return node.path }
func (node *DiskLastDayAllNode) ShouldPauseRefresh() bool { return true }
func (node *DiskLastDayAllNode) GetLeafData() map[string]string { return nil }
func (node *DiskLastDayAllNode) GetChildren() []MetricChild {
// Align every operation onto one timeline; each slot is the cross-operation sum.
total := totalSegmented(node.segmented)
if len(total.Segments) == 0 {
return []MetricChild{}
}
children := []MetricChild{{Name: "Total", Description: "Aggregated totals across all time segments"}}
for i := len(total.Segments) - 1; i >= 0; i-- {
seg := total.Segments[i]
if seg.Count == 0 {
continue
}
segmentTime := total.FirstTime.Add(time.Duration(i*total.Interval) * time.Second)
endTime := segmentTime.Add(time.Duration(total.Interval) * time.Second)
avg := ""
if seg.AccTime > 0 {
avg = fmt.Sprintf(", %.1fms avg", (seg.AccTime/float64(seg.Count))*1000)
}
day := "Today "
if !sameLocalDay(segmentTime, time.Now()) {
day = "Yesterday "
}
children = append(children, MetricChild{
Name: segmentTime.UTC().Format("15:04Z"),
Description: fmt.Sprintf("%s%s -> %s (%d ops%s)",
day, segmentTime.Local().Format("15:04"), endTime.Local().Format("15:04"),
seg.Count, avg),
})
}
return children
}
func (node *DiskLastDayAllNode) GetChild(name string) (MetricNode, error) {
total := totalSegmented(node.segmented)
if len(total.Segments) == 0 {
return nil, fmt.Errorf("no segmented data available")
}
if name == "Total" {
return &DiskLastDayAllLeafNode{action: total.Total(), label: "Total", parent: node, path: node.path + "/Total"}, nil
}
for i := range total.Segments {
segmentTime := total.FirstTime.Add(time.Duration(i*total.Interval) * time.Second)
if segmentTime.UTC().Format("15:04Z") == name {
endTime := segmentTime.Add(time.Duration(total.Interval) * time.Second)
label := fmt.Sprintf("%s -> %s", segmentTime.Local().Format("15:04"), endTime.Local().Format("15:04"))
return &DiskLastDayAllLeafNode{action: total.Segments[i], label: label, parent: node, path: node.path + "/" + name}, nil
}
}
return nil, fmt.Errorf("time segment not found: %s", name)
}
// DiskLastDayAllLeafNode shows aggregated DiskAction data for a single time segment (or total).
type DiskLastDayAllLeafNode struct {
action madmin.DiskAction
label string
parent MetricNode
path string
}
func (node *DiskLastDayAllLeafNode) GetOpts() madmin.MetricsOptions { return getNodeOpts(node) }
func (node *DiskLastDayAllLeafNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskLastDayAllLeafNode) GetMetricFlags() madmin.MetricFlags {
return madmin.MetricsDayStats
}
func (node *DiskLastDayAllLeafNode) GetParent() MetricNode { return node.parent }
func (node *DiskLastDayAllLeafNode) GetPath() string { return node.path }
func (node *DiskLastDayAllLeafNode) ShouldPauseRefresh() bool { return true }
func (node *DiskLastDayAllLeafNode) GetChildren() []MetricChild { return nil }
func (node *DiskLastDayAllLeafNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("leaf node")
}
func (node *DiskLastDayAllLeafNode) GetLeafData() map[string]string {
data := map[string]string{}
t := node.action
if t.Count == 0 {
data["Operations"] = "0"
return data
}
avgTime := t.AccTime / float64(t.Count) * 1000
minTime := t.MinTime * 1000
maxTime := t.MaxTime * 1000
data["Operations"] = humanize.Comma(int64(t.Count))
data["Time"] = fmt.Sprintf("%.2f/%.2f/%.2f ms (min/avg/max)", minTime, avgTime, maxTime)
if t.AccTime > 0 {
data["Rate"] = fmt.Sprintf("%.2f ops/sec", float64(t.Count)/t.AccTime)
}
if t.Bytes > 0 {
avgSize := float64(t.Bytes) / float64(t.Count)
data["Data Transferred"] = fmt.Sprintf("%s total, %s avg/op", humanize.Bytes(t.Bytes), humanize.Bytes(uint64(avgSize)))
}
errPct := float64(t.AvailabilityErrs+t.Timeouts) / float64(t.Count) * 100
data["Errors"] = fmt.Sprintf("%.1f%%", errPct)
return data
}
// DiskLastDayOperationNode handles navigation for a specific operation type within segmented last day operations
type DiskLastDayOperationNode struct {
operationType string
segmented madmin.SegmentedDiskActions
parent MetricNode
path string
}
func (node *DiskLastDayOperationNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskLastDayOperationNode(operationType string, segmented madmin.SegmentedDiskActions, parent MetricNode, path string) *DiskLastDayOperationNode {
return &DiskLastDayOperationNode{operationType: operationType, segmented: segmented, parent: parent, path: path}
}
func (node *DiskLastDayOperationNode) ShouldPauseUpdates() bool { return false }
func (node *DiskLastDayOperationNode) GetChildren() []MetricChild {
var children []MetricChild
// Add "Total" entry first
children = append(children, MetricChild{
Name: "Total",
Description: "Total statistics across all time segments",
})
// Add time segments, most recent first (filter out empty segments)
for i := len(node.segmented.Segments) - 1; i >= 0; i-- {
segmentTime := node.segmented.FirstTime.Add(time.Duration(i*node.segmented.Interval) * time.Second)
endTime := segmentTime.Add(time.Duration(node.segmented.Interval) * time.Second)
segmentName := segmentTime.UTC().Format("15:04Z")
// Get operation count for this segment
var operations uint64
if i < len(node.segmented.Segments) {
operations = node.segmented.Segments[i].Count
}
// Filter out time segments with no operations
if operations == 0 {
continue
}
// Add average time if available
avg := ""
if operations > 0 && node.segmented.Segments[i].AccTime > 0 {
avgTime := (node.segmented.Segments[i].AccTime / float64(operations)) * 1000
avg = fmt.Sprintf(", %.1fms avg", avgTime)
}
// Determine day prefix
day := "Today "
if !sameLocalDay(segmentTime, time.Now()) {
day = "Yesterday "
}
children = append(children, MetricChild{
Name: segmentName,
Description: fmt.Sprintf("%s%s -> %s (%d ops%s)",
day,
segmentTime.Local().Format("15:04"),
endTime.Local().Format("15:04"),
operations,
avg),
})
}
return children
}
func (node *DiskLastDayOperationNode) GetChild(name string) (MetricNode, error) {
// Handle "Total" entry
if name == "Total" {
return &DiskOperationTotalNode{
operationType: node.operationType,
segmented: node.segmented,
parent: node,
path: fmt.Sprintf("%s/Total", node.path),
}, nil
}
// Handle time segments - find by time format (with UTC indicator)
for i := len(node.segmented.Segments) - 1; i >= 0; i-- {
segmentTime := node.segmented.FirstTime.Add(time.Duration(i*node.segmented.Interval) * time.Second)
if segmentTime.UTC().Format("15:04Z") == name {
return &DiskOperationTimeSegmentNode{
operationType: node.operationType,
segment: node.segmented.Segments[i],
segmentTime: segmentTime,
interval: node.segmented.Interval,
parent: node,
path: fmt.Sprintf("%s/%s", node.path, name),
}, nil
}
}
return nil, fmt.Errorf("time segment not found: %s", name)
}
func (node *DiskLastDayOperationNode) GetLeafData() map[string]string { return nil }
func (node *DiskLastDayOperationNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskLastDayOperationNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskLastDayOperationNode) GetParent() MetricNode { return node.parent }
func (node *DiskLastDayOperationNode) GetPath() string { return node.path }
func (node *DiskLastDayOperationNode) ShouldPauseRefresh() bool { return false }
// DiskOperationTotalNode shows aggregated statistics for an operation across all time segments
type DiskOperationTotalNode struct {
operationType string
segmented madmin.SegmentedDiskActions
parent MetricNode
path string
}
func (node *DiskOperationTotalNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func (node *DiskOperationTotalNode) ShouldPauseUpdates() bool { return false }
func (node *DiskOperationTotalNode) GetChildren() []MetricChild { return []MetricChild{} }
func (node *DiskOperationTotalNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskOperationTotalNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskOperationTotalNode) GetParent() MetricNode { return node.parent }
func (node *DiskOperationTotalNode) GetPath() string { return node.path }
func (node *DiskOperationTotalNode) ShouldPauseRefresh() bool { return false }
func (node *DiskOperationTotalNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("operation total is a leaf node")
}
func (node *DiskOperationTotalNode) GetLeafData() map[string]string {
data := map[string]string{}
// Calculate totals across all segments using the Total() method
total := node.segmented.Total()
// Time range info - show full day range
if len(node.segmented.Segments) > 0 {
firstTime := node.segmented.FirstTime
lastSegmentTime := node.segmented.FirstTime.Add(time.Duration((len(node.segmented.Segments)-1)*node.segmented.Interval) * time.Second)
endTime := lastSegmentTime.Add(time.Duration(node.segmented.Interval) * time.Second)
data["Time Range"] = fmt.Sprintf("%s -> %s",
firstTime.Local().Format("15:04"),
endTime.Local().Format("15:04"))
}
// Operation statistics
if total.Count > 0 {
avgTime := total.AccTime / float64(total.Count) * 1000 // Convert to milliseconds
minTime := total.MinTime * 1000 // Convert to milliseconds
maxTime := total.MaxTime * 1000 // Convert to milliseconds
if total.AccTime > 0 {
rps := float64(total.Count) / total.AccTime
data["Rate"] = fmt.Sprintf("%.2f ops/sec", rps)
}
data["Operations"] = humanize.Comma(int64(total.Count))
data["Time"] = fmt.Sprintf("%.2f/%.2f/%.2f ms (min/avg/max)", minTime, avgTime, maxTime)
if total.Bytes > 0 {
avgSize := float64(total.Bytes) / float64(total.Count)
data["Data Transferred"] = fmt.Sprintf("%s total, %s avg/op", humanize.Bytes(total.Bytes), humanize.Bytes(uint64(avgSize)))
}
errPct := float64(total.AvailabilityErrs+total.Timeouts) / float64(total.Count) * 100
data["Errors"] = fmt.Sprintf("%.1f%%", errPct)
} else {
data["Operations"] = "0"
}
return data
}
// DiskOperationTimeSegmentNode shows statistics for a specific operation type within a specific time segment
type DiskOperationTimeSegmentNode struct {
operationType string
segment madmin.DiskAction
segmentTime time.Time
interval int // Segment interval in seconds
parent MetricNode
path string
}
func (node *DiskOperationTimeSegmentNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func (node *DiskOperationTimeSegmentNode) ShouldPauseUpdates() bool { return false }
func (node *DiskOperationTimeSegmentNode) GetChildren() []MetricChild { return []MetricChild{} }
func (node *DiskOperationTimeSegmentNode) GetMetricType() madmin.MetricType {
return madmin.MetricsDisk
}
func (node *DiskOperationTimeSegmentNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskOperationTimeSegmentNode) GetParent() MetricNode { return node.parent }
func (node *DiskOperationTimeSegmentNode) GetPath() string { return node.path }
func (node *DiskOperationTimeSegmentNode) ShouldPauseRefresh() bool { return false }
func (node *DiskOperationTimeSegmentNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("operation time segment is a leaf node")
}
func (node *DiskOperationTimeSegmentNode) GetLeafData() map[string]string {
data := map[string]string{}
// Time range info - use proper interval
endTime := node.segmentTime.Add(time.Duration(node.interval) * time.Second)
data["Time Range"] = fmt.Sprintf("%s -> %s",
node.segmentTime.Local().Format("15:04"),
endTime.Local().Format("15:04"))
// Operation statistics
if node.segment.Count > 0 {
avgTime := node.segment.AccTime / float64(node.segment.Count) * 1000 // Convert to milliseconds
minTime := node.segment.MinTime * 1000 // Convert to milliseconds
maxTime := node.segment.MaxTime * 1000 // Convert to milliseconds
if node.segment.AccTime > 0 {
rps := float64(node.segment.Count) / node.segment.AccTime
data["Rate"] = fmt.Sprintf("%.2f ops/sec", rps)
}
data["Operations"] = humanize.Comma(int64(node.segment.Count))
data["Time"] = fmt.Sprintf("%.2f/%.2f/%.2f ms (min/avg/max)", minTime, avgTime, maxTime)
if node.segment.Bytes > 0 {
avgSize := float64(node.segment.Bytes) / float64(node.segment.Count)
data["Data Transferred"] = fmt.Sprintf("%s total, %s avg/op", humanize.Bytes(node.segment.Bytes), humanize.Bytes(uint64(avgSize)))
}
errPct := float64(node.segment.AvailabilityErrs+node.segment.Timeouts) / float64(node.segment.Count) * 100
data["Errors"] = fmt.Sprintf("%.1f%%", errPct)
} else {
data["Operations"] = "0"
}
return data
}
// DiskIOTimeSegmentNode shows IO statistics for a specific time segment
type DiskIOTimeSegmentNode struct {
segment madmin.DiskIOStats
segmentTime time.Time
interval int // Segment interval in seconds
parent MetricNode
path string
}
func (node *DiskIOTimeSegmentNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskIOTimeSegmentNode(segment madmin.DiskIOStats, segmentTime time.Time, interval int, parent MetricNode, path string) *DiskIOTimeSegmentNode {
return &DiskIOTimeSegmentNode{segment: segment, segmentTime: segmentTime, interval: interval, parent: parent, path: path}
}
func (node *DiskIOTimeSegmentNode) ShouldPauseUpdates() bool { return false }
func (node *DiskIOTimeSegmentNode) GetChildren() []MetricChild { return []MetricChild{} }
func (node *DiskIOTimeSegmentNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskIOTimeSegmentNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskIOTimeSegmentNode) GetParent() MetricNode { return node.parent }
func (node *DiskIOTimeSegmentNode) GetPath() string { return node.path }
func (node *DiskIOTimeSegmentNode) ShouldPauseRefresh() bool { return false }
func (node *DiskIOTimeSegmentNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("IO time segment is a leaf node")
}
func (node *DiskIOTimeSegmentNode) GetLeafData() map[string]string {
data := map[string]string{}
// Time range info - use proper interval
endTime := node.segmentTime.Add(time.Duration(node.interval) * time.Second)
data["Time Range"] = fmt.Sprintf("%s -> %s",
node.segmentTime.Local().Format("15:04"),
endTime.Local().Format("15:04"))
// IO statistics for this segment using the same format as io_last_minute
totalIOs := node.segment.ReadIOs + node.segment.WriteIOs + node.segment.DiscardIOs + node.segment.FlushIOs
if totalIOs > 0 {
// Use proper segment timeframe
timeframeSeconds := float64(node.interval)
numDrives := node.segment.N // Number of drives for this segment
if numDrives == 0 {
numDrives = 1 // Avoid division by zero
}
data["00:Info"] = fmt.Sprintf("Aggregated from %d drives over %.0f seconds",
numDrives, timeframeSeconds)
// Format IO operation stats using the same formatIOStats function
formatIOStats(data, "Read", node.segment.ReadIOs, node.segment.ReadMerges, node.segment.ReadSectors,
node.segment.ReadTicks, numDrives, timeframeSeconds)
formatIOStats(data, "Write", node.segment.WriteIOs, node.segment.WriteMerges, node.segment.WriteSectors,
node.segment.WriteTicks, numDrives, timeframeSeconds)
formatIOStats(data, "Discard", node.segment.DiscardIOs, node.segment.DiscardMerges, node.segment.DiscardSectors,
node.segment.DiscardTicks, numDrives, timeframeSeconds)
formatIOStats(data, "Flush", node.segment.FlushIOs, 0, 0,
node.segment.FlushTicks, numDrives, timeframeSeconds)
// Add device utilization metrics
if node.segment.TotalTicks > 0 {
utilPercent := float64(node.segment.TotalTicks) / (timeframeSeconds * 1000.0) * 100.0
avgUtilPerDrive := utilPercent / float64(numDrives)
data["Device Utilization"] = fmt.Sprintf("%.1f%% total, %.1f%% avg per drive",
utilPercent, avgUtilPerDrive)
}
// Show current IOs if available
if node.segment.CurrentIOs > 0 {
data["Current IOs"] = fmt.Sprintf("%d operations in progress", node.segment.CurrentIOs)
}
} else {
data["00:Info"] = "No IO activity in this time segment"
}
return data
}
// DiskIOLastDayAllNode shows time-segmented IO totals with navigation into each segment.
type DiskIOLastDayAllNode struct {
dailyStats *madmin.SegmentedDiskIO
parent MetricNode
path string
}
func NewDiskIOLastDayAllNode(dailyStats *madmin.SegmentedDiskIO, parent MetricNode, path string) *DiskIOLastDayAllNode {
return &DiskIOLastDayAllNode{dailyStats: dailyStats, parent: parent, path: path}
}
func (node *DiskIOLastDayAllNode) GetOpts() madmin.MetricsOptions { return getNodeOpts(node) }
func (node *DiskIOLastDayAllNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskIOLastDayAllNode) GetMetricFlags() madmin.MetricFlags { return madmin.MetricsDayStats }
func (node *DiskIOLastDayAllNode) GetParent() MetricNode { return node.parent }
func (node *DiskIOLastDayAllNode) GetPath() string { return node.path }
func (node *DiskIOLastDayAllNode) ShouldPauseRefresh() bool { return true }
func (node *DiskIOLastDayAllNode) GetLeafData() map[string]string { return nil }
func (node *DiskIOLastDayAllNode) GetChildren() []MetricChild {
if node.dailyStats == nil || len(node.dailyStats.Segments) == 0 {
return nil
}
children := []MetricChild{{Name: "Total", Description: "Aggregated IO totals across all time segments"}}
for i := len(node.dailyStats.Segments) - 1; i >= 0; i-- {
seg := node.dailyStats.Segments[i]
totalIOs := seg.ReadIOs + seg.WriteIOs + seg.DiscardIOs + seg.FlushIOs
if totalIOs == 0 {
continue
}
segmentTime := node.dailyStats.FirstTime.Add(time.Duration(i*node.dailyStats.Interval) * time.Second)
endTime := segmentTime.Add(time.Duration(node.dailyStats.Interval) * time.Second)
intervalSecs := float64(node.dailyStats.Interval)
readIOPS := float64(seg.ReadIOs) / intervalSecs
writeIOPS := float64(seg.WriteIOs) / intervalSecs
day := "Today "
if !sameLocalDay(segmentTime, time.Now()) {
day = "Yesterday "
}
desc := fmt.Sprintf("%s%s -> %s, r:%.1f w:%.1f IOPS",
day, segmentTime.Local().Format("15:04"), endTime.Local().Format("15:04"),
readIOPS, writeIOPS)
totalTicks := seg.ReadTicks + seg.WriteTicks + seg.DiscardTicks + seg.FlushTicks
if totalTicks > 0 && totalIOs > 0 {
desc += fmt.Sprintf(", %.2fms avg", float64(totalTicks)/float64(totalIOs))
}
children = append(children, MetricChild{
Name: segmentTime.UTC().Format("15:04Z"),
Description: desc,
})
}
return children
}
func (node *DiskIOLastDayAllNode) GetChild(name string) (MetricNode, error) {
if node.dailyStats == nil {
return nil, fmt.Errorf("no IO data available")
}
if name == "Total" {
return &DiskIOTotalNode{
dailyStats: *node.dailyStats,
parent: node,
path: node.path + "/Total",
}, nil
}
for i := range node.dailyStats.Segments {
segmentTime := node.dailyStats.FirstTime.Add(time.Duration(i*node.dailyStats.Interval) * time.Second)
if segmentTime.UTC().Format("15:04Z") == name {
return NewDiskIOTimeSegmentNode(node.dailyStats.Segments[i], segmentTime, node.dailyStats.Interval, node, node.path+"/"+name), nil
}
}
return nil, fmt.Errorf("time segment not found: %s", name)
}
type DiskIOTotalNode struct {
dailyStats madmin.SegmentedDiskIO
parent MetricNode
path string
}
func (node *DiskIOTotalNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func (node *DiskIOTotalNode) ShouldPauseUpdates() bool { return false }
func (node *DiskIOTotalNode) GetChildren() []MetricChild { return []MetricChild{} }
func (node *DiskIOTotalNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskIOTotalNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskIOTotalNode) GetParent() MetricNode { return node.parent }
func (node *DiskIOTotalNode) GetPath() string { return node.path }
func (node *DiskIOTotalNode) ShouldPauseRefresh() bool { return false }
func (node *DiskIOTotalNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("IO total is a leaf node")
}
func (node *DiskIOTotalNode) GetLeafData() map[string]string {
data := map[string]string{}
// Aggregate all segments
var totalReadIOs, totalWriteIOs, totalDiscardIOs, totalFlushIOs uint64
var totalReadMerges, totalWriteMerges, totalDiscardMerges uint64
var totalReadSectors, totalWriteSectors, totalDiscardSectors uint64
var totalReadTicks, totalWriteTicks, totalDiscardTicks, totalFlushTicks uint64
var totalTotalTicks uint64
var segmentCount int
for _, segment := range node.dailyStats.Segments {
totalReadIOs += segment.ReadIOs
totalWriteIOs += segment.WriteIOs
totalDiscardIOs += segment.DiscardIOs
totalFlushIOs += segment.FlushIOs
totalReadMerges += segment.ReadMerges
totalWriteMerges += segment.WriteMerges
totalDiscardMerges += segment.DiscardMerges
totalReadSectors += segment.ReadSectors
totalWriteSectors += segment.WriteSectors
totalDiscardSectors += segment.DiscardSectors
totalReadTicks += segment.ReadTicks
totalWriteTicks += segment.WriteTicks
totalDiscardTicks += segment.DiscardTicks
totalFlushTicks += segment.FlushTicks
totalTotalTicks += segment.TotalTicks
if segment.ReadIOs+segment.WriteIOs+segment.DiscardIOs+segment.FlushIOs > 0 {
segmentCount++
}
}
if segmentCount > 0 {
// Calculate total timeframe (all segments combined)
totalTimeframeSeconds := float64(len(node.dailyStats.Segments) * node.dailyStats.Interval)
// Estimate average number of drives (use segment count as approximation)
avgNumDrives := segmentCount
data["00:Info"] = fmt.Sprintf("Aggregated across %d time segments over %.0f seconds",
segmentCount, totalTimeframeSeconds)
// Format IO operation stats using the same formatIOStats function
formatIOStats(data, "Read", totalReadIOs, totalReadMerges, totalReadSectors,
totalReadTicks, avgNumDrives, totalTimeframeSeconds)
formatIOStats(data, "Write", totalWriteIOs, totalWriteMerges, totalWriteSectors,
totalWriteTicks, avgNumDrives, totalTimeframeSeconds)
formatIOStats(data, "Discard", totalDiscardIOs, totalDiscardMerges, totalDiscardSectors,
totalDiscardTicks, avgNumDrives, totalTimeframeSeconds)
formatIOStats(data, "Flush", totalFlushIOs, 0, 0,
totalFlushTicks, avgNumDrives, totalTimeframeSeconds)
// Add device utilization metrics
if totalTotalTicks > 0 {
utilPercent := float64(totalTotalTicks) / (totalTimeframeSeconds * 1000.0) * 100.0
avgUtilPerDrive := utilPercent / float64(avgNumDrives)
data["Device Utilization"] = fmt.Sprintf("%.1f%% total, %.1f%% avg per drive",
utilPercent, avgUtilPerDrive)
}
} else {
data["00:Info"] = "No IO activity recorded"
}
return data
}
// DiskCacheNode handles navigation for cache statistics
type DiskCacheNode struct {
cache *madmin.CacheStats
parent MetricNode
path string
}
func (node *DiskCacheNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskCacheNode(cache interface{}, parent MetricNode, path string) *DiskCacheNode {
if cacheStats, ok := cache.(*madmin.CacheStats); ok {
return &DiskCacheNode{cache: cacheStats, parent: parent, path: path}
}
return &DiskCacheNode{cache: nil, parent: parent, path: path}
}
func (node *DiskCacheNode) GetChildren() []MetricChild { return []MetricChild{} }
func (node *DiskCacheNode) GetLeafData() map[string]string {
if node.cache == nil {
return map[string]string{"Status": "Cache not available"}
}
data := map[string]string{}
// Cache Overview
data["Status"] = "Cache enabled"
if node.cache.N > 0 {
data["Cache nodes"] = strconv.Itoa(node.cache.N)
}
// Capacity and Usage
if node.cache.Capacity > 0 {
data["Total capacity"] = humanize.Bytes(uint64(node.cache.Capacity))
if node.cache.Used > 0 {
usagePercent := float64(node.cache.Used) / float64(node.cache.Capacity) * 100
data["Used space"] = fmt.Sprintf("%s (%.1f%%)", humanize.Bytes(uint64(node.cache.Used)), usagePercent)
freeSpace := node.cache.Capacity - node.cache.Used
data["Free space"] = humanize.Bytes(uint64(freeSpace))
} else {
data["Used space"] = "0 B (0.0%)"
data["Free space"] = humanize.Bytes(uint64(node.cache.Capacity))
}
}
// Hit/Miss Statistics
totalRequests := node.cache.Hits + node.cache.Misses
if totalRequests > 0 {
hitRate := float64(node.cache.Hits) / float64(totalRequests) * 100
data["Hit rate"] = fmt.Sprintf("%.1f%%", hitRate)
data["Total requests"] = humanize.Comma(totalRequests)
data["Cache hits"] = humanize.Comma(node.cache.Hits)
data["Cache misses"] = humanize.Comma(node.cache.Misses)
}
// Deletion Statistics
totalDeletes := node.cache.DelHits + node.cache.DelMisses
if totalDeletes > 0 {
delHitRate := float64(node.cache.DelHits) / float64(totalDeletes) * 100
data["Delete hit rate"] = fmt.Sprintf("%.1f%%", delHitRate)
data["Delete hits"] = humanize.Comma(node.cache.DelHits)
data["Delete misses"] = humanize.Comma(node.cache.DelMisses)
}
// Collision Information
if node.cache.Collisions > 0 {
data["Hash collisions"] = humanize.Comma(node.cache.Collisions)
}
return data
}
func (node *DiskCacheNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskCacheNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskCacheNode) GetParent() MetricNode { return node.parent }
func (node *DiskCacheNode) GetPath() string { return node.path }
func (node *DiskCacheNode) ShouldPauseRefresh() bool {
return false
}
func (node *DiskCacheNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("drive cache is a leaf node")
}
// DiskSMARTNode handles navigation for S.M.A.R.T. health information
type DiskSMARTNode struct {
smart *madmin.SMARTInfo
parent MetricNode
path string
}
func (node *DiskSMARTNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskSMARTNode(smart *madmin.SMARTInfo, parent MetricNode, path string) *DiskSMARTNode {
return &DiskSMARTNode{smart: smart, parent: parent, path: path}
}
func (node *DiskSMARTNode) GetChildren() []MetricChild { return []MetricChild{} }
func (node *DiskSMARTNode) GetLeafData() map[string]string {
if node.smart == nil {
return map[string]string{"Status": "No S.M.A.R.T. data available"}
}
data := map[string]string{}
if node.smart.DeviceType != "" {
data["Device Type"] = node.smart.DeviceType
}
if node.smart.ModelNumber != "" {
data["Model"] = node.smart.ModelNumber
}
if node.smart.SerialNumber != "" {
data["Serial Number"] = node.smart.SerialNumber
}
if node.smart.FirmwareRev != "" {
data["Firmware"] = node.smart.FirmwareRev
}
// Health Status Overview
if node.smart.N > 0 {
data["00:Drives"] = fmt.Sprintf("%d drives total", node.smart.N)
}
if len(node.smart.Status) > 0 {
// Create a slice of status entries for sorting
type statusEntry struct {
status string
count int
}
entries := make([]statusEntry, 0, len(node.smart.Status))
for status, count := range node.smart.Status {
entries = append(entries, statusEntry{status: status, count: count})
}
// Sort by count (descending), then by status name (ascending)
sort.Slice(entries, func(i, j int) bool {
if entries[i].count != entries[j].count {
return entries[i].count > entries[j].count // Descending by count
}
return entries[i].status < entries[j].status // Ascending by name
})
// Build status details
statusDetails := make([]string, 0, len(entries))
for _, entry := range entries {
if entry.count > 0 {
statusDetails = append(statusDetails, fmt.Sprintf("%d %s", entry.count, entry.status))
}
}
if len(statusDetails) > 0 {
data["01:Health Status"] = strings.Join(statusDetails, ", ")
}
}
// Common SMART Metrics (if we have stats)
if node.smart.StatsN > 0 {
data["02:Stats Available"] = fmt.Sprintf("Detailed stats from %d drives", node.smart.StatsN)
// Temperature
if node.smart.Temperature > 0 {
avgTemp := node.smart.Temperature / float64(node.smart.StatsN)
tempStr := ""
if node.smart.StatsN == 1 {
// For single drive, just show the temperature without "average"
tempStr = fmt.Sprintf("%.1f°C", avgTemp)
} else {
// For multiple drives, show average and max if available
tempStr = fmt.Sprintf("%.1f°C average", avgTemp)
if node.smart.MaxTemperature > 0 {
tempStr += fmt.Sprintf(", %.1f°C max", node.smart.MaxTemperature)
}
}
data["Temperature"] = tempStr
}
// Power-on hours
if node.smart.PowerOnHours > 0 {
avgHours := node.smart.PowerOnHours / float64(node.smart.StatsN)
// Convert to more readable units
avgDays := avgHours / 24
hoursStr := ""
// Format based on single vs multiple drives
avgLabel := ""
if node.smart.StatsN > 1 {
avgLabel = " average"
}
if avgDays > 365 {
years := avgDays / 365
hoursStr = fmt.Sprintf("%.1f years%s", years, avgLabel)
} else if avgDays > 30 {
months := avgDays / 30
hoursStr = fmt.Sprintf("%.1f months%s", months, avgLabel)
} else if avgDays > 1 {
hoursStr = fmt.Sprintf("%.1f days%s", avgDays, avgLabel)
} else {
hoursStr = fmt.Sprintf("%.1f hours%s", avgHours, avgLabel)
}
// Show max for multiple drives if available
if node.smart.StatsN > 1 && node.smart.MaxPowerOnHours > 0 {
maxDays := node.smart.MaxPowerOnHours / 24
if maxDays > 365 {
years := maxDays / 365
hoursStr += fmt.Sprintf(", %.1f years max", years)
} else if maxDays > 30 {
months := maxDays / 30
hoursStr += fmt.Sprintf(", %.1f months max", months)
} else if maxDays > 1 {
hoursStr += fmt.Sprintf(", %.1f days max", maxDays)
} else {
hoursStr += fmt.Sprintf(", %.1f hours max", node.smart.MaxPowerOnHours)
}
}
data["Power-On Time"] = hoursStr
}
// Power cycles
if node.smart.PowerCycles > 0 {
avgCycles := float64(node.smart.PowerCycles) / float64(node.smart.StatsN)
cyclesStr := ""
if node.smart.StatsN == 1 {
cyclesStr = fmt.Sprintf("%.0f", avgCycles)
} else {
cyclesStr = fmt.Sprintf("%.0f average", avgCycles)
if node.smart.MaxPowerCycles > 0 {
cyclesStr += fmt.Sprintf(", %d max", node.smart.MaxPowerCycles)
}
}
data["Power Cycles"] = cyclesStr
}
// Failure risk
if node.smart.FailureRisk > 0 {
avgRisk := (node.smart.FailureRisk / float64(node.smart.StatsN)) * 100
riskStr := ""
if node.smart.StatsN == 1 {
riskStr = fmt.Sprintf("%.2f%% annual failure rate", avgRisk)
} else {
riskStr = fmt.Sprintf("%.2f%% average annual failure rate", avgRisk)
if node.smart.MaxFailureRisk > 0 {
riskStr += fmt.Sprintf(", %.2f%% max", node.smart.MaxFailureRisk*100)
}
}
data["Failure Risk"] = riskStr
}
}
// NVMe-specific information
if node.smart.NVMe != nil && node.smart.NVMe.N > 0 {
nvme := node.smart.NVMe
data["10:NVMe Drives"] = fmt.Sprintf("%d NVMe drives with detailed stats", nvme.N)
// Critical warnings
if nvme.CriticalWarningFlags > 0 {
warnings := []string{}
if nvme.CriticalWarningFlags&0x01 != 0 {
warnings = append(warnings, "spare below threshold")
}
if nvme.CriticalWarningFlags&0x02 != 0 {
warnings = append(warnings, "temperature threshold exceeded")
}
if nvme.CriticalWarningFlags&0x04 != 0 {
warnings = append(warnings, "reliability degraded")
}
if nvme.CriticalWarningFlags&0x08 != 0 {
warnings = append(warnings, "read-only mode")
}
if nvme.CriticalWarningFlags&0x10 != 0 {
warnings = append(warnings, "volatile memory backup failed")
}
if nvme.CriticalWarningFlags&0x20 != 0 {
warnings = append(warnings, "persistent memory read-only")
}
if len(warnings) > 0 {
data["11:NVMe Critical Warnings"] = strings.Join(warnings, ", ")
}
}
// Available spare
if nvme.AvailableSpare > 0 || nvme.MinAvailableSpare > 0 {
avgSpare := float64(nvme.AvailableSpare) / float64(nvme.N)
spareStr := fmt.Sprintf("%.0f%% average", avgSpare)
if nvme.N > 1 && nvme.MinAvailableSpare > 0 {
spareStr += fmt.Sprintf(", %d%% min", nvme.MinAvailableSpare)
}
data["12:NVMe Available Spare"] = spareStr
}
// Percentage used (endurance)
if nvme.PercentageUsed > 0 || nvme.MaxPercentageUsed > 0 {
avgUsed := float64(nvme.PercentageUsed) / float64(nvme.N)
usedStr := fmt.Sprintf("%.0f%% average endurance used", avgUsed)
if nvme.N > 1 && nvme.MaxPercentageUsed > 0 {
usedStr += fmt.Sprintf(", %d%% max", nvme.MaxPercentageUsed)
}
data["13:NVMe Endurance"] = usedStr
}
// Media errors
if nvme.MediaErrors > 0 || nvme.MaxMediaErrors > 0 {
avgErrors := float64(nvme.MediaErrors) / float64(nvme.N)
errStr := fmt.Sprintf("%.0f average", avgErrors)
if nvme.N > 1 && nvme.MaxMediaErrors > 0 {
errStr += fmt.Sprintf(", %d max", nvme.MaxMediaErrors)
}
data["14:NVMe Media Errors"] = errStr
}
// Data units read/written (convert from 1000s of 512-byte units to readable size)
if nvme.DataUnitsRead > 0 || nvme.DataUnitsWritten > 0 {
// Each unit is 512KB (1000 * 512 bytes)
avgReadBytes := (nvme.DataUnitsRead / float64(nvme.N)) * 1000 * 512
avgWriteBytes := (nvme.DataUnitsWritten / float64(nvme.N)) * 1000 * 512
dataStr := fmt.Sprintf("Read: %s, Written: %s average",
humanize.Bytes(uint64(avgReadBytes)),
humanize.Bytes(uint64(avgWriteBytes)))
data["15:NVMe Data Transfer"] = dataStr
}
// Host operations
if nvme.HostReads > 0 || nvme.HostWrites > 0 {
avgReads := nvme.HostReads / float64(nvme.N)
avgWrites := nvme.HostWrites / float64(nvme.N)
opsStr := fmt.Sprintf("Reads: %.0f, Writes: %.0f average", avgReads, avgWrites)
data["16:NVMe Host Operations"] = opsStr
}
// Controller busy time
if nvme.CtrlBusyTime > 0 {
avgBusyMinutes := nvme.CtrlBusyTime / float64(nvme.N)
busyStr := ""
if avgBusyMinutes > 60*24 {
busyDays := avgBusyMinutes / (60 * 24)
busyStr = fmt.Sprintf("%.1f days average", busyDays)
} else if avgBusyMinutes > 60 {
busyHours := avgBusyMinutes / 60
busyStr = fmt.Sprintf("%.1f hours average", busyHours)
} else {
busyStr = fmt.Sprintf("%.1f minutes average", avgBusyMinutes)
}
data["17:NVMe Controller Busy"] = busyStr
}
// Unsafe shutdowns
if nvme.UnsafeShutdowns > 0 {
avgShutdowns := float64(nvme.UnsafeShutdowns) / float64(nvme.N)
shutStr := fmt.Sprintf("%.0f average", avgShutdowns)
if nvme.N > 1 && nvme.MaxUnsafeShutdowns > 0 {
shutStr += fmt.Sprintf(", %d max", nvme.MaxUnsafeShutdowns)
}
data["18:NVMe Unsafe Shutdowns"] = shutStr
}
// Temperature time warnings
if nvme.WarningTempTime > 0 || nvme.CritCompTime > 0 {
tempTimeStr := ""
if nvme.WarningTempTime > 0 {
avgWarnMinutes := nvme.WarningTempTime / float64(nvme.N)
if avgWarnMinutes > 60 {
tempTimeStr = fmt.Sprintf("Warning: %.1f hours", avgWarnMinutes/60)
} else {
tempTimeStr = fmt.Sprintf("Warning: %.1f minutes", avgWarnMinutes)
}
}
if nvme.CritCompTime > 0 {
avgCritMinutes := nvme.CritCompTime / float64(nvme.N)
if tempTimeStr != "" {
tempTimeStr += ", "
}
if avgCritMinutes > 60 {
tempTimeStr += fmt.Sprintf("Critical: %.1f hours", avgCritMinutes/60)
} else {
tempTimeStr += fmt.Sprintf("Critical: %.1f minutes", avgCritMinutes)
}
}
data["19:NVMe Temperature Time"] = tempTimeStr
}
}
// SATA-specific information
if node.smart.SATA != nil && node.smart.SATA.N > 0 {
sata := node.smart.SATA
data["20:SATA Drives"] = fmt.Sprintf("%d SATA drives with detailed stats", sata.N)
// Reallocated sectors
if sata.ReallocatedSectors > 0 || sata.MaxReallocatedSectors > 0 {
avgReallocated := float64(sata.ReallocatedSectors) / float64(sata.N)
reallocStr := fmt.Sprintf("%.0f average", avgReallocated)
if sata.N > 1 && sata.MaxReallocatedSectors > 0 {
reallocStr += fmt.Sprintf(", %d max", sata.MaxReallocatedSectors)
}
data["21:SATA Reallocated Sectors"] = reallocStr
}
// Pending sectors
if sata.PendingSectors > 0 || sata.MaxPendingSectors > 0 {
avgPending := float64(sata.PendingSectors) / float64(sata.N)
pendingStr := fmt.Sprintf("%.0f average", avgPending)
if sata.N > 1 && sata.MaxPendingSectors > 0 {
pendingStr += fmt.Sprintf(", %d max", sata.MaxPendingSectors)
}
data["22:SATA Pending Sectors"] = pendingStr
}
// Offline uncorrectable
if sata.OfflineUncorrectable > 0 || sata.MaxOfflineUncorrectable > 0 {
avgUncorrectable := float64(sata.OfflineUncorrectable) / float64(sata.N)
uncorrectableStr := fmt.Sprintf("%.0f average", avgUncorrectable)
if sata.N > 1 && sata.MaxOfflineUncorrectable > 0 {
uncorrectableStr += fmt.Sprintf(", %d max", sata.MaxOfflineUncorrectable)
}
data["23:SATA Offline Uncorrectable"] = uncorrectableStr
}
}
return data
}
func (node *DiskSMARTNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskSMARTNode) GetMetricFlags() madmin.MetricFlags { return madmin.MetricsSMART }
func (node *DiskSMARTNode) GetParent() MetricNode { return node.parent }
func (node *DiskSMARTNode) GetPath() string { return node.path }
func (node *DiskSMARTNode) ShouldPauseRefresh() bool {
return false
}
func (node *DiskSMARTNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("disk S.M.A.R.T. is a leaf node")
}
// DiskSummaryNode provides aggregated disk statistics
type DiskSummaryNode struct {
disk *madmin.DiskMetric
parent MetricNode
path string
}
func (node *DiskSummaryNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskSummaryNode(disk *madmin.DiskMetric, parent MetricNode, path string) *DiskSummaryNode {
return &DiskSummaryNode{disk: disk, parent: parent, path: path}
}
func (node *DiskSummaryNode) GetChildren() []MetricChild { return []MetricChild{} }
func (node *DiskSummaryNode) GetLeafData() map[string]string {
if node.disk == nil {
return map[string]string{"Error": "drive metrics not available"}
}
data := map[string]string{}
// Executive Summary Header
data["Drive Summary"] = fmt.Sprintf("Collected at %s",
node.disk.CollectedAt.Format("2006-01-02 15:04:05"))
// Cluster Health Overview
totalDisks := node.disk.NDisks
healthyDisks := totalDisks - node.disk.Offline - node.disk.Hanging - node.disk.Healing
if totalDisks > 0 {
healthPercent := float64(healthyDisks) / float64(totalDisks) * 100.0
var healthStatus string
switch {
case healthPercent >= 95:
healthStatus = "Excellent"
case healthPercent >= 85:
healthStatus = "Good"
case healthPercent >= 70:
healthStatus = "Warning"
default:
healthStatus = "Critical"
}
data["Cluster Health"] = fmt.Sprintf("%s - %d of %d drives healthy (%.1f%%)",
healthStatus, healthyDisks, totalDisks, healthPercent)
// Problem breakdown
var issues []string
if node.disk.Offline > 0 {
issues = append(issues, fmt.Sprintf("%d offline", node.disk.Offline))
}
if node.disk.Hanging > 0 {
issues = append(issues, fmt.Sprintf("%d hanging", node.disk.Hanging))
}
if node.disk.Healing > 0 {
issues = append(issues, fmt.Sprintf("%d healing", node.disk.Healing))
}
if len(issues) > 0 {
data["Issues"] = strings.Join(issues, ", ")
}
}
// Storage Capacity Analysis
if node.disk.Space.N > 0 {
totalCapacity := node.disk.Space.Free.Total + node.disk.Space.Used.Total
if totalCapacity > 0 {
usagePercent := float64(node.disk.Space.Used.Total) / float64(totalCapacity) * 100.0
var capacityStatus string
switch {
case usagePercent < 70:
capacityStatus = "Healthy"
case usagePercent < 85:
capacityStatus = "Monitor"
case usagePercent < 95:
capacityStatus = "Warning"
default:
capacityStatus = "Critical"
}
data["Storage Capacity"] = fmt.Sprintf("%s - %s used of %s total (%.1f%%)",
capacityStatus,
humanize.Bytes(node.disk.Space.Used.Total),
humanize.Bytes(totalCapacity),
usagePercent)
// Capacity distribution
if node.disk.Space.N > 1 {
data["Capacity Distribution"] = fmt.Sprintf("Range: %s to %s free across %d drives",
humanize.Bytes(node.disk.Space.Free.Min),
humanize.Bytes(node.disk.Space.Free.Max),
node.disk.Space.N)
}
// Inode status
totalInodes := node.disk.Space.UsedInodes.Total + node.disk.Space.FreeInodes.Total
if totalInodes > 0 {
inodePercent := float64(node.disk.Space.UsedInodes.Total) / float64(totalInodes) * 100.0
data["File System"] = fmt.Sprintf("%s inodes used of %s total (%.1f%%)",
humanize.Comma(int64(node.disk.Space.UsedInodes.Total)),
humanize.Comma(int64(totalInodes)),
inodePercent)
}
}
}
// Operational Activity Summary
totalOpTypes := len(node.disk.LifetimeOps) + len(node.disk.LastMinute)
if totalOpTypes > 0 {
data["Operations Tracked"] = fmt.Sprintf("%d operation types tracked", totalOpTypes)
}
if len(node.disk.LifetimeOps) > 0 {
data["Lifetime Operations"] = fmt.Sprintf("%d operation types with historical data",
len(node.disk.LifetimeOps))
}
if len(node.disk.LastMinute) > 0 {
data["Recent Activity"] = fmt.Sprintf("%d operation types active in last minute",
len(node.disk.LastMinute))
}
if len(node.disk.LastDaySegmented) > 0 {
data["Daily Trends"] = fmt.Sprintf("%d operation types with daily segmented data",
len(node.disk.LastDaySegmented))
}
// State Issues Detail
if len(node.disk.State) > 0 {
var totalStateIssues int
for _, count := range node.disk.State {
totalStateIssues += count
}
if totalStateIssues > 0 {
data["State Issues"] = fmt.Sprintf("%d drive state issues across %d categories",
totalStateIssues, len(node.disk.State))
}
}
// Available Features
var availableFeatures []string
if node.disk.HealingInfo != nil {
availableFeatures = append(availableFeatures, "active healing")
}
if node.disk.Cache != nil {
availableFeatures = append(availableFeatures, "cache statistics")
}
if node.disk.IOStats != nil {
availableFeatures = append(availableFeatures, "legacy IO metrics")
}
if len(availableFeatures) > 0 {
data["Additional Features"] = strings.Join(availableFeatures, ", ")
}
// Performance Indicators
if len(node.disk.LastMinute) > 0 {
data["Performance"] = "Real-time metrics available - navigate to IO stats for details"
}
return data
}
func (node *DiskSummaryNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskSummaryNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskSummaryNode) GetParent() MetricNode { return node.parent }
func (node *DiskSummaryNode) GetPath() string { return node.path }
func (node *DiskSummaryNode) ShouldPauseRefresh() bool {
return false
}
func (node *DiskSummaryNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("drive summary is a leaf node")
}
// DiskActionNode represents a leaf node with disk action details
type DiskActionNode struct {
actionType string
action *madmin.DiskAction
parent MetricNode
path string
}
func (node *DiskActionNode) GetOpts() madmin.MetricsOptions {
return getNodeOpts(node)
}
func NewDiskActionNode(actionType string, action *madmin.DiskAction, parent MetricNode, path string) *DiskActionNode {
return &DiskActionNode{actionType: actionType, action: action, parent: parent, path: path}
}
func (node *DiskActionNode) GetChildren() []MetricChild { return []MetricChild{} }
func (node *DiskActionNode) GetLeafData() map[string]string {
if node.action == nil {
return map[string]string{
"action_type": node.actionType,
"count": "0",
"bytes": "0",
"acc_time": "0",
"min_time": "0",
"max_time": "0",
}
}
return map[string]string{
"action_type": node.actionType,
"count": strconv.FormatUint(node.action.Count, 10),
"bytes": strconv.FormatUint(node.action.Bytes, 10),
"acc_time": fmt.Sprintf("%.2f", node.action.AccTime),
"min_time": fmt.Sprintf("%.2f", node.action.MinTime),
"max_time": fmt.Sprintf("%.2f", node.action.MaxTime),
}
}
func (node *DiskActionNode) GetMetricType() madmin.MetricType { return madmin.MetricsDisk }
func (node *DiskActionNode) GetMetricFlags() madmin.MetricFlags { return 0 }
func (node *DiskActionNode) GetParent() MetricNode { return node.parent }
func (node *DiskActionNode) GetPath() string { return node.path }
func (node *DiskActionNode) ShouldPauseRefresh() bool {
return false
}
func (node *DiskActionNode) GetChild(_ string) (MetricNode, error) {
return nil, fmt.Errorf("drive action is a leaf node")
}
// formatIOStats formats IO statistics for a specific operation type (Read/Write/Discard/Flush)
func formatIOStats(data map[string]string, opType string, ios, merges, sectors, ticks uint64, numDrives int, timeframeSeconds float64) {
if ios == 0 {
return // Skip operations with no activity
}
// Calculate rates per second
iosPerSec := float64(ios) / timeframeSeconds
avgIOsPerDrivePerSec := iosPerSec / float64(numDrives)
// Calculate sector sizes (512 bytes per sector)
totalBytes := sectors * 512
bytesPerSec := float64(totalBytes) / timeframeSeconds
avgBytesPerDrivePerSec := bytesPerSec / float64(numDrives)
// Calculate timing metrics
var avgServiceTime float64
if ios > 0 && ticks > 0 {
avgServiceTime = float64(ticks) / float64(ios) // Average milliseconds per IO
}
// Calculate merge efficiency
mergePercent := float64(merges) / float64(ios+merges) * 100.0
// Format the comprehensive statistics
statsLine := fmt.Sprintf("%s/sec", humanize.Comma(int64(iosPerSec)))
if avgIOsPerDrivePerSec > 0.01 { // Only show per-drive if meaningful
statsLine += fmt.Sprintf(" (%.1f/drive)", avgIOsPerDrivePerSec)
}
if totalBytes > 0 {
statsLine += fmt.Sprintf(", %s/sec", humanize.Bytes(uint64(bytesPerSec)))
if avgBytesPerDrivePerSec > 0 {
statsLine += fmt.Sprintf(" (%s/drive)", humanize.Bytes(uint64(avgBytesPerDrivePerSec)))
}
}
if avgServiceTime > 0 {
statsLine += fmt.Sprintf(", %.2fms avg service", avgServiceTime)
}
if merges > 0 {
statsLine += fmt.Sprintf(", %.1f%% merged", mergePercent)
}
data[opType+" Operations"] = statsLine
// Add totals for reference
totalLine := fmt.Sprintf("%s IOs", humanize.Comma(int64(ios)))
if totalBytes > 0 {
totalLine += fmt.Sprintf(", %s transferred", humanize.Bytes(totalBytes))
}
if merges > 0 {
totalLine += fmt.Sprintf(", %s merged", humanize.Comma(int64(merges)))
}
data[opType+" Totals"] = totalLine
}