Search in sources :

Example 1 with Meter

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);
}
Also used : Measurement(com.netflix.spectator.api.Measurement) Meter(com.netflix.spectator.api.Meter) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Test(org.junit.Test)

Example 2 with Meter

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));
}
Also used : Measurement(com.netflix.spectator.api.Measurement) Meter(com.netflix.spectator.api.Meter) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Test(org.junit.Test)

Example 3 with Meter

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;
}
Also used : Meter(com.netflix.spectator.api.Meter) GlobalRegistry(org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry) Registry(com.netflix.spectator.api.Registry) LinkedHashMap(java.util.LinkedHashMap) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with Meter

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();
}
Also used : Measurement(com.netflix.spectator.api.Measurement) LogCollector(org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector) DeploymentOptions(io.vertx.core.DeploymentOptions) Meter(com.netflix.spectator.api.Meter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with Meter

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);
}
Also used : Measurement(com.netflix.spectator.api.Measurement) PeriodMeter(org.apache.servicecomb.foundation.metrics.meter.PeriodMeter) PeriodMeter(org.apache.servicecomb.foundation.metrics.meter.PeriodMeter) Meter(com.netflix.spectator.api.Meter) PolledEvent(org.apache.servicecomb.foundation.metrics.PolledEvent) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Registry(com.netflix.spectator.api.Registry)

Aggregations

Meter (com.netflix.spectator.api.Meter)8 Measurement (com.netflix.spectator.api.Measurement)5 Registry (com.netflix.spectator.api.Registry)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)3 LinkedHashMap (java.util.LinkedHashMap)2 GlobalRegistry (org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry)2 CompositeRegistry (com.netflix.spectator.api.CompositeRegistry)1 Sample (io.prometheus.client.Collector.MetricFamilySamples.Sample)1 CollectorRegistry (io.prometheus.client.CollectorRegistry)1 ApiResponses (io.swagger.annotations.ApiResponses)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 PolledEvent (org.apache.servicecomb.foundation.metrics.PolledEvent)1 PeriodMeter (org.apache.servicecomb.foundation.metrics.meter.PeriodMeter)1 LogCollector (org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector)1 DefaultPublishModel (org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel)1