Browse Source

Memory stat fixed

master
Felix 3 years ago
parent
commit
06cee625ca
  1. 7
      ganglia.go

7
ganglia.go

@ -73,13 +73,14 @@ func HostRow(host Host) string {
mem := -1.0
if mem_tot > 0 && mem_free > 0 {
mem = mem_tot/mem_free
mem_used := mem_tot - mem_free
mem = mem_used/mem_tot
}
then := time.Unix(host.Time, 0) // In UTC
time := then.Format("2006-01-02-15:04:05")
return fmt.Sprintf("%20s\t%15s\t%20s%5.0f %%\t%5.1f %%\t%5.1f %5.1f %5.1f", host.Name, host.Ip, time, cpu, mem, load1, load5, load15)
return fmt.Sprintf("%25s\t%15s\t%20s%5.0f %%\t%5.1f %%\t%5.1f %5.1f %5.1f", host.Name, host.Ip, time, cpu, mem*100.0, load1, load5, load15)
}
func readStream(reader io.Reader) ([]byte, error) {
@ -148,7 +149,7 @@ func main() {
sort.Slice(hosts, func(i, j int) bool { return strings.Compare(hosts[i].Name, hosts[j].Name) < 0 })
// Header
fmt.Printf("%20s\t%15s\t%20s%7s\t%7s\t%17s\n", "Host", "Ip", "Last Update", "CPU", "Memory", "Load (1-5-15)")
fmt.Printf("%25s\t%15s\t%20s%7s\t%7s\t%17s\n", "Host", "Ip", "Last Update", "CPU", "Memory", "Load (1-5-15)")
for _, host := range hosts {
fmt.Printf("%s\n", HostRow(host))
}

Loading…
Cancel
Save