Skip to content

Commit

Permalink
filter param
Browse files Browse the repository at this point in the history
  • Loading branch information
lomik committed Dec 5, 2018
1 parent 603535a commit 440f59f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bgcolor = "black"
## URI Parameters
* **g0.expr**, **g1.expr**, ..., **gN.expr** - prometheus queries
* **g0.legend**, **g1.legend**, ..., **gN.legend** - custom legend [template](https://golang.org/pkg/text/template/). Tag values can be printed with {{.tagname}} instruction
* **query** - alias for g0.expr
* **gN.filter[labelName]=labelValue** - display only series with corresponding label values
* **timeout** - optional custom query timeout
* **pixelRatio** - device pixel ratio
* **template** - template name from config
Expand Down
8 changes: 8 additions & 0 deletions pkg/hander.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,18 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

SeriesLoop:
for _, r := range promRes.Data.Result {
if len(r.Values) < 1 {
continue
}
// check filter
for labelName, filterValue := range graphData.Filter {
if labelValue, exists := r.Metric[labelName]; !exists || filterValue != labelValue {
continue SeriesLoop
}
}

step := int64(1)
if len(r.Values) > 1 {
step = r.Values[1].Timestamp - r.Values[0].Timestamp
Expand Down

0 comments on commit 440f59f

Please sign in to comment.