Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed Nov 9, 2015
1 parent 48f6b03 commit 34e9873
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions render/detailed_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,21 @@ func processOriginTable(nmd report.Node, addHostTag bool, addContainerTag bool)
}, len(rows) > 0 || commFound || pidFound
}

func sparklineRow(human, format string, scale float64, metric report.Metric) Row {
func sparklineRow(human string, metric report.Metric, format func(*report.Sample) string) Row {
if format == nil {
format = formatDefault
}
lastStr := ""
if last := metric.LastSample(); last != nil {
lastStr = fmt.Sprintf(format, last.Value/scale)
lastStr = format(last)
}
return Row{Key: human, ValueMajor: lastStr, Metric: metric, ValueType: "sparkline"}
}

func formatDefault(s *report.Sample) string { return fmt.Sprintf("%0.2f", s.Value) }
func formatMB(s *report.Sample) string { return fmt.Sprintf("%0.2f MB", s.Value/1024*1024) }
func formatPercent(s *report.Sample) string { return fmt.Sprintf("%0.2f%%", s.Value) }

func containerOriginTable(nmd report.Node, addHostTag bool) (Table, bool) {
rows := []Row{}
for _, tuple := range []struct{ key, human string }{
Expand All @@ -337,10 +344,10 @@ func containerOriginTable(nmd report.Node, addHostTag bool) (Table, bool) {
}

if val, ok := nmd.Metrics[docker.MemoryUsage]; ok {
rows = append(rows, sparklineRow("Memory Usage", "%0.2f MB", 1024*1024, val))
rows = append(rows, sparklineRow("Memory Usage", val, formatMB))
}
if val, ok := nmd.Metrics[docker.CPUTotalUsage]; ok {
rows = append(rows, sparklineRow("CPU Usage", "%0.2f%%", 1, val))
rows = append(rows, sparklineRow("CPU Usage", val, formatPercent))
}

var (
Expand Down Expand Up @@ -430,7 +437,7 @@ func hostOriginTable(nmd report.Node) (Table, bool) {
val.Max = maxLoad
val.First = lastLoad.Add(-15 * time.Second) // TODO(paulbellamy): This should be based on the duration flag, maybe? or just auto-scale to data.
val.Last = lastLoad
rows = append(rows, sparklineRow(tuple.human, "%0.2f", 1, val))
rows = append(rows, sparklineRow(tuple.human, val, nil))
}
}
for _, tuple := range []struct{ key, human string }{
Expand Down

0 comments on commit 34e9873

Please sign in to comment.