Search in sources :

Example 1 with BasicCounter

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;
}
Also used : ArrayList(java.util.ArrayList) BasicCounter(com.netflix.servo.monitor.BasicCounter) InjectableTag(com.netflix.servo.tag.InjectableTag) Tag(com.netflix.servo.tag.Tag)

Example 2 with BasicCounter

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;
    });
}
Also used : Counter(com.netflix.servo.monitor.Counter) BasicCounter(com.netflix.servo.monitor.BasicCounter) BasicCounter(com.netflix.servo.monitor.BasicCounter)

Example 3 with BasicCounter

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());
}
Also used : Counter(com.netflix.servo.monitor.Counter) StepCounter(com.netflix.servo.monitor.StepCounter) BasicCounter(com.netflix.servo.monitor.BasicCounter) PeakRateCounter(com.netflix.servo.monitor.PeakRateCounter) BasicCounter(com.netflix.servo.monitor.BasicCounter) Test(org.junit.Test)

Example 4 with BasicCounter

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();
}
Also used : BasicCounter(com.netflix.servo.monitor.BasicCounter)

Example 5 with BasicCounter

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"));
}
Also used : Counter(com.netflix.servo.monitor.Counter) BasicCounter(com.netflix.servo.monitor.BasicCounter) BasicCounter(com.netflix.servo.monitor.BasicCounter) Test(org.junit.Test)

Aggregations

BasicCounter (com.netflix.servo.monitor.BasicCounter)5 Counter (com.netflix.servo.monitor.Counter)3 Test (org.junit.Test)2 PeakRateCounter (com.netflix.servo.monitor.PeakRateCounter)1 StepCounter (com.netflix.servo.monitor.StepCounter)1 InjectableTag (com.netflix.servo.tag.InjectableTag)1 Tag (com.netflix.servo.tag.Tag)1 ArrayList (java.util.ArrayList)1