From 879651a4ea68507dcf9d8a8b59f71fda6df0921b Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Tue, 8 Aug 2017 12:33:59 -0700 Subject: [PATCH] Update api structs for metrics endpoint --- api/agent.go | 35 +++++++++++++++++++++++++++++++---- api/agent_test.go | 3 +-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/api/agent.go b/api/agent.go index 2f43d8eda..fe82ab2b3 100644 --- a/api/agent.go +++ b/api/agent.go @@ -99,10 +99,37 @@ type AgentToken struct { // Metrics info is used to store different types of metric values from the agent. type MetricsInfo struct { Timestamp string - Gauges []map[string]interface{} - Points []map[string]interface{} - Counters []map[string]interface{} - Samples []map[string]interface{} + Gauges []GaugeValue + Points []PointValue + Counters []SampledValue + Samples []SampledValue +} + +// GaugeValue stores one value that is updated as time goes on, such as +// the amount of memory allocated. +type GaugeValue struct { + Name string + Value float32 + Labels map[string]string +} + +// PointValue holds a series of points for a metric. +type PointValue struct { + Name string + Points []float32 +} + +// SampledValue stores info about a metric that is incremented over time, +// such as the number of requests to an HTTP endpoint. +type SampledValue struct { + Name string + Count int + Sum float64 + Min float64 + Max float64 + Mean float64 + Stddev float64 + Labels map[string]string } // Agent can be used to query the Agent endpoints diff --git a/api/agent_test.go b/api/agent_test.go index 1b2cf2cba..7cdc2f255 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -44,8 +44,7 @@ func TestAPI_AgentMetrics(t *testing.T) { t.Fatalf("bad: %v", metrics) } - name := metrics.Gauges[0]["Name"] - if name != "consul.runtime.alloc_bytes" { + if metrics.Gauges[0].Name != "consul.runtime.alloc_bytes" { t.Fatalf("bad: %v", metrics.Gauges[0]) } }