Skip to content

Commit 440f59f

Browse files
committed
filter param
1 parent 603535a commit 440f59f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bgcolor = "black"
6868
## URI Parameters
6969
* **g0.expr**, **g1.expr**, ..., **gN.expr** - prometheus queries
7070
* **g0.legend**, **g1.legend**, ..., **gN.legend** - custom legend [template](https://golang.org/pkg/text/template/). Tag values can be printed with {{.tagname}} instruction
71-
* **query** - alias for g0.expr
71+
* **gN.filter[labelName]=labelValue** - display only series with corresponding label values
7272
* **timeout** - optional custom query timeout
7373
* **pixelRatio** - device pixel ratio
7474
* **template** - template name from config

pkg/hander.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,18 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
206206
return
207207
}
208208

209+
SeriesLoop:
209210
for _, r := range promRes.Data.Result {
210211
if len(r.Values) < 1 {
211212
continue
212213
}
214+
// check filter
215+
for labelName, filterValue := range graphData.Filter {
216+
if labelValue, exists := r.Metric[labelName]; !exists || filterValue != labelValue {
217+
continue SeriesLoop
218+
}
219+
}
220+
213221
step := int64(1)
214222
if len(r.Values) > 1 {
215223
step = r.Values[1].Timestamp - r.Values[0].Timestamp

0 commit comments

Comments
 (0)