Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit cfb0f50

Browse files
ncolomerCyrille Le Clerc
authored andcommitted
Make tags to be serialized according to DogStatsD and Sysdig protocols
Fixes #123
1 parent 4d46c28 commit cfb0f50

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/main/java/org/jmxtrans/agent/StatsDOutputWriter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public synchronized void postConstruct(Map<String, String> settings) {
7373
if (statsType.equals(STATSD_DATADOG)) {
7474
String tagsStr = ConfigurationUtils.getString(settings, SETTINGS_TAGS, "");
7575
tags = Tag.tagsFromCommaSeparatedString(tagsStr);
76-
tags.add(new Tag("#host", ConfigurationUtils.getString(settings, SETTING_HOST_NAMME, getHostName().replaceAll("\\.", "_") )));
76+
tags.add(new Tag("host", ConfigurationUtils.getString(settings, SETTING_HOST_NAMME, getHostName().replaceAll("\\.", "_") )));
7777
metricNamePrefix = ConfigurationUtils.getString(settings, SETTING_ROOT_PREFIX, "java");
7878
} else if (statsType.equals(STATSD_SYSDIG)) {
7979
String tagsStr = ConfigurationUtils.getString(settings, SETTINGS_TAGS, "");
@@ -147,13 +147,14 @@ public synchronized void writeQueryResult(String metricName, String metricType,
147147
.append(value)
148148
.append("|")
149149
.append(type)
150-
.append("|")
150+
.append("|#")
151151
.append(StringUtils2.join(Tag.convertTagsToStrings(tags), ","))
152152
.append("\n");
153153
} else if (statsType.equals(STATSD_SYSDIG)) {
154154
sb.append(metricNamePrefix)
155155
.append(".")
156156
.append(metricName)
157+
.append("#")
157158
.append(StringUtils2.join(Tag.convertTagsToStrings(tags), ","))
158159
.append(":")
159160
.append(value)

src/main/java/org/jmxtrans/agent/Tag.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static Tag parseOneTag(String part) {
9090
throw new RuntimeException(
9191
"Error when parsing tags from substring " + part + ", must be on format <name>:<value>,...");
9292
}
93-
Tag tag = new Tag("#"+nameAndValue[0].trim(), getValueProperties(nameAndValue[1].trim()));
93+
Tag tag = new Tag(nameAndValue[0].trim(), getValueProperties(nameAndValue[1].trim()));
9494
return tag;
9595
}
9696

@@ -100,7 +100,7 @@ private static Tag parseOneTag(String part, String separator) {
100100
throw new RuntimeException(
101101
"Error when parsing influx from substring " + part + ", must be on format <name"+separator+"<value>,...");
102102
}
103-
Tag tag = new Tag("#"+nameAndValue[0].trim(), getValueProperties(nameAndValue[1].trim()), separator);
103+
Tag tag = new Tag(nameAndValue[0].trim(), getValueProperties(nameAndValue[1].trim()), separator);
104104
return tag;
105105
}
106106

src/test/java/org/jmxtrans/agent/StatsDOutputWriterTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ public void test_write_counter_metric_dd() throws IOException {
7474

7575
writer.postConstruct(settings);
7676
writer.writeQueryResult("my-metric", "gauge", 12);
77-
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.my-metric:12|g|#tag1:ok,#tag2:woff,#host:bar\n"));
77+
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.my-metric:12|g|#tag1:ok,tag2:woff,host:bar\n"));
7878
writer.writeQueryResult("my-metric", "g", 13);
79-
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.my-metric:13|g|#tag1:ok,#tag2:woff,#host:bar\n"));
79+
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.my-metric:13|g|#tag1:ok,tag2:woff,host:bar\n"));
8080

8181
writer.writeQueryResult("the.answer", "counter", 42);
82-
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer:42|c|#tag1:ok,#tag2:woff,#host:bar\n"));
82+
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer:42|c|#tag1:ok,tag2:woff,host:bar\n"));
8383
writer.writeQueryResult("the.answer", "c", 43);
84-
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer:43|c|#tag1:ok,#tag2:woff,#host:bar\n"));
84+
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer:43|c|#tag1:ok,tag2:woff,host:bar\n"));
8585

8686
writer.writeQueryResult("the.answer", "lala", 44);
87-
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer:44|c|#tag1:ok,#tag2:woff,#host:bar\n"));
87+
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer:44|c|#tag1:ok,tag2:woff,host:bar\n"));
8888

8989
}
9090

@@ -100,17 +100,17 @@ public void test_write_counter_metric_sysdig() throws IOException {
100100

101101
writer.postConstruct(settings);
102102
writer.writeQueryResult("my-metric", "gauge", 12);
103-
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.my-metric#tag1=ok,#tag2=woff:12|g\n"));
103+
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.my-metric#tag1=ok,tag2=woff:12|g\n"));
104104
writer.writeQueryResult("my-metric", "g", 13);
105-
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.my-metric#tag1=ok,#tag2=woff:13|g\n"));
105+
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.my-metric#tag1=ok,tag2=woff:13|g\n"));
106106

107107
writer.writeQueryResult("the.answer", "counter", 42);
108-
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer#tag1=ok,#tag2=woff:42|c\n"));
108+
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer#tag1=ok,tag2=woff:42|c\n"));
109109
writer.writeQueryResult("the.answer", "c", 43);
110-
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer#tag1=ok,#tag2=woff:43|c\n"));
110+
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer#tag1=ok,tag2=woff:43|c\n"));
111111

112112
writer.writeQueryResult("the.answer", "lala", 44);
113-
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer#tag1=ok,#tag2=woff:44|c\n"));
113+
Assert.assertThat(writer.receivedStat, equalTo("foo.bar.the.answer#tag1=ok,tag2=woff:44|c\n"));
114114

115115
}
116116

0 commit comments

Comments
 (0)