2017-12-04 8 views
0

DropwizardMetricServices#submit()使用しているゲージメトリックを2回目に送信しません。DropwizardMetricServicesは、JMXに初めてメジャーメトリックを送信しません(最初の削除後)

つまり、私のユースケースは、JMXを読み込んだ後にJMXからゲージメトリックを削除することです。そして、私のアプリケーションは同じメトリック(別の値で)を送ることができます。

初めてゲージメトリックが正常に送信されます(アプリケーションでメトリックが読み込まれると、アプリケーションでそれが削除されます)。しかし、同じメトリックは2回目に提出されません。

私は、DropwizardMetricServices#submit()の2回目の作業ができない理由は何か混乱していますか?以下は

はコードです:

は、メトリック送信:メトリックを読み取り、削除

private void submitNonSparseMetric(final String metricName, final long value) { 
    validateMetricName(metricName); 
    metricService.submit(metricName, value); // metricService is the DropwizardMetricServices 
    log(metricName, value); 
    LOGGER.debug("Submitted the metric {} to JMX", metricName); 
} 

コード:

protected void collectMetrics() { 
    // Create the connection 
    Long currTime = System.currentTimeMillis()/1000; // Graphite needs 
    Socket connection = createConnection(); 
    if (connection == null){ 
     return; 
    } 
    // Get the output stream 
    DataOutputStream outputStream = getDataOutputStream(connection); 
    if (outputStream == null){ 
     closeConnection(); 
     return; 
    } 
    // Get metrics from JMX 
    Map<String, Gauge> g = metricRegistry.getGauges(); // metricRegistry is com.codahale.metrics.MetricRegistry 
    for(Entry<String, Gauge> e : g.entrySet()){ 
     String key = e.getKey(); 
     if(p2cMetric(key)){ 
      String metricName = convertToMetricStandard(key); 
      String metricValue = String.valueOf(e.getValue().getValue()); 

      String metricToSend = String.format("%s %s %s\n", metricName, metricValue, currTime); 
      try { 
       writeToStream(outputStream, metricToSend); 
       // Remove the metric from JMX after successfully sending metric to graphite 
       removeMetricFromJMX(key); 
      } catch (IOException e1) { 
       LOGGER.error("Unable to send metric to Graphite - {}", e1.getMessage()); 
      } 
     } 

    } 

    closeOutputStream(); 
    closeConnection(); 
} 

答えて

0

を私は問題を発見したと思います。

DropwizardMetricServices doc-https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.html#submit-java.lang.String-double-、 submit()メソッドSet the specified gauge valueに準拠しています。 したがって、JMXの既存のゲージメトリックの値だけを設定し、JMXに新しいメトリックを追加するのではなく、DropwizardMetricServices#submit()メソッドを使用することをお勧めします。

これで、DropwizardMetricServices#submit()をMetricRegistry#register()(com.codahale.metrics.MetricRegistry)メソッドに置き換えると、期待通りに機能したメトリックをすべて送信し、メトリックはJMXに読み込まれました私のアプリケーションによって削除されました)。

しかし、私はDropwizardMetricServices#submit()がJMXに新しいメトリックを追加するだけで、(JMXから)既に削除されているメトリックは追加しないのではないかと思っています。 DropwizardMetricServicesはJMXに送信されたすべてのメトリックを(メモリ内に)キャッシュしますか? DropwizardMetricServices#submit()メソッドがメトリックを再サブミットしないようにしますか?

関連する問題