Skip to content

Commit

Permalink
Report mongodb times as timer not as histogram
Browse files Browse the repository at this point in the history
Signed-off-by: Klem Yannic (INST/ECS1) <Yannic.Klem@bosch-si.com>
  • Loading branch information
Yannic92 committed Jul 10, 2018
1 parent 42f03d5 commit 86dd671
Showing 1 changed file with 10 additions and 4 deletions.
Expand Up @@ -18,6 +18,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mongodb.event.CommandEvent;
import com.mongodb.event.CommandFailedEvent;
import com.mongodb.event.CommandListener;
import com.mongodb.event.CommandStartedEvent;
Expand All @@ -31,10 +32,11 @@
public class KamonCommandListener implements CommandListener {

private static final Logger LOGGER = LoggerFactory.getLogger(KamonCommandListener.class);
private final String histogramPrefix;
private static final String COMMAND_NAME_TAG = "command_name";
private final String timerName;

public KamonCommandListener(final String metricName) {
this.histogramPrefix = ConditionChecker.argumentNotEmpty(metricName, "metricName") + "_mongodb_";
this.timerName = ConditionChecker.argumentNotEmpty(metricName, "metricName") + "_mongodb_";
}

@Override
Expand Down Expand Up @@ -65,7 +67,7 @@ public void commandSucceeded(final CommandSucceededEvent event) {

final long elapsedTime = event.getElapsedTime(TimeUnit.NANOSECONDS);
final String commandName = event.getCommandName();
Kamon.histogram(TraceUtils.metricizeTraceUri(histogramPrefix + commandName)).record(elapsedTime);
recordElapsedTime(elapsedTime, commandName);
}

@Override
Expand All @@ -83,6 +85,10 @@ public void commandFailed(final CommandFailedEvent event) {

final long elapsedTime = event.getElapsedTime(TimeUnit.NANOSECONDS);
final String commandName = event.getCommandName();
Kamon.histogram(TraceUtils.metricizeTraceUri(histogramPrefix + commandName)).record(elapsedTime);
recordElapsedTime(elapsedTime, commandName);
}

private void recordElapsedTime(final long elapsedTime, final String commandName) {
Kamon.timer(TraceUtils.metricizeTraceUri(timerName)).refine(COMMAND_NAME_TAG, commandName).record(elapsedTime);
}
}

0 comments on commit 86dd671

Please sign in to comment.