Search in sources :

Example 16 with DataPoint

use of net.opentsdb.core.DataPoint in project opentsdb by OpenTSDB.

the class TestMovingAverage method evaluateWindow6dps.

@Test
public void evaluateWindow6dps() throws Exception {
    params.add("6");
    final DataPoints[] results = func.evaluate(data_query, query_results, params);
    assertEquals(1, results.length);
    assertEquals(METRIC, results[0].metricName());
    long ts = START_TIME;
    double v = 0;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertFalse(dp.isInteger());
        assertEquals(v, dp.doubleValue(), 0.001);
        ts += INTERVAL;
    }
}
Also used : DataPoint(net.opentsdb.core.DataPoint) DataPoints(net.opentsdb.core.DataPoints) Test(org.junit.Test) SeekableViewsForTest(net.opentsdb.core.SeekableViewsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with DataPoint

use of net.opentsdb.core.DataPoint in project opentsdb by OpenTSDB.

the class TestMovingAverage method evaluateWindow4min.

@Test
public void evaluateWindow4min() throws Exception {
    params.add("'4min'");
    final DataPoints[] results = func.evaluate(data_query, query_results, params);
    assertEquals(1, results.length);
    assertEquals(METRIC, results[0].metricName());
    long ts = START_TIME;
    double v = 0;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertFalse(dp.isInteger());
        assertEquals(v, dp.doubleValue(), 0.001);
        ts += INTERVAL;
        if (ts == 1356998640000L) {
            v = 3.5;
        }
    }
}
Also used : DataPoint(net.opentsdb.core.DataPoint) DataPoints(net.opentsdb.core.DataPoints) Test(org.junit.Test) SeekableViewsForTest(net.opentsdb.core.SeekableViewsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with DataPoint

use of net.opentsdb.core.DataPoint in project opentsdb by OpenTSDB.

the class TestMovingAverage method evaluateWindow2dps.

@Test
public void evaluateWindow2dps() throws Exception {
    params.add("2");
    final DataPoints[] results = func.evaluate(data_query, query_results, params);
    assertEquals(1, results.length);
    assertEquals(METRIC, results[0].metricName());
    long ts = START_TIME;
    double v = 0;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertFalse(dp.isInteger());
        assertEquals(v, dp.doubleValue(), 0.001);
        ts += INTERVAL;
        if (v < 1) {
            v = 1.5;
        } else {
            v += 1;
        }
    }
}
Also used : DataPoint(net.opentsdb.core.DataPoint) DataPoints(net.opentsdb.core.DataPoints) Test(org.junit.Test) SeekableViewsForTest(net.opentsdb.core.SeekableViewsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with DataPoint

use of net.opentsdb.core.DataPoint in project opentsdb by OpenTSDB.

the class TestMovingAverage method evaluateSubQuery.

@Test
public void evaluateSubQuery() throws Exception {
    params.add("1");
    SeekableView view2 = SeekableViewsForTest.generator(START_TIME, INTERVAL, NUM_POINTS, true, 10, 1);
    DataPoints dps2 = PowerMockito.mock(DataPoints.class);
    when(dps2.iterator()).thenReturn(view2);
    when(dps2.metricNameAsync()).thenReturn(Deferred.fromResult("sys.mem"));
    DataPoints[] group_bys2 = new DataPoints[] { dps2 };
    query_results.add(group_bys2);
    final DataPoints[] results = func.evaluate(data_query, query_results, params);
    assertEquals(2, results.length);
    assertEquals(METRIC, results[0].metricName());
    assertEquals("sys.mem", results[1].metricName());
    long ts = START_TIME;
    double v = 1;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertFalse(dp.isInteger());
        assertEquals(v, dp.doubleValue(), 0.001);
        ts += INTERVAL;
        v += 1;
    }
    ts = START_TIME;
    v = 10;
    for (DataPoint dp : results[1]) {
        assertEquals(ts, dp.timestamp());
        assertFalse(dp.isInteger());
        assertEquals(v, dp.doubleValue(), 0.001);
        ts += INTERVAL;
        v += 1;
    }
}
Also used : DataPoint(net.opentsdb.core.DataPoint) SeekableView(net.opentsdb.core.SeekableView) DataPoints(net.opentsdb.core.DataPoints) Test(org.junit.Test) SeekableViewsForTest(net.opentsdb.core.SeekableViewsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 20 with DataPoint

use of net.opentsdb.core.DataPoint in project opentsdb by OpenTSDB.

the class CliQuery method doQuery.

private static Plot doQuery(final TSDB tsdb, final String[] args, final boolean want_plot) {
    final ArrayList<String> plotparams = new ArrayList<String>();
    final ArrayList<Query> queries = new ArrayList<Query>();
    final ArrayList<String> plotoptions = new ArrayList<String>();
    parseCommandLineQuery(args, tsdb, queries, plotparams, plotoptions);
    if (queries.isEmpty()) {
        usage(null, "Not enough arguments, need at least one query.", 2);
    }
    final Plot plot = (want_plot ? new Plot(queries.get(0).getStartTime(), queries.get(0).getEndTime()) : null);
    if (want_plot) {
        plot.setParams(parsePlotParams(plotparams));
    }
    final int nqueries = queries.size();
    for (int i = 0; i < nqueries; i++) {
        // TODO(tsuna): Optimization: run each query in parallel.
        final StringBuilder buf = want_plot ? null : new StringBuilder();
        for (final DataPoints datapoints : queries.get(i).run()) {
            if (want_plot) {
                plot.add(datapoints, plotoptions.get(i));
            } else {
                final String metric = datapoints.metricName();
                final String tagz = datapoints.getTags().toString();
                for (final DataPoint datapoint : datapoints) {
                    buf.append(metric).append(' ').append(datapoint.timestamp()).append(' ');
                    if (datapoint.isInteger()) {
                        buf.append(datapoint.longValue());
                    } else {
                        buf.append(String.format("%f", datapoint.doubleValue()));
                    }
                    buf.append(' ').append(tagz).append('\n');
                    System.out.print(buf);
                    buf.delete(0, buf.length());
                }
            }
        }
    }
    return plot;
}
Also used : Query(net.opentsdb.core.Query) DataPoint(net.opentsdb.core.DataPoint) Plot(net.opentsdb.graph.Plot) ArrayList(java.util.ArrayList) DataPoints(net.opentsdb.core.DataPoints) DataPoint(net.opentsdb.core.DataPoint)

Aggregations

DataPoint (net.opentsdb.core.DataPoint)60 DataPoints (net.opentsdb.core.DataPoints)55 Test (org.junit.Test)49 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)49 SeekableViewsForTest (net.opentsdb.core.SeekableViewsForTest)47 SeekableView (net.opentsdb.core.SeekableView)46 ArrayList (java.util.ArrayList)9 MutableDataPoint (net.opentsdb.core.MutableDataPoint)7 IOException (java.io.IOException)3 Map (java.util.Map)3 AggregationIterator (net.opentsdb.core.AggregationIterator)3 Callback (com.stumbleupon.async.Callback)2 Deferred (com.stumbleupon.async.Deferred)2 PrintWriter (java.io.PrintWriter)2 HashMap (java.util.HashMap)2 Query (net.opentsdb.core.Query)2 TSSubQuery (net.opentsdb.core.TSSubQuery)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1