0.3.0 outputs: riemann

This commit is contained in:
Cameron Sparr 2015-12-19 14:55:44 -07:00
parent 96e54ab326
commit f60d846eb3
1 changed files with 23 additions and 17 deletions

View File

@ -55,8 +55,10 @@ func (r *Riemann) Write(points []*client.Point) error {
var events []*raidman.Event var events []*raidman.Event
for _, p := range points { for _, p := range points {
ev := buildEvent(p) evs := buildEvents(p)
events = append(events, ev) for _, ev := range evs {
events = append(events, ev)
}
} }
var senderr = r.client.SendMulti(events) var senderr = r.client.SendMulti(events)
@ -68,24 +70,28 @@ func (r *Riemann) Write(points []*client.Point) error {
return nil return nil
} }
func buildEvent(p *client.Point) *raidman.Event { func buildEvents(p *client.Point) []*raidman.Event {
host, ok := p.Tags()["host"] events := []*raidman.Event{}
if !ok { for fieldName, value := range p.Fields() {
hostname, err := os.Hostname() host, ok := p.Tags()["host"]
if err != nil { if !ok {
host = "unknown" hostname, err := os.Hostname()
} else { if err != nil {
host = hostname host = "unknown"
} else {
host = hostname
}
} }
event := &raidman.Event{
Host: host,
Service: p.Name() + "_" + fieldName,
Metric: value,
}
events = append(events, event)
} }
var event = &raidman.Event{ return events
Host: host,
Service: p.Name(),
Metric: p.Fields()["value"],
}
return event
} }
func init() { func init() {