Modify ShouldPass so that it checks the tags of a metric, if configured.
A plugin can have 'tagpass' and 'tagdrop' subsections: [disk.tagpass] And tagname = array lists of things to filter by: fstype = [ "ext4", "xfs" ] path = [ "/", /opt", "/home" ] [disk.tagdrop] path = [ "/" ]
This commit is contained in:
parent
3192d2c983
commit
954ed7981e
76
config.go
76
config.go
|
@ -51,18 +51,28 @@ func (c *Config) Plugins() map[string]*ast.Table {
|
||||||
return c.plugins
|
return c.plugins
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The name of a tag, and the values on which to filter
|
||||||
|
type TagFilter struct {
|
||||||
|
Name string
|
||||||
|
Filter []string
|
||||||
|
}
|
||||||
|
|
||||||
// ConfiguredPlugin containing a name, interval, and drop/pass prefix lists
|
// ConfiguredPlugin containing a name, interval, and drop/pass prefix lists
|
||||||
|
// Also lists the tags to filter
|
||||||
type ConfiguredPlugin struct {
|
type ConfiguredPlugin struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
Drop []string
|
Drop []string
|
||||||
Pass []string
|
Pass []string
|
||||||
|
|
||||||
|
TagDrop []TagFilter
|
||||||
|
TagPass []TagFilter
|
||||||
|
|
||||||
Interval time.Duration
|
Interval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShouldPass returns true if the metric should pass, false if should drop
|
// ShouldPass returns true if the metric should pass, false if should drop
|
||||||
func (cp *ConfiguredPlugin) ShouldPass(measurement string) bool {
|
func (cp *ConfiguredPlugin) ShouldPass(measurement string, tags map[string]string) bool {
|
||||||
if cp.Pass != nil {
|
if cp.Pass != nil {
|
||||||
for _, pat := range cp.Pass {
|
for _, pat := range cp.Pass {
|
||||||
if strings.HasPrefix(measurement, pat) {
|
if strings.HasPrefix(measurement, pat) {
|
||||||
|
@ -83,6 +93,32 @@ func (cp *ConfiguredPlugin) ShouldPass(measurement string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cp.TagPass != nil {
|
||||||
|
for _, pat := range cp.TagPass {
|
||||||
|
if tagval, ok := tags[pat.Name]; ok {
|
||||||
|
for _, filter := range pat.Filter {
|
||||||
|
if filter == tagval {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if cp.TagDrop != nil {
|
||||||
|
for _, pat := range cp.TagDrop {
|
||||||
|
if tagval, ok := tags[pat.Name]; ok {
|
||||||
|
for _, filter := range pat.Filter {
|
||||||
|
if filter == tagval {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,9 +176,47 @@ func (c *Config) ApplyPlugin(name string, v interface{}) (*ConfiguredPlugin, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if node, ok := tbl.Fields["tagpass"]; ok {
|
||||||
|
if subtbl, ok := node.(*ast.Table); ok {
|
||||||
|
for name, val := range subtbl.Fields {
|
||||||
|
if kv, ok := val.(*ast.KeyValue); ok {
|
||||||
|
tagfilter := &TagFilter{Name: name}
|
||||||
|
if ary, ok := kv.Value.(*ast.Array); ok {
|
||||||
|
for _, elem := range ary.Value {
|
||||||
|
if str, ok := elem.(*ast.String); ok {
|
||||||
|
tagfilter.Filter = append(tagfilter.Filter, str.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cp.TagPass = append(cp.TagPass, *tagfilter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if node, ok := tbl.Fields["tagdrop"]; ok {
|
||||||
|
if subtbl, ok := node.(*ast.Table); ok {
|
||||||
|
for name, val := range subtbl.Fields {
|
||||||
|
if kv, ok := val.(*ast.KeyValue); ok {
|
||||||
|
tagfilter := &TagFilter{Name: name}
|
||||||
|
if ary, ok := kv.Value.(*ast.Array); ok {
|
||||||
|
for _, elem := range ary.Value {
|
||||||
|
if str, ok := elem.(*ast.String); ok {
|
||||||
|
tagfilter.Filter = append(tagfilter.Filter, str.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cp.TagDrop = append(cp.TagDrop, *tagfilter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete(tbl.Fields, "drop")
|
delete(tbl.Fields, "drop")
|
||||||
delete(tbl.Fields, "pass")
|
delete(tbl.Fields, "pass")
|
||||||
delete(tbl.Fields, "interval")
|
delete(tbl.Fields, "interval")
|
||||||
|
delete(tbl.Fields, "tagdrop")
|
||||||
|
delete(tbl.Fields, "tagpass")
|
||||||
return cp, toml.UnmarshalTable(tbl, v)
|
return cp, toml.UnmarshalTable(tbl, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue