Search in sources :

Example 6 with Observation

use of org.spf4j.tsdb2.avro.Observation in project spf4j by zolyfarkas.

the class RecorderFactoryTest method testCreateScalableQuantizedRecorder.

/**
 * Test of createScalableQuantizedRecorder method, of class RecorderFactory.
 */
@Test
public void testCreateScalableQuantizedRecorder() throws IOException, InterruptedException {
    String forWhat = "test1";
    String unitOfMeasurement = "ms";
    int sampleTime = 1000;
    int factor = 10;
    int lowerMagnitude = 0;
    int higherMagnitude = 3;
    int quantasPerMagnitude = 10;
    CloseableMeasurementRecorder result = RecorderFactory.createScalableQuantizedRecorder2(forWhat, unitOfMeasurement, sampleTime, factor, lowerMagnitude, higherMagnitude, quantasPerMagnitude);
    for (int i = 0; i < 500; i++) {
        result.record(i);
        Thread.sleep(20);
    }
    result.close();
    assertData(forWhat, 124750);
    MeasurementStore store = ProcessMeasurementStore.getMeasurementStore();
    MeasurementStoreQuery query = store.query();
    Collection<Schema> measurements = query.getMeasurements((x) -> forWhat.equals(x));
    Schema m = measurements.iterator().next();
    try (AvroCloseableIterable<Observation> observations = query.getObservations(m, Instant.EPOCH, Instant.now())) {
        for (Observation o : observations) {
            LOG.debug("RAW Obeservation", o);
        }
    }
    try (AvroCloseableIterable<Observation> observations = query.getAggregatedObservations(m, Instant.EPOCH, Instant.now(), 2, TimeUnit.SECONDS)) {
        for (Observation o : observations) {
            LOG.debug("AGG Obeservation", o);
        }
    }
}
Also used : Schema(org.apache.avro.Schema) Observation(org.spf4j.tsdb2.avro.Observation) ProcessMeasurementStore(org.spf4j.perf.impl.ProcessMeasurementStore) Test(org.junit.Test)

Aggregations

Schema (org.apache.avro.Schema)5 Observation (org.spf4j.tsdb2.avro.Observation)5 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 Test (org.junit.Test)2 AvroCloseableIterable (org.spf4j.base.avro.AvroCloseableIterable)2 ProcessMeasurementStore (org.spf4j.perf.impl.ProcessMeasurementStore)2 Beta (com.google.common.annotations.Beta)1 TLongList (gnu.trove.list.TLongList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 THashSet (gnu.trove.set.hash.THashSet)1 BufferedReader (java.io.BufferedReader)1 Closeable (java.io.Closeable)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 UncheckedIOException (java.io.UncheckedIOException)1 Writer (java.io.Writer)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1