Skip to content

Commit

Permalink
Merge pull request #361 from aol/micro-metrics-instant-gauge
Browse files Browse the repository at this point in the history
InstantGauge to use with datadog
  • Loading branch information
morrowgi authored Jul 19, 2017
2 parents ee439ff + b3c93e9 commit d04eb2a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.aol.micro.server.spring.metrics;

import java.util.concurrent.atomic.AtomicLong;

import com.codahale.metrics.Gauge;


public class InstantGauge implements Gauge<Long> {

private final AtomicLong counter = new AtomicLong(0l);

@Override
public Long getValue() {
return counter.getAndSet(0l);
}

public void increment() {
counter.incrementAndGet();
}

public void increase(long value) {
counter.addAndGet(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.aol.micro.server.spring.metrics;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class InstantGaugeTest {

@Test
public void instantGauge() {
InstantGauge gauge = new InstantGauge();
gauge.increment();
gauge.increase(3);

assertEquals(4l ,gauge.getValue().longValue());
assertEquals(0l ,gauge.getValue().longValue());

}

}

0 comments on commit d04eb2a

Please sign in to comment.