Last active
September 6, 2018 11:59
-
-
Save jkschneider/a7af362d51da99b21dd9c84484213a44 to your computer and use it in GitHub Desktop.
Demonstrating how to use a prefix with Micrometer Etsy-flavored Statsd bound for Graphite.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.micrometer.core.samples; | |
import io.micrometer.graphite.GraphiteHierarchicalNameMapper; | |
import io.micrometer.statsd.StatsdConfig; | |
import io.micrometer.statsd.StatsdFlavor; | |
import io.micrometer.statsd.StatsdMeterRegistry; | |
public class StatsdPrefixSample { | |
public static void main(String[] args) { | |
StatsdMeterRegistry registry = StatsdMeterRegistry | |
.builder(new StatsdConfig() { | |
@Override | |
public String get(String key) { | |
return null; | |
} | |
@Override | |
public StatsdFlavor flavor() { | |
return StatsdFlavor.ETSY; | |
} | |
}) | |
.nameMapper(new GraphiteHierarchicalNameMapper("server")) | |
.lineSink(System.out::println) | |
.build(); | |
registry.config().commonTags("server", "MYSERVERNAME"); | |
registry.counter("my.counter", "othertag", "value").increment(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi John,
Thanks for publishing this code, got a few questions:
per your comment: "Line 23 is just for demonstration purposes, and shouldn't be part of your typical config. It just means that we are redirecting statsd lines to System.out rather than to the default UDP port."
when i remove this line i don't see any publish messages via wire-shark, not to my configure host at
management.export.statsd.host: or management.export.statsd.host. and also not to localhost which is the default apparently.
per your comment:"In Spring Boot, Line 19 can be configured with management.metrics.export.statsd.flavor=etsy instead."
it seems that both ways produce different results:
with line 19:
MYSERVERNAME.myCounter.othertag.value.statistic.count:1|c
without line 19 and with etsy flavor property:
my.counter:1|c|#statistic:count,othertag:value,server:MYSERVERNAME
Calling to line 28 multiple time gives the same result, should i expect it to increment the number between calls ?
MYSERVERNAME.myCounter.othertag.value.statistic.count:1|c
MYSERVERNAME.myCounter.othertag.value.statistic.count:1|c
MYSERVERNAME.myCounter.othertag.value.statistic.count:1|c
Adding a simple private method with @timed annotation and calling it from main doesn't produce any more printouts, should it ?
@timed
private void simplePrivateMethod(){
}
Any chance you can add example of a timer and a counter ?
i was able to mesure the time of the simplePrivateMethod by wrapping the method call with this:
Timer timer = Timer.builder("myservice").tag("method", "manual").register(registry);
long start = System.nanoTime();
StatsdPrefixSample statsdPrefixSample=new StatsdPrefixSample();
statsdPrefixSample.simplePrivateMethod();
but that made me confuse about the use of the @timed annotation, do both measure the time of the method execution ?
5 What about all the "outOfTheBox" meters that are being sent such as JVM, Tomcat etc? will they get the prefix "MYSERVERNAME" too ?
6. per your comment "Line 26 should be defined in a @bean MeterRegistryCustomizer as seen in the Spring Boot reference docs."
after defining it as a bean i got
myCounter.othertag.value.statistic.count:1|c instead of
MYSERVERNAME.myCounter.othertag.value.statistic.count:1|c
Thanks in advanced for your help, my organization really want to replace all of our meter handling to Micrometer but we so far we are struggling with setting it up.
Can we have a quick call to troubleshoot this ? or maybe i can upload my code so we can find the issue with it ?
Thanks,
Oren