Search in sources :

Example 1 with Counter

use of com.netflix.spectator.api.Counter in project kork by spinnaker.

the class StackdriverWriterTest method writeRegistryWithSmallRegistry.

@Test
public void writeRegistryWithSmallRegistry() throws IOException {
    TestableStackdriverWriter spy = spy(new TestableStackdriverWriter(writerConfig.build()));
    Monitoring.Projects.TimeSeries.Create mockCreateMethod = Mockito.mock(Monitoring.Projects.TimeSeries.Create.class);
    DefaultRegistry registry = new DefaultRegistry(clock);
    Counter counterA = registry.counter(idAXY);
    Counter counterB = registry.counter(idBXY);
    counterA.increment(4);
    counterB.increment(10);
    when(timeseriesApi.create(eq("projects/test-project"), any(CreateTimeSeriesRequest.class))).thenReturn(mockCreateMethod);
    when(mockCreateMethod.execute()).thenReturn(null);
    spy.writeRegistry(registry);
    verify(mockCreateMethod, times(1)).execute();
    ArgumentCaptor<CreateTimeSeriesRequest> captor = ArgumentCaptor.forClass(CreateTimeSeriesRequest.class);
    verify(timeseriesApi, times(1)).create(eq("projects/test-project"), captor.capture());
    // A, B, timer count and totalTime.
    Assert.assertEquals(4, captor.getValue().getTimeSeries().size());
}
Also used : Counter(com.netflix.spectator.api.Counter) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Monitoring(com.google.api.services.monitoring.v3.Monitoring) Test(org.junit.Test)

Example 2 with Counter

use of com.netflix.spectator.api.Counter in project iep by Netflix.

the class SpectatorEndpoint method get.

@Override
public Object get(String path) {
    Query q = Query.parse(path);
    return registry.stream().filter(m -> !m.hasExpired()).flatMap(m -> {
        List<Object> ms = new ArrayList<>();
        Map<String, String> tags = toMap(m.id());
        if (m instanceof Counter) {
            add(q, tags, ms, new CounterInfo(tags, ((Counter) m).count()));
        } else if (m instanceof Timer) {
            Timer t = (Timer) m;
            add(q, tags, ms, new TimerInfo(tags, t.totalTime(), t.count()));
        } else if (m instanceof DistributionSummary) {
            DistributionSummary t = (DistributionSummary) m;
            add(q, tags, ms, new DistInfo(tags, t.totalAmount(), t.count()));
        } else if (m instanceof Gauge) {
            Gauge g = (Gauge) m;
            add(q, tags, ms, new GaugeInfo(tags, g.value()));
        }
        return ms.stream();
    }).collect(Collectors.toList());
}
Also used : Gauge(com.netflix.spectator.api.Gauge) Preconditions(com.netflix.spectator.impl.Preconditions) Tag(com.netflix.spectator.api.Tag) Counter(com.netflix.spectator.api.Counter) Set(java.util.Set) HashMap(java.util.HashMap) Deque(java.util.Deque) HttpEndpoint(com.netflix.iep.admin.HttpEndpoint) Id(com.netflix.spectator.api.Id) Collectors(java.util.stream.Collectors) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Timer(com.netflix.spectator.api.Timer) Inject(javax.inject.Inject) List(java.util.List) Registry(com.netflix.spectator.api.Registry) Map(java.util.Map) Pattern(java.util.regex.Pattern) DistributionSummary(com.netflix.spectator.api.DistributionSummary) Measurement(com.netflix.spectator.api.Measurement) ArrayDeque(java.util.ArrayDeque) Gauge(com.netflix.spectator.api.Gauge) DistributionSummary(com.netflix.spectator.api.DistributionSummary) Counter(com.netflix.spectator.api.Counter) Timer(com.netflix.spectator.api.Timer) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Counter (com.netflix.spectator.api.Counter)2 Monitoring (com.google.api.services.monitoring.v3.Monitoring)1 HttpEndpoint (com.netflix.iep.admin.HttpEndpoint)1 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)1 DistributionSummary (com.netflix.spectator.api.DistributionSummary)1 Gauge (com.netflix.spectator.api.Gauge)1 Id (com.netflix.spectator.api.Id)1 Measurement (com.netflix.spectator.api.Measurement)1 Registry (com.netflix.spectator.api.Registry)1 Tag (com.netflix.spectator.api.Tag)1 Timer (com.netflix.spectator.api.Timer)1 Preconditions (com.netflix.spectator.impl.Preconditions)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1