Search in sources :

Example 6 with Counter

use of com.netflix.servo.monitor.Counter in project incubator-servicecomb-java-chassis by apache.

the class MonitorManager method getCounter.

public Counter getCounter(Function<MonitorConfig, Counter> function, String name, String... tags) {
    validateMonitorNameAndTags(name, tags);
    return counters.computeIfAbsent(getMonitorKey(name, tags), f -> {
        Counter counter = function.apply(getConfig(name, tags));
        basicMonitorRegistry.register(counter);
        return counter;
    });
}
Also used : Counter(com.netflix.servo.monitor.Counter) BasicCounter(com.netflix.servo.monitor.BasicCounter)

Example 7 with Counter

use of com.netflix.servo.monitor.Counter 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)

Example 8 with Counter

use of com.netflix.servo.monitor.Counter in project tutorials by eugenp.

the class MetricTypeTest method givenDefaultCounter_whenManipulate_thenCountValid.

@Test
public void givenDefaultCounter_whenManipulate_thenCountValid() {
    Counter counter = Monitors.newCounter("test");
    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) Test(org.junit.Test)

Aggregations

Counter (com.netflix.servo.monitor.Counter)8 BasicCounter (com.netflix.servo.monitor.BasicCounter)7 Test (org.junit.Test)6 PeakRateCounter (com.netflix.servo.monitor.PeakRateCounter)4 StepCounter (com.netflix.servo.monitor.StepCounter)4 Ignore (org.junit.Ignore)1