use of com.netflix.servo.monitor.BasicCounter in project zuul by Netflix.
the class Counter method getCounter.
private BasicCounter getCounter(String name) {
BasicCounter counter = map.get(name);
if (counter == null) {
synchronized (lock) {
counter = map.get(name);
if (counter != null) {
return counter;
}
List<Tag> tags = new ArrayList<Tag>(2);
tags.add(InjectableTag.HOSTNAME);
tags.add(InjectableTag.IP);
counter = new BasicCounter(MonitorConfig.builder(name).withTags(tags).build());
map.putIfAbsent(name, counter);
DefaultMonitorRegistry.getInstance().register(counter);
}
}
return counter;
}
use of com.netflix.servo.monitor.BasicCounter in project incubator-servicecomb-java-chassis by apache.
the class MonitorManager method getCounter.
public Counter getCounter(String name, String... tags) {
validateMonitorNameAndTags(name, tags);
return counters.computeIfAbsent(getMonitorKey(name, tags), f -> {
Counter counter = new BasicCounter(getConfig(name, tags));
basicMonitorRegistry.register(counter);
return counter;
});
}
use of com.netflix.servo.monitor.BasicCounter in project tutorials by eugenp.
the class MetricTypeTest method givenBasicCounter_whenManipulate_thenCountValid.
@Test
public void givenBasicCounter_whenManipulate_thenCountValid() {
Counter counter = new BasicCounter(MonitorConfig.builder("test").build());
assertEquals("counter should start with 0", 0, counter.getValue().intValue());
counter.increment();
assertEquals("counter should have increased by 1", 1, counter.getValue().intValue());
counter.increment(-1);
assertEquals("counter should have decreased by 1", 0, counter.getValue().intValue());
}
use of com.netflix.servo.monitor.BasicCounter in project zuul by Netflix.
the class Counter method increment.
@Override
public void increment(String name) {
BasicCounter counter = getCounter(name);
counter.increment();
}
use of com.netflix.servo.monitor.BasicCounter in project tutorials by eugenp.
the class AtlasObserverLiveTest method givenAtlasAndCounter_whenRegister_thenPublishedToAtlas.
@Test
public void givenAtlasAndCounter_whenRegister_thenPublishedToAtlas() throws Exception {
Counter counter = new BasicCounter(MonitorConfig.builder("test").withTag("servo", "counter").build());
DefaultMonitorRegistry.getInstance().register(counter);
assertThat(atlasValuesOfTag("servo"), not(containsString("counter")));
for (int i = 0; i < 3; i++) {
counter.increment(RandomUtils.nextInt(10));
SECONDS.sleep(1);
counter.increment(-1 * RandomUtils.nextInt(10));
SECONDS.sleep(1);
}
assertThat(atlasValuesOfTag("servo"), containsString("counter"));
}
Aggregations