Skip to content

Commit

Permalink
Include all tag values in graphite output
Browse files Browse the repository at this point in the history
closes #595
  • Loading branch information
sparrc committed Jan 27, 2016
1 parent a822d94 commit bd88b08
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions plugins/outputs/graphite/graphite.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,30 @@ func (g *Graphite) Write(points []*client.Point) error {
timestamp := point.UnixNano() / 1000000000

for field_name, value := range point.Fields() {
var tag_str string
for tag_key, tag_value := range point.Tags() {
tag_value := strings.Replace(tag_value, ".", "_", -1)
if tag_key == "host" {
tag_str = tag_value + "." + tag_str
} else {
tag_str += "." + tag_value
}
}
tag_str = strings.Trim(tag_str, ".")
tag_str = strings.Replace(tag_str, "..", ".", -1)
// Convert value
value_str := fmt.Sprintf("%#v", value)
// Write graphite point
var graphitePoint string
if name == field_name {
graphitePoint = fmt.Sprintf("%s.%s %s %d\n",
strings.Replace(point.Tags()["host"], ".", "_", -1),
tag_str,
strings.Replace(name, ".", "_", -1),
value_str,
timestamp)
} else {
graphitePoint = fmt.Sprintf("%s.%s.%s %s %d\n",
strings.Replace(point.Tags()["host"], ".", "_", -1),
tag_str,
strings.Replace(name, ".", "_", -1),
strings.Replace(field_name, ".", "_", -1),
value_str,
Expand All @@ -99,7 +110,6 @@ func (g *Graphite) Write(points []*client.Point) error {
graphitePoint = fmt.Sprintf("%s.%s", g.Prefix, graphitePoint)
}
bp = append(bp, graphitePoint)
//fmt.Printf(graphitePoint)
}
}
graphitePoints := strings.Join(bp, "")
Expand Down

0 comments on commit bd88b08

Please sign in to comment.