package de.is24.util.monitoring.metrics;

import com.codahale.metrics.MetricRegistry;
import de.is24.util.monitoring.AbstractMonitorPlugin;
import java.util.concurrent.TimeUnit;


public class MetricsPlugin extends AbstractMonitorPlugin {
  private MetricRegistry metricRegistry;

  public MetricsPlugin(MetricRegistry metricRegistry) {
    this.metricRegistry = metricRegistry;
  }

  @Override
  public String getUniqueName() {
    return null;
  }

  @Override
  public void initializeCounter(String name) {
  }

  @Override
  public void incrementCounter(String name, int increment) {
    metricRegistry.counter(name).inc(increment);
  }

  @Override
  public void incrementHighRateCounter(String name, int increment) {
    incrementCounter(name, increment);
  }

  @Override
  public void addTimerMeasurement(String name, long timing) {
    metricRegistry.timer(name).update(timing, TimeUnit.MILLISECONDS);
  }

  @Override
  public void addSingleEventTimerMeasurement(String name, long timing) {
    metricRegistry.timer(name).update(timing, TimeUnit.MILLISECONDS);
  }

  @Override
  public void addHighRateTimerMeasurement(String name, long timing) {
    metricRegistry.timer(name).update(timing, TimeUnit.MILLISECONDS);
  }

  @Override
  public void initializeTimerMeasurement(String name) {
  }

  @Override
  public void afterRemovalNotification() {
  }
}

@@ -609,21 +609,41 @@
 counter(
+withCountersPrefix(
 name)
+)
 .inc(inc
@@ -872,37 +872,55 @@
 cRegistry.timer(
+withTimersPrefix(
 name)
+)
 .update(timing, 
@@ -1041,71 +1041,40 @@
     
-metricRegistry.timer(name).update(timing, TimeUnit.MILLISECONDS
+addTimerMeasurement(name, timing
 );%0A 
@@ -1167,71 +1167,40 @@
     
-metricRegistry.timer(name).update(timing, TimeUnit.MILLISECONDS
+addTimerMeasurement(name, timing
 );%0A 
@@ -1280,32 +1280,32 @@
  %7D%0A%0A  @Override%0A
-
   public void af
@@ -1334,11 +1334,181 @@
 () %7B%0A  %7D
+%0A%0A  private String withTimersPrefix(String name) %7B%0A    return %22timers.%22 + name;%0A  %7D%0A%0A  private String withCountersPrefix(String name) %7B%0A    return %22counters.%22 + name;%0A  %7D
 %0A%7D%0A

Add prefixes for timers and counters to emulate StatsD behavior.