send metric tags as riemann tags
allow sending measurement name as tag Signed-off-by: Fabio Berchtold <fabio.berchtold@swisscom.com>
This commit is contained in:
parent
ce5054c850
commit
747f39a7da
2
Godeps
2
Godeps
|
@ -1,7 +1,7 @@
|
||||||
github.com/Shopify/sarama 8aadb476e66ca998f2f6bb3c993e9a2daa3666b9
|
github.com/Shopify/sarama 8aadb476e66ca998f2f6bb3c993e9a2daa3666b9
|
||||||
github.com/Sirupsen/logrus 219c8cb75c258c552e999735be6df753ffc7afdc
|
github.com/Sirupsen/logrus 219c8cb75c258c552e999735be6df753ffc7afdc
|
||||||
github.com/aerospike/aerospike-client-go 7f3a312c3b2a60ac083ec6da296091c52c795c63
|
github.com/aerospike/aerospike-client-go 7f3a312c3b2a60ac083ec6da296091c52c795c63
|
||||||
github.com/amir/raidman 53c1b967405155bfc8758557863bf2e14f814687
|
github.com/amir/raidman c74861fe6a7bb8ede0a010ce4485bdbb4fc4c985
|
||||||
github.com/aws/aws-sdk-go 13a12060f716145019378a10e2806c174356b857
|
github.com/aws/aws-sdk-go 13a12060f716145019378a10e2806c174356b857
|
||||||
github.com/beorn7/perks 3ac7bf7a47d159a033b107610db8a1b6575507a4
|
github.com/beorn7/perks 3ac7bf7a47d159a033b107610db8a1b6575507a4
|
||||||
github.com/cenkalti/backoff 4dc77674aceaabba2c7e3da25d4c823edfb73f99
|
github.com/cenkalti/backoff 4dc77674aceaabba2c7e3da25d4c823edfb73f99
|
||||||
|
|
|
@ -436,8 +436,10 @@
|
||||||
# url = "localhost:5555"
|
# url = "localhost:5555"
|
||||||
# ## transport protocol to use either tcp or udp
|
# ## transport protocol to use either tcp or udp
|
||||||
# transport = "tcp"
|
# transport = "tcp"
|
||||||
# ## separator to use between input name and field name in Riemann service name
|
# ## separator to use between measurement name and field name in Riemann service name
|
||||||
# separator = " "
|
# separator = " "
|
||||||
|
# ## set measurement name as a Riemann tag instead of prepending it to the Riemann service name
|
||||||
|
# measurement_as_tag = false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ type Riemann struct {
|
||||||
URL string
|
URL string
|
||||||
Transport string
|
Transport string
|
||||||
Separator string
|
Separator string
|
||||||
|
MeasurementAsTag bool
|
||||||
|
|
||||||
client *raidman.Client
|
client *raidman.Client
|
||||||
}
|
}
|
||||||
|
@ -24,8 +25,10 @@ var sampleConfig = `
|
||||||
url = "localhost:5555"
|
url = "localhost:5555"
|
||||||
## transport protocol to use either tcp or udp
|
## transport protocol to use either tcp or udp
|
||||||
transport = "tcp"
|
transport = "tcp"
|
||||||
## separator to use between input name and field name in Riemann service name
|
## separator to use between measurement name and field name in Riemann service name
|
||||||
separator = " "
|
separator = " "
|
||||||
|
## set measurement name as a Riemann tag instead of prepending it to the Riemann service name
|
||||||
|
measurement_as_tag = false
|
||||||
`
|
`
|
||||||
|
|
||||||
func (r *Riemann) Connect() error {
|
func (r *Riemann) Connect() error {
|
||||||
|
@ -71,7 +74,7 @@ func (r *Riemann) Write(metrics []telegraf.Metric) error {
|
||||||
|
|
||||||
var events []*raidman.Event
|
var events []*raidman.Event
|
||||||
for _, p := range metrics {
|
for _, p := range metrics {
|
||||||
evs := buildEvents(p, r.Separator)
|
evs := r.buildEvents(p)
|
||||||
for _, ev := range evs {
|
for _, ev := range evs {
|
||||||
events = append(events, ev)
|
events = append(events, ev)
|
||||||
}
|
}
|
||||||
|
@ -87,7 +90,7 @@ func (r *Riemann) Write(metrics []telegraf.Metric) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildEvents(p telegraf.Metric, s string) []*raidman.Event {
|
func (r *Riemann) buildEvents(p telegraf.Metric) []*raidman.Event {
|
||||||
events := []*raidman.Event{}
|
events := []*raidman.Event{}
|
||||||
for fieldName, value := range p.Fields() {
|
for fieldName, value := range p.Fields() {
|
||||||
host, ok := p.Tags()["host"]
|
host, ok := p.Tags()["host"]
|
||||||
|
@ -102,12 +105,16 @@ func buildEvents(p telegraf.Metric, s string) []*raidman.Event {
|
||||||
|
|
||||||
event := &raidman.Event{
|
event := &raidman.Event{
|
||||||
Host: host,
|
Host: host,
|
||||||
Service: serviceName(s, p.Name(), p.Tags(), fieldName),
|
Service: r.service(p.Name(), fieldName),
|
||||||
|
Tags: r.tags(p.Name(), p.Tags()),
|
||||||
|
Attributes: p.Tags(),
|
||||||
|
Time: p.Time().Unix(),
|
||||||
}
|
}
|
||||||
|
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
case string:
|
case string:
|
||||||
event.State = value.(string)
|
state := []byte(value.(string))
|
||||||
|
event.State = string(state[:254]) // Riemann states must be less than 255 bytes, e.g. "ok", "warning", "critical"
|
||||||
default:
|
default:
|
||||||
event.Metric = value
|
event.Metric = value
|
||||||
}
|
}
|
||||||
|
@ -118,30 +125,36 @@ func buildEvents(p telegraf.Metric, s string) []*raidman.Event {
|
||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
func serviceName(s string, n string, t map[string]string, f string) string {
|
func (r *Riemann) tags(name string, tags map[string]string) []string {
|
||||||
serviceStrings := []string{}
|
var tagNames, tagValues []string
|
||||||
serviceStrings = append(serviceStrings, n)
|
|
||||||
|
|
||||||
// we'll skip the 'host' tag
|
for tagName := range tags {
|
||||||
tagStrings := []string{}
|
|
||||||
tagNames := []string{}
|
|
||||||
|
|
||||||
for tagName := range t {
|
|
||||||
tagNames = append(tagNames, tagName)
|
tagNames = append(tagNames, tagName)
|
||||||
}
|
}
|
||||||
sort.Strings(tagNames)
|
sort.Strings(tagNames)
|
||||||
|
|
||||||
|
if r.MeasurementAsTag {
|
||||||
|
tagValues = append(tagValues, name)
|
||||||
|
}
|
||||||
|
|
||||||
for _, tagName := range tagNames {
|
for _, tagName := range tagNames {
|
||||||
if tagName != "host" {
|
if tagName != "host" { // we'll skip the 'host' tag
|
||||||
tagStrings = append(tagStrings, t[tagName])
|
tagValues = append(tagValues, tags[tagName])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var tagString string = strings.Join(tagStrings, s)
|
|
||||||
if tagString != "" {
|
return tagValues
|
||||||
serviceStrings = append(serviceStrings, tagString)
|
|
||||||
}
|
}
|
||||||
serviceStrings = append(serviceStrings, f)
|
|
||||||
return strings.Join(serviceStrings, s)
|
func (r *Riemann) service(name string, field string) string {
|
||||||
|
var serviceStrings []string
|
||||||
|
|
||||||
|
if !r.MeasurementAsTag {
|
||||||
|
serviceStrings = append(serviceStrings, name)
|
||||||
|
}
|
||||||
|
serviceStrings = append(serviceStrings, field)
|
||||||
|
|
||||||
|
return strings.Join(serviceStrings, r.Separator)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
Loading…
Reference in New Issue