Updated Riemann output:
* Customizable 'separator' option instead of hard-coded '_' * String values are sent as "State" instead of "Metric", preventing Riemann from rejecting them * Riemann service name is set to an (ugly) combination of input name & (sorted) tags' values...this allows connecting different events for the same input together on the Riemann side closes #642
This commit is contained in:
parent
fc7fa4b6c5
commit
893357f01e
|
@ -14,6 +14,7 @@ parsing JSON data as it does now.
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
- [#443](https://github.com/influxdata/telegraf/issues/443): Fix Ping command timeout parameter on Linux.
|
- [#443](https://github.com/influxdata/telegraf/issues/443): Fix Ping command timeout parameter on Linux.
|
||||||
- [#662](https://github.com/influxdata/telegraf/pull/667): Change `[tags]` to `[global_tags]` to fix multiple-plugin tags bug.
|
- [#662](https://github.com/influxdata/telegraf/pull/667): Change `[tags]` to `[global_tags]` to fix multiple-plugin tags bug.
|
||||||
|
- [#642](https://github.com/influxdata/telegraf/issues/642): Riemann output plugin issues.
|
||||||
|
|
||||||
## v0.10.2 [2016-02-04]
|
## v0.10.2 [2016-02-04]
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/amir/raidman"
|
"github.com/amir/raidman"
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
@ -13,6 +15,7 @@ import (
|
||||||
type Riemann struct {
|
type Riemann struct {
|
||||||
URL string
|
URL string
|
||||||
Transport string
|
Transport string
|
||||||
|
Separator string
|
||||||
|
|
||||||
client *raidman.Client
|
client *raidman.Client
|
||||||
}
|
}
|
||||||
|
@ -22,6 +25,8 @@ 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 = " "
|
||||||
`
|
`
|
||||||
|
|
||||||
func (r *Riemann) Connect() error {
|
func (r *Riemann) Connect() error {
|
||||||
|
@ -55,7 +60,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)
|
evs := buildEvents(p, r.Separator)
|
||||||
for _, ev := range evs {
|
for _, ev := range evs {
|
||||||
events = append(events, ev)
|
events = append(events, ev)
|
||||||
}
|
}
|
||||||
|
@ -70,7 +75,7 @@ func (r *Riemann) Write(metrics []telegraf.Metric) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildEvents(p telegraf.Metric) []*raidman.Event {
|
func buildEvents(p telegraf.Metric, s string) []*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"]
|
||||||
|
@ -85,15 +90,48 @@ func buildEvents(p telegraf.Metric) []*raidman.Event {
|
||||||
|
|
||||||
event := &raidman.Event{
|
event := &raidman.Event{
|
||||||
Host: host,
|
Host: host,
|
||||||
Service: p.Name() + "_" + fieldName,
|
Service: serviceName(s, p.Name(), p.Tags(), fieldName),
|
||||||
Metric: value,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch value.(type) {
|
||||||
|
case string:
|
||||||
|
event.State = value.(string)
|
||||||
|
default:
|
||||||
|
event.Metric = value
|
||||||
|
}
|
||||||
|
|
||||||
events = append(events, event)
|
events = append(events, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func serviceName(s string, n string, t map[string]string, f string) string {
|
||||||
|
serviceStrings := []string{}
|
||||||
|
serviceStrings = append(serviceStrings, n)
|
||||||
|
|
||||||
|
// we'll skip the 'host' tag
|
||||||
|
tagStrings := []string{}
|
||||||
|
tagNames := []string{}
|
||||||
|
|
||||||
|
for tagName := range t {
|
||||||
|
tagNames = append(tagNames, tagName)
|
||||||
|
}
|
||||||
|
sort.Strings(tagNames)
|
||||||
|
|
||||||
|
for _, tagName := range tagNames {
|
||||||
|
if tagName != "host" {
|
||||||
|
tagStrings = append(tagStrings, t[tagName])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var tagString string = strings.Join(tagStrings, s)
|
||||||
|
if tagString != "" {
|
||||||
|
serviceStrings = append(serviceStrings, tagString)
|
||||||
|
}
|
||||||
|
serviceStrings = append(serviceStrings, f)
|
||||||
|
return strings.Join(serviceStrings, s)
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
outputs.Add("riemann", func() telegraf.Output {
|
outputs.Add("riemann", func() telegraf.Output {
|
||||||
return &Riemann{}
|
return &Riemann{}
|
||||||
|
|
Loading…
Reference in New Issue