I'm going thru this tutorial on my Mac, trying to send counter metrics from my Java code to Prometheus via StatsD-Exporter.
On my localhost I run two Docker containers, one is Prometheus, the other is StatsD-exporter. Trying to be as much permitting as possible, this is my statsd_mapping.yaml:
mappings:
- match: "*.*.*.*"
name: "${1}_name"
labels:
label1: "$2"
label2: "$3"
label3: "$4"
So in order to send some data to statsd-exporter, I'm using this shell command a few times:
echo -n 'blah.step_4.reason.new_entities:1|c' | nc -u -w0 localhost 9125
Then I'm browsing to http://localhost:9102/metrics
and I can see my metric there:
# HELP blah_name Metric autogenerated by statsd_exporter.
# TYPE blah_name counter
blah_name{label1="step_4",label2="reason",label3="new_entities"} 5
My metric was received 5 times as expected.
Then I'm using the Java NonBlockingStatsDClient, sending the same metric, and I expect to see the metric as before.
This is my Java code:
private static final StatsDClient statsd = new NonBlockingStatsDClient(
"",
"127.0.0.1",
9125
);
public static void main(String[] args) {
statsd.incrementCounter("blah1.step_4.reason.new_entities");
}
Running the code above bring random results.
What do I miss?
Thanks!
OK I just got it solved. The problem is that I'm using a Non blocking client. As the main thread is dead before the client succeeded to send anything - I couldn't find any metric on StatsD.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.