diff --git a/render/metrics.go b/render/metrics.go index 362faa0580..ce1ba7ba27 100644 --- a/render/metrics.go +++ b/render/metrics.go @@ -20,6 +20,7 @@ type MetricRow struct { ID string `json:"id"` Label string `json:"label"` Format string `json:"format,omitempty"` + Group string `json:"group,omitempty"` Value float64 `json:"value"` *report.Metric } @@ -46,6 +47,9 @@ func (m MetricRow) MarshalJSON() ([]byte, error) { if m.Format != "" { j["format"] = m.Format } + if m.Group != "" { + j["group"] = m.Group + } return json.Marshal(j) } @@ -56,7 +60,7 @@ func renderTime(t time.Time) string { return t.Format(time.RFC3339Nano) } -func metricRow(id, label string, metric report.Metric, format string) MetricRow { +func metricRow(id, label string, metric report.Metric, format, group string) MetricRow { var last float64 if s := metric.LastSample(); s != nil { last = s.Value @@ -65,6 +69,7 @@ func metricRow(id, label string, metric report.Metric, format string) MetricRow ID: id, Label: label, Format: format, + Group: group, Value: toFixed(last, 2), Metric: &metric, } @@ -102,6 +107,7 @@ func containerNodeMetrics(nmd report.Node) []MetricRow { "Memory Usage", val, filesizeFormat, + "", )) } if val, ok := nmd.Metrics[docker.CPUTotalUsage]; ok { @@ -110,6 +116,7 @@ func containerNodeMetrics(nmd report.Node) []MetricRow { "CPU Usage", val, percentFormat, + "", )) } return rows @@ -130,6 +137,14 @@ func hostNodeMetrics(nmd report.Node) []MetricRow { } rows := []MetricRow{} + for _, tuple := range []struct{ ID, Label, fmt string }{ + {host.CPUUsage, "CPU Usage", percentFormat}, + {host.MemUsage, "Memory Usage", percentFormat}, + } { + if val, ok := nmd.Metrics[tuple.ID]; ok { + rows = append(rows, metricRow(tuple.ID, tuple.Label, val, tuple.fmt, "")) + } + } for _, tuple := range []struct{ ID, Label string }{ {host.Load1, "Load (1m)"}, {host.Load5, "Load (5m)"}, @@ -137,15 +152,7 @@ func hostNodeMetrics(nmd report.Node) []MetricRow { } { if val, ok := nmd.Metrics[tuple.ID]; ok { val.Max = maxLoad - rows = append(rows, metricRow(tuple.ID, tuple.Label, val, defaultFormat)) - } - } - for _, tuple := range []struct{ ID, Label, fmt string }{ - {host.CPUUsage, "CPU Usage", percentFormat}, - {host.MemUsage, "Memory Usage", percentFormat}, - } { - if val, ok := nmd.Metrics[tuple.ID]; ok { - rows = append(rows, metricRow(tuple.ID, tuple.Label, val, tuple.fmt)) + rows = append(rows, metricRow(tuple.ID, tuple.Label, val, defaultFormat, "load")) } } return rows