Search in sources :

Example 1 with Counter

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

the class TestMonitorManager method checkRegisterMonitorWithoutAnyTags.

@Test
public void checkRegisterMonitorWithoutAnyTags() {
    Counter counter = MonitorManager.getInstance().getCounter("MonitorWithoutAnyTag");
    counter.increment(999);
    Assert.assertTrue(MonitorManager.getInstance().measure().containsKey("MonitorWithoutAnyTag"));
    Assert.assertEquals(999, MonitorManager.getInstance().measure().get("MonitorWithoutAnyTag"), 0);
}
Also used : Counter(com.netflix.servo.monitor.Counter) Test(org.junit.Test)

Example 2 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(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 Counter

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

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

the class MetricTypeTest method givenStepCounter_whenManipulate_thenRateValid.

@Ignore
@Test
public void givenStepCounter_whenManipulate_thenRateValid() throws Exception {
    System.setProperty("servo.pollers", "1000");
    Counter counter = new StepCounter(MonitorConfig.builder("test").build());
    assertEquals("counter should start with rate 0.0", 0.0, counter.getValue());
    counter.increment();
    SECONDS.sleep(1);
    assertEquals("counter rate should have increased to 1.0", 1.0, counter.getValue());
}
Also used : StepCounter(com.netflix.servo.monitor.StepCounter) Counter(com.netflix.servo.monitor.Counter) StepCounter(com.netflix.servo.monitor.StepCounter) BasicCounter(com.netflix.servo.monitor.BasicCounter) PeakRateCounter(com.netflix.servo.monitor.PeakRateCounter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Counter

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

the class MetricTypeTest method givenPeakRateCounter_whenManipulate_thenPeakRateReturn.

@Test
public void givenPeakRateCounter_whenManipulate_thenPeakRateReturn() throws Exception {
    Counter counter = new PeakRateCounter(MonitorConfig.builder("test").build());
    assertEquals("counter should start with 0", 0, counter.getValue().intValue());
    counter.increment();
    SECONDS.sleep(1);
    counter.increment();
    counter.increment();
    assertEquals("peak rate should have be 2", 2, 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) 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