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());
}
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());
}
Aggregations