Search in sources :

Example 6 with Measurement

use of com.netflix.spectator.api.Measurement 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 7 with Measurement

use of com.netflix.spectator.api.Measurement 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 8 with Measurement

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

the class BaseServerEndpoint method getMetrics.

private Object getMetrics() {
    List<Object> metrics = new ArrayList<>();
    for (Meter meter : registry) {
        for (Measurement m : meter.measure()) {
            if (Double.isFinite(m.value())) {
                Map<String, Object> datapoint = new LinkedHashMap<>();
                datapoint.put("name", m.id().name());
                datapoint.put("tags", encodeTags(m.id()));
                datapoint.put("timestamp", m.timestamp());
                datapoint.put("value", m.value());
                metrics.add(datapoint);
            }
        }
    }
    return metrics;
}
Also used : Measurement(com.netflix.spectator.api.Measurement) Meter(com.netflix.spectator.api.Meter) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Measurement (com.netflix.spectator.api.Measurement)8 Id (com.netflix.spectator.api.Id)3 Meter (com.netflix.spectator.api.Meter)3 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Tag (com.netflix.spectator.api.Tag)1 ConfigParams (com.netflix.spectator.stackdriver.ConfigParams)1 StackdriverWriter (com.netflix.spectator.stackdriver.StackdriverWriter)1 InetAddress (java.net.InetAddress)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Predicate (java.util.function.Predicate)1 MeasurementNode (org.apache.servicecomb.foundation.metrics.publish.spectator.MeasurementNode)1 Logger (org.slf4j.Logger)1 Bean (org.springframework.context.annotation.Bean)1 Scheduler (rx.Scheduler)1