use of com.netflix.spectator.api.Meter in project kork by spinnaker.
the class StackdriverWriterTest method testMeasurementsToTimeSeries.
@Test
public void testMeasurementsToTimeSeries() throws IOException {
Measurement measureAXY = new Measurement(idAXY, clock.monotonicTime(), 1);
Measurement measureBXY = new Measurement(idBXY, clock.monotonicTime(), 2);
DefaultRegistry testRegistry = new DefaultRegistry(clock);
testRegistry.counter(idAXY).increment();
testRegistry.counter(idBXY).increment(2);
// Note this writer is still using the mock Monitoring client stub.
TestableStackdriverWriter spy = spy(new TestableStackdriverWriter(writerConfig.build()));
Meter counterA = testRegistry.counter(idAXY);
Meter counterB = testRegistry.counter(idBXY);
doReturn(new TimeSeries()).when(spy).measurementToTimeSeries(eq(descriptorA.getType()), eq(testRegistry), eq(counterA), eq(measureAXY));
doReturn(new TimeSeries()).when(spy).measurementToTimeSeries(eq(descriptorB.getType()), eq(testRegistry), eq(counterB), eq(measureBXY));
// Just testing the call flow produces descriptors since
// we return empty TimeSeries values.
spy.registryToTimeSeries(testRegistry);
}
use of com.netflix.spectator.api.Meter in project kork by spinnaker.
the class StackdriverWriterTest method testAddMeasurementsToTimeSeries.
@Test
public void testAddMeasurementsToTimeSeries() {
DefaultRegistry testRegistry = new DefaultRegistry(clock);
long millisA = TimeUnit.MILLISECONDS.convert(1472394975L, TimeUnit.SECONDS);
long millisB = millisA + 987;
String timeA = "2016-08-28T14:36:15.000000000Z";
String timeB = "2016-08-28T14:36:15.987000000Z";
Meter timerA = testRegistry.timer(idAXY);
Meter timerB = testRegistry.timer(idBXY);
Measurement measureAXY = new Measurement(idAXY, millisA, 1);
Measurement measureBXY = new Measurement(idBXY, millisB, 20.1);
descriptorRegistrySpy.addExtraTimeSeriesLabel(MetricDescriptorCache.INSTANCE_LABEL, INSTANCE_ID);
Assert.assertEquals(makeTimeSeries(descriptorA, idAXY, 1, timeA), writer.measurementToTimeSeries(descriptorA.getType(), testRegistry, timerA, measureAXY));
Assert.assertEquals(makeTimeSeries(descriptorB, idBXY, 20.1, timeB), writer.measurementToTimeSeries(descriptorB.getType(), testRegistry, timerB, measureBXY));
}
use of com.netflix.spectator.api.Meter in project java-chassis by ServiceComb.
the class MetricsRestPublisher method measure.
@ApiResponses({ @ApiResponse(code = 400, response = String.class, message = "illegal request content") })
@GET
@Path("/")
public Map<String, Double> measure() {
Map<String, Double> measurements = new LinkedHashMap<>();
if (globalRegistry == null) {
return measurements;
}
StringBuilder sb = new StringBuilder();
for (Registry registry : globalRegistry.getRegistries()) {
for (Meter meter : registry) {
meter.measure().forEach(measurement -> {
String key = idToString(measurement.id(), sb);
measurements.put(key, measurement.value());
});
}
}
return measurements;
}
use of com.netflix.spectator.api.Meter in project java-chassis by ServiceComb.
the class TestVertxMetersInitializer method init.
@Test
public void init() throws InterruptedException {
globalRegistry.add(registry);
vertxMetersInitializer.init(globalRegistry, eventBus, null);
logPublisher.init(null, eventBus, null);
VertxUtils.blockDeploy(SharedVertxFactory.getSharedVertx(), TestServerVerticle.class, new DeploymentOptions());
VertxUtils.blockDeploy(SharedVertxFactory.getSharedVertx(), TestClientVerticle.class, new DeploymentOptions());
globalRegistry.poll(1);
List<Meter> meters = Lists.newArrayList(registry.iterator());
List<Measurement> measurements = new ArrayList<>();
for (Meter meter : meters) {
meter.measure().forEach(measurements::add);
}
LogCollector logCollector = new LogCollector();
testLog(logCollector, meters, measurements, true);
logCollector.clear();
testLog(logCollector, meters, measurements, false);
logCollector.teardown();
}
use of com.netflix.spectator.api.Meter in project java-chassis by ServiceComb.
the class GlobalRegistry method poll.
public PolledEvent poll(long secondInterval) {
long msNow = clock.wallTime();
List<Meter> meters = new ArrayList<>();
List<Measurement> measurements = new ArrayList<>();
for (Registry registry : registries) {
SpectatorUtils.removeExpiredMeters(registry);
for (Meter meter : registry) {
if (meter instanceof PeriodMeter) {
((PeriodMeter) meter).calcMeasurements(msNow, secondInterval);
}
meters.add(meter);
meter.measure().forEach(measurements::add);
}
}
return new PolledEvent(meters, measurements);
}
Aggregations