Browse Source

Merge pull request #1222 from rexzzw/chore/memory-humansize-iec

chore: convert disk and memory size by humanize.IBytes
Jacky 4 days ago
parent
commit
ad5ebc310e
2 changed files with 10 additions and 10 deletions
  1. 3 3
      internal/analytic/disk.go
  2. 7 7
      internal/analytic/memory.go

+ 3 - 3
internal/analytic/disk.go

@@ -45,9 +45,9 @@ func GetDiskStat() (DiskStat, error) {
 			Mountpoint: partition.Mountpoint,
 			Device:     partition.Device,
 			Fstype:     partition.Fstype,
-			Total:      humanize.Bytes(usage.Total),
-			Used:       humanize.Bytes(usage.Used),
-			Free:       humanize.Bytes(usage.Free),
+			Total:      humanize.IBytes(usage.Total),
+			Used:       humanize.IBytes(usage.Used),
+			Free:       humanize.IBytes(usage.Free),
 			Percentage: cast.ToFloat64(fmt.Sprintf("%.2f", usage.UsedPercent)),
 		}
 		partitionStats = append(partitionStats, partitionStat)

+ 7 - 7
internal/analytic/memory.go

@@ -16,13 +16,13 @@ func GetMemoryStat() (MemStat, error) {
 		return MemStat{}, errors.Wrap(err, "error analytic getMemoryStat")
 	}
 	return MemStat{
-		Total:      humanize.Bytes(memoryStat.Total),
-		Used:       humanize.Bytes(memoryStat.Used),
-		Cached:     humanize.Bytes(memoryStat.Cached),
-		Free:       humanize.Bytes(memoryStat.Free),
-		SwapUsed:   humanize.Bytes(memoryStat.SwapTotal - memoryStat.SwapFree),
-		SwapTotal:  humanize.Bytes(memoryStat.SwapTotal),
-		SwapCached: humanize.Bytes(memoryStat.SwapCached),
+		Total:      humanize.IBytes(memoryStat.Total),
+		Used:       humanize.IBytes(memoryStat.Used),
+		Cached:     humanize.IBytes(memoryStat.Cached),
+		Free:       humanize.IBytes(memoryStat.Free),
+		SwapUsed:   humanize.IBytes(memoryStat.SwapTotal - memoryStat.SwapFree),
+		SwapTotal:  humanize.IBytes(memoryStat.SwapTotal),
+		SwapCached: humanize.IBytes(memoryStat.SwapCached),
 		SwapPercent: cast.ToFloat64(fmt.Sprintf("%.2f",
 			100*float64(memoryStat.SwapTotal-memoryStat.SwapFree)/math.Max(float64(memoryStat.SwapTotal), 1))),
 		Pressure: cast.ToFloat64(fmt.Sprintf("%.2f", memoryStat.UsedPercent)),