Skip to content

Commit

Permalink
Add okmeter agent tag format
Browse files Browse the repository at this point in the history
  • Loading branch information
ds authored and smira committed Oct 3, 2023
1 parent 60e773d commit 669a2e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type TagFormat struct {
// OtherSeparator separates 2nd and subsequent tags from each other
OtherSeparator byte
// KeyValueSeparator separates tag name and tag value
KeyValueSeparator byte
KeyValueSeparator []byte
}

// Tag types
Expand All @@ -61,7 +61,7 @@ type Tag struct {
// Append formats tag and appends it to the buffer
func (tag Tag) Append(buf []byte, style *TagFormat) []byte {
buf = append(buf, []byte(tag.name)...)
buf = append(buf, style.KeyValueSeparator)
buf = append(buf, style.KeyValueSeparator...)
if tag.typ == typeString {
return append(buf, []byte(tag.strvalue)...)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ var (
Placement: TagPlacementName,
FirstSeparator: ",",
OtherSeparator: ',',
KeyValueSeparator: '=',
KeyValueSeparator: []byte{'='},
}

// TagFormatDatadog is format for DogStatsD (Datadog Agent)
Expand All @@ -125,7 +125,7 @@ var (
Placement: TagPlacementSuffix,
FirstSeparator: "|#",
OtherSeparator: ',',
KeyValueSeparator: ':',
KeyValueSeparator: []byte{':'},
}

// TagFormatGraphite is format for Graphite
Expand All @@ -135,6 +135,16 @@ var (
Placement: TagPlacementName,
FirstSeparator: ";",
OtherSeparator: ';',
KeyValueSeparator: '=',
KeyValueSeparator: []byte{'='},
}

// TagFormatOkmeter is format for Okmeter agent
//
// Docs: https://okmeter.io/misc/docs#statsd-plugin-config
TagFormatOkmeter = &TagFormat{
Placement: TagPlacementName,
FirstSeparator: ".",
OtherSeparator: '.',
KeyValueSeparator: []byte("_is_"),
}
)
2 changes: 2 additions & 0 deletions tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ func TestFormatTags(t *testing.T) {
compare([]Tag{StringTag("type", "web"), IntTag("status", 200)}, TagFormatInfluxDB, ",host=foo,type=web,status=200"))
t.Run("Graphite",
compare([]Tag{StringTag("type", "web"), IntTag("status", 200)}, TagFormatGraphite, ";host=foo;type=web;status=200"))
t.Run("Okmeter",
compare([]Tag{StringTag("type", "web"), IntTag("status", 200)}, TagFormatOkmeter, ".host_is_foo.type_is_web.status_is_200"))
}

0 comments on commit 669a2e5

Please sign in to comment.