summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: becb1cb)
raw | patch | inline | side by side (parent: becb1cb)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 14 May 2015 16:56:40 +0000 (18:56 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 14 May 2015 17:10:08 +0000 (19:10 +0200) |
server/query.go | patch | blob | history | |
templates/graphs.tmpl | patch | blob | history |
diff --git a/server/query.go b/server/query.go
index 22385bf07de13e576e03007b179ede5fd6e97000..ad645bd1dbf139887de5f86a8e26bb5af1556b96 100644 (file)
--- a/server/query.go
+++ b/server/query.go
p := struct {
Query, Metrics string
QueryOptions string
- GroupBy string
+ GroupBy []string
+ Attributes map[string]bool
}{
Query: req.r.PostForm.Get("metrics-query"),
- GroupBy: req.r.PostForm.Get("group-by"),
+ GroupBy: req.r.PostForm["group-by"],
}
if req.r.Method == "POST" {
p.Metrics = p.Query
- if p.GroupBy != "" {
- p.QueryOptions += "/g=" + strings.Join(strings.Fields(p.GroupBy), ",")
+ if len(p.GroupBy) > 0 {
+ p.QueryOptions += "/g=" + strings.Join(p.GroupBy, ",")
+ }
+
+ metrics, err := s.queryMetrics(p.Query)
+ if err != nil {
+ return nil, err
+ }
+ p.Attributes = make(map[string]bool)
+ for _, m := range metrics {
+ for a := range m.Attributes {
+ var checked bool
+ for _, g := range p.GroupBy {
+ if a == g {
+ checked = true
+ break
+ }
+ }
+ p.Attributes[a] = checked
+ }
}
}
return tmpl(s.results["graphs"], &p)
diff --git a/templates/graphs.tmpl b/templates/graphs.tmpl
index 10cd23807a3b34a0e7a05ad286804193b346e2dd..5c8b4907904f0740b123334db7ad398229c3e839 100644 (file)
--- a/templates/graphs.tmpl
+++ b/templates/graphs.tmpl
<section>
<h1>Graphs</h1>
<form action="/graphs" method="POST">
- <input type="text" name="metrics-query" value="{{.Query}}"
+ <p><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" />
+ <button type="submit">GO</button></p>
+{{if .Attributes}}
+ <p><b>Group by:</b>
+ {{range $a, $v := .Attributes}}
+ <input type="checkbox" name="group-by" value="{{$a}}" {{if $v}}checked{{end}} />{{$a}}
+ {{end}}
+ </p>
+{{end}}
</form><br />
{{if .Metrics}}
<img src="/graph/q{{urlquery .QueryOptions}}/{{urlquery .Metrics}}" border="0" />