From: Sebastian Harl Date: Wed, 13 May 2015 20:34:43 +0000 (+0200) Subject: graph: Introduce a new type representing a metric. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=35c9956996c736aa0465c524358455643299c373;p=sysdb%2Fwebui.git graph: Introduce a new type representing a metric. The new type allows to add further information to a metric. --- diff --git a/graph/graph.go b/graph/graph.go index cb1852c..7985dc4 100644 --- a/graph/graph.go +++ b/graph/graph.go @@ -38,13 +38,22 @@ import ( "github.com/sysdb/go/sysdb" ) -// A Graph represents a single graph. It may reference multiple time-series. +// A Metric represents a single data-source of a graph. +type Metric struct { + // The unique identifier of the metric. + Hostname, Identifier string + + // Attributes describing details of the metric. + Attributes map[string]string +} + +// A Graph represents a single graph. It may reference multiple data-sources. type Graph struct { // Time range of the graph. Start, End time.Time - // Metrics: {, } - Metrics [][2]string + // Content of the graph. + Metrics []Metric } type pl struct { @@ -53,8 +62,9 @@ type pl struct { ts int // Index of the current time-series. } -func (p *pl) addTimeseries(c *client.Client, metric [2]string, start, end time.Time) error { - q, err := client.QueryString("TIMESERIES %s.%s START %s END %s", metric[0], metric[1], start, end) +func (p *pl) addTimeseries(c *client.Client, metric Metric, start, end time.Time) error { + q, err := client.QueryString("TIMESERIES %s.%s START %s END %s", + metric.Hostname, metric.Identifier, start, end) if err != nil { return fmt.Errorf("Failed to retrieve graph data: %v", err) } diff --git a/server/graph.go b/server/graph.go index 9c679bc..7509485 100644 --- a/server/graph.go +++ b/server/graph.go @@ -64,7 +64,7 @@ func (s *Server) graph(w http.ResponseWriter, req request) { g := &graph.Graph{ Start: start, End: end, - Metrics: [][2]string{{req.args[0], req.args[1]}}, + Metrics: []graph.Metric{{Hostname: req.args[0], Identifier: req.args[1]}}, } p, err := g.Plot(s.c) if err != nil {