This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
/
stat_filter.go
71 lines (59 loc) · 1.74 KB
/
stat_filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/***** BEGIN LICENSE BLOCK *****
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# The Initial Developer of the Original Code is the Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2012
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Ben Bangert (bbangert@mozilla.com)
# Mike Trinkala (trink@mozilla.com)
#
# ***** END LICENSE BLOCK *****/
package pipeline
type metric struct {
Type_ string `json:"type"`
Name string
Value string
}
type StatFilterConfig struct {
Metric []metric
}
type StatFilter struct {
metrics []metric
}
func (s *StatFilter) ConfigStruct() interface{} {
return new(StatFilterConfig)
}
func (s *StatFilter) Init(config interface{}) (err error) {
conf := config.(*StatFilterConfig)
s.metrics = conf.Metric
return
}
func (s *StatFilter) Run(fr FilterRunner, h PluginHelper) (err error) {
inChan := fr.InChan()
var (
pack *PipelinePack
captures map[string]string
)
for plc := range inChan {
pack = plc.Pack
captures = plc.Captures
// Load existing fields into the set for replacement
captures["Logger"] = pack.Message.GetLogger()
captures["Hostname"] = pack.Message.GetHostname()
captures["Type"] = pack.Message.GetType()
captures["Payload"] = pack.Message.GetPayload()
// We matched, generate appropriate metrics
for _, met := range s.metrics {
pack := MessageGenerator.Retrieve()
pack.Message.SetType(met.Type_)
pack.Message.SetLogger(InterpolateString(met.Name, captures))
pack.Message.SetPayload(InterpolateString(met.Value, captures))
MessageGenerator.Inject(pack)
}
}
return
}