summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 479e609)
raw | patch | inline | side by side (parent: 479e609)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 14 May 2015 12:29:25 +0000 (14:29 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 14 May 2015 12:29:25 +0000 (14:29 +0200) |
server/graph.go | patch | blob | history | |
server/query.go | patch | blob | history | |
static/style/main.css | patch | blob | history | |
templates/graphs.tmpl | patch | blob | history |
diff --git a/server/graph.go b/server/graph.go
index ddc8c4d17e5f6aec59531fbcf2a5e4f33b50c852..badf28f2be9e01758892d1f6b9f171b8c86c619a 100644 (file)
--- a/server/graph.go
+++ b/server/graph.go
"fmt"
"io"
"net/http"
+ "strings"
"time"
"github.com/gonum/plot/vg"
Start: start,
End: end,
}
- if req.args[0] == "q" {
+ if req.args[0] == "q" || len(req.args[0]) > 1 && req.args[0][:2] == "q/" {
if g.Metrics, err = s.queryMetrics(req.args[1]); err != nil {
s.badrequest(w, fmt.Errorf("Failed to query metrics: %v", err))
return
}
+
+ if req.args[0] != "q" {
+ for _, arg := range strings.Split(req.args[0][2:], "/") {
+ if arg := strings.SplitN(arg, "=", 2); len(arg) == 2 {
+ if arg[0] == "g" {
+ g.GroupBy = strings.Split(arg[1], ",")
+ }
+ }
+ }
+ }
} else {
g.Metrics = []graph.Metric{{Hostname: req.args[0], Identifier: req.args[1]}}
}
var metrics []graph.Metric
for _, h := range hosts {
for _, m := range h.Metrics {
- metrics = append(metrics, graph.Metric{Hostname: h.Name, Identifier: m.Name})
+ metric := graph.Metric{
+ Hostname: h.Name,
+ Identifier: m.Name,
+ Attributes: make(map[string]string),
+ }
+ for _, attr := range m.Attributes {
+ metric.Attributes[attr.Name] = attr.Value
+ }
+ metrics = append(metrics, metric)
}
}
return metrics, nil
diff --git a/server/query.go b/server/query.go
index bde450fef97dc74911e4aa516b859a3dba85afe7..22385bf07de13e576e03007b179ede5fd6e97000 100644 (file)
--- a/server/query.go
+++ b/server/query.go
func graphs(req request, s *Server) (*page, error) {
p := struct {
Query, Metrics string
+ QueryOptions string
+ GroupBy string
}{
- Query: req.r.PostForm.Get("metrics-query"),
+ Query: req.r.PostForm.Get("metrics-query"),
+ GroupBy: req.r.PostForm.Get("group-by"),
}
if req.r.Method == "POST" {
p.Metrics = p.Query
+ if p.GroupBy != "" {
+ p.QueryOptions += "/g=" + strings.Join(strings.Fields(p.GroupBy), ",")
+ }
}
return tmpl(s.results["graphs"], &p)
}
diff --git a/static/style/main.css b/static/style/main.css
index 1bcae8641f89521ca6ba6c8693e29c0ca17918fc..00ec0897ff5ae02a4e9a88b0b1001d6312202e99 100644 (file)
--- a/static/style/main.css
+++ b/static/style/main.css
height: 25px;
border: 1px solid #000;
padding: 0px 3px;
+ margin: 3px;
}
button {
diff --git a/templates/graphs.tmpl b/templates/graphs.tmpl
index 43ec6226bb69868221c0f620dd0d19c3adb05023..6a1320128d0bc15a3557d39184bc034404e7631a 100644 (file)
--- a/templates/graphs.tmpl
+++ b/templates/graphs.tmpl
<input type="text" name="metrics-query" value="{{.Query}}"
class="query" placeholder="Search metrics" required />
<button type="submit">GO</button>
+ <br />
+ <input type="text" name="group-by" value="{{.GroupBy}}"
+ class="query" placeholder="Group by" />
</form><br />
{{if .Metrics}}
- <img src="/graph/q/{{.Metrics}}" border="0" />
+ <img src="/graph/q{{urlquery .QueryOptions}}/{{.Metrics}}" border="0" />
{{end}}
<p> </p>
</section>