make tag separate type
This commit is contained in:
parent
8a8b9893aa
commit
a872e72402
|
@ -6,6 +6,8 @@ Following is an example of send PagerDuty alerts based on "time_iowait" field
|
||||||
of the "cpu" metric. It will send PagerDyty alert any time the "time_iowait"
|
of the "cpu" metric. It will send PagerDyty alert any time the "time_iowait"
|
||||||
value is more than 50
|
value is more than 50
|
||||||
|
|
||||||
|
Optionally, alerts can be restriced to metrics with a given set of tags
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[[outputs.pagerduty]]
|
[[outputs.pagerduty]]
|
||||||
service_key = "<SERVICE KEY>"
|
service_key = "<SERVICE KEY>"
|
||||||
|
@ -13,4 +15,7 @@ value is more than 50
|
||||||
description = "Check CPU"
|
description = "Check CPU"
|
||||||
field = "time_iowait"
|
field = "time_iowait"
|
||||||
expression = "> 50.0"
|
expression = "> 50.0"
|
||||||
|
[[outputs.pagerduty.tags]]
|
||||||
|
name = "role"
|
||||||
|
value = "web"
|
||||||
```
|
```
|
||||||
|
|
|
@ -6,14 +6,19 @@ import (
|
||||||
"github.com/influxdata/telegraf/plugins/outputs"
|
"github.com/influxdata/telegraf/plugins/outputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Tag struct {
|
||||||
|
Name string `toml:"name"`
|
||||||
|
Value string `toml:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
type PD struct {
|
type PD struct {
|
||||||
ServiceKey string `toml:"service_key"`
|
ServiceKey string `toml:"service_key"`
|
||||||
Desc string `toml:"description"`
|
Desc string `toml:"description"`
|
||||||
Metric string `toml:"metric"`
|
Metric string `toml:"metric"`
|
||||||
Field string `toml:"field"`
|
Field string `toml:"field"`
|
||||||
Expression string `toml:"expression"`
|
Expression string `toml:"expression"`
|
||||||
TagFilter map[string]string `toml:"tag_filter"`
|
TagFilter []Tag `toml:"tags"`
|
||||||
incidentKey string `toml:"-"`
|
incidentKey string `toml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
|
@ -29,7 +34,6 @@ var sampleConfig = `
|
||||||
## will be considered for further processing
|
## will be considered for further processing
|
||||||
[[outputs.pagerduty.tag_filter]]
|
[[outputs.pagerduty.tag_filter]]
|
||||||
role = "web-server"
|
role = "web-server"
|
||||||
region = "us-west1"
|
|
||||||
## Expression is used to evaluate the alert
|
## Expression is used to evaluate the alert
|
||||||
expression = "> 50.0"
|
expression = "> 50.0"
|
||||||
`
|
`
|
||||||
|
@ -54,9 +58,9 @@ func (p *PD) isMatch(metric telegraf.Metric) bool {
|
||||||
if p.Metric != metric.Name() {
|
if p.Metric != metric.Name() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for k, v := range p.TagFilter {
|
for _, tag := range p.TagFilter {
|
||||||
t, ok := metric.Tags()[k]
|
v, ok := metric.Tags()[tag.Name]
|
||||||
if !ok || (t != v) {
|
if !ok || (v != tag.Value) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue