Skip to content

Commit

Permalink
Merge pull request #42 from brharrington/servo-step-counter
Browse files Browse the repository at this point in the history
Use StepCounter instead of BasicCounter
  • Loading branch information
brharrington committed Oct 22, 2014
2 parents c3d0d12 + cb48f8b commit bb7f4c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@

import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

/** Counter implementation for the servo registry. */
class ServoCounter implements Counter, ServoMeter {

private final Clock clock;
private final com.netflix.servo.monitor.BasicCounter impl;
private final com.netflix.servo.monitor.StepCounter impl;
private final AtomicLong count;

/** Create a new instance. */
ServoCounter(Clock clock, com.netflix.servo.monitor.BasicCounter impl) {
ServoCounter(Clock clock, com.netflix.servo.monitor.StepCounter impl) {
this.clock = clock;
this.impl = impl;
this.count = new AtomicLong(0L);
}

@Override public void addMonitors(List<Monitor<?>> monitors) {
Expand All @@ -50,19 +53,21 @@ class ServoCounter implements Counter, ServoMeter {

@Override public Iterable<Measurement> measure() {
long now = clock.wallTime();
long v = count();
double v = impl.getValue(0).doubleValue();
return Collections.singleton(new Measurement(id(), now, v));
}

@Override public void increment() {
impl.increment();
count.incrementAndGet();
}

@Override public void increment(long amount) {
impl.increment(amount);
count.addAndGet(amount);
}

@Override public long count() {
return impl.getValue(0).longValue();
return count.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ MonitorConfig toMonitorConfig(Id id) {

@Override protected Counter newCounter(Id id) {
MonitorConfig cfg = toMonitorConfig(id);
BasicCounter counter = new BasicCounter(cfg);
StepCounter counter = new StepCounter(cfg, new ServoClock(clock()));
return new ServoCounter(clock(), counter);
}

Expand Down

0 comments on commit bb7f4c7

Please sign in to comment.