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();
}