简体   繁体   中英

StatsD-Exporter metrics are not being received from Java

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.

  • Sometimes I just cannot find my metric
  • In most of the times I can find a new metric sent from Java but it is stuck on count 1. Means that even if I send the same metric 10 times, it'll still display 1. Then taking the same name of the metric and sending it to statsd from the shell - and the counter increments.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM