/** * Gets the metric data point at the index i * * @param i the index position of the metric value * @return the metric value */ public double getValue(int i) { return values.get(i); }
/** * Gets the metric data point at the index i * * @param i the index position of the metric value * @return the metric value */ public double getValue(int i) { return values.get(i); }
private static double mean(DoubleList values) { double sum = 0.0; for (int i = 0; i < values.size(); i++) { sum = sum + values.get(i); } return sum / values.size(); }
private double mean() { double sum = 0.0; for (int i = 0; i < size(); i++) { sum = sum + get(i); } return sum / size(); }
private Point of(int index) { return new Point(index, timestamps.get(index), values.get(index)); }
private Point of(int index) { return new Point(index, timestamps.get(index), values.get(index)); }
private static double variance(DoubleList doubles) { double avg = mean(doubles); double sum = 0.0; for (int i = 0; i < doubles.size(); i++) { double value = doubles.get(i); sum += (value - avg) * (value - avg); } return sum / (doubles.size() - 1); }
private double variance() { double avg = mean(); double sum = 0.0; for (int i = 0; i < size(); i++) { double value = get(i); sum += (value - avg) * (value - avg); } return sum / (size() - 1); }
/** * Adds all the given points to the time series * * @param timestamps the timestamps * @param values the values */ public final void addAll(LongList timestamps, DoubleList values) { for (int i = 0; i < timestamps.size(); i++) { add(timestamps.get(i), values.get(i)); } }
/** * Adds all the given points to the time series * * @param timestamps the timestamps * @param values the values */ public final void addAll(LongList timestamps, DoubleList values) { for (int i = 0; i < timestamps.size(); i++) { add(timestamps.get(i), values.get(i)); } }
/** * Performs a linear regression on the data points * * @throws IllegalArgumentException if the lengths of the two arrays are not equal */ public LinearRegression(LongList timestamps, DoubleList values) { double[] x = new double[timestamps.size()]; double[] y = new double[values.size()]; for (int i = 0; i < timestamps.size(); i++) { x[i] = timestamps.get(i); y[i] = values.get(i); } double sumX = 0.0; double sumY = 0.0; for (int i = 0; i < x.length; i++) { sumX += x[i]; sumY += y[i]; } double xBar = sumX / x.length; double yBar = sumY / x.length; double xxBar = 0.0; double xyBar = 0.0; for (int i = 0; i < x.length; i++) { xxBar += (x[i] - xBar) * (x[i] - xBar); xyBar += (x[i] - xBar) * (y[i] - yBar); } intercept = xyBar / xxBar; }
@Test public void testSingle() throws Exception { try (InputStream stream = GraphiteFormatParserTest.class.getResourceAsStream("/opentsdb-http-api-single.json")) { assertNotNull(stream); List<MetricTimeSeries> series = Lists.newArrayList(sut.parse(stream)); // We should have one metric assertThat(series.size(), is(1)); MetricTimeSeries metric = series.get(0); assertThat(metric.getName(), is("sys.cpu.nice")); assertThat(metric.getTimestamps().size(), is(1)); assertThat(metric.getValues().get(0), is(18.0)); assertThat(metric.getTimestamps().get(0), is(1346846400000L)); } }
@Test public void testMultiple() throws Exception { try (InputStream stream = GraphiteFormatParserTest.class.getResourceAsStream("/opentsdb-http-api-multiple.json")) { assertNotNull(stream); List<MetricTimeSeries> series = Lists.newArrayList(sut.parse(stream)); // We should have two metrics assertThat(series.size(), is(2)); MetricTimeSeries first = series.get(0); assertThat(first.getName(), is("sys.cpu.nice")); assertThat(first.getTimestamps().size(), is(2)); assertThat(first.getValues().get(0), is(1.0)); assertThat(first.getTimestamps().get(0), is(1346846400000L)); assertThat(first.getValues().get(1), is(2.0)); assertThat(first.getTimestamps().get(1), is(1346846400100L)); MetricTimeSeries second = series.get(1); assertThat(second.getName(), is("sys.cpu.load")); assertThat(second.getTimestamps().size(), is(1)); assertThat(second.getValues().get(0), is(2.0)); assertThat(second.getTimestamps().get(0), is(1346846400000L)); } } }
@Test public void test() throws Exception { try (InputStream stream = KairosDbFormatParserTest.class.getResourceAsStream("/kairosdb.json")) { assertNotNull(stream); List<MetricTimeSeries> series = Lists.newArrayList(sut.parse(stream)); // We should have two metrics assertThat(series.size(), is(2)); MetricTimeSeries first = series.get(0); assertThat(first.getName(), is("archive.file.tracked")); assertThat(first.getTimestamps().size(), is(1)); assertThat(first.getValues().get(0), is(123.0)); assertThat(first.getTimestamps().get(0), is(1349109376L)); assertThat(first.getAttributesReference().get("host"), is("test")); MetricTimeSeries second = series.get(1); assertThat(second.getName(), is("archive.file.search")); assertThat(second.getTimestamps().size(), is(1)); assertThat(second.getValues().get(0), is(32.1)); assertThat(second.getTimestamps().get(0), is(1349109665L)); assertThat(second.getAttributesReference().get("host"), is("test")); } } }
assertThat(bashSeries.getValues().get(0), is(1.0)); assertThat(bashSeries.getValues().get(1), is(2.0)); assertThat(bashSeries.getValues().get(2), is(3.0)); assertThat(bashSeries.getValues().get(3), is(4.0)); assertThat(bashSeries.getValues().get(4), is(5.0)); assertThat(psSeries.getValues().get(0), is(6.0)); assertThat(psSeries.getValues().get(1), is(7.0)); assertThat(psSeries.getValues().get(2), is(8.0)); assertThat(psSeries.getValues().get(3), is(9.0));
assertThat(server01.getTimestamps().get(0), is(NOW.toEpochMilli())); assertThat(server01.getValues().size(), is(1)); assertThat(server01.getValues().get(0), is(0.67)); assertThat(server01.getAttributesReference().get("host"), is("server01")); assertThat(server02.getTimestamps().get(0), is(1422568543702900L)); assertThat(server02.getValues().size(), is(1)); assertThat(server02.getValues().get(0), is(0.55)); assertThat(server02.getAttributesReference().get("host"), is("server02")); assertThat(server03.getTimestamps().get(1), is(1422568544702900L)); assertThat(server03.getValues().size(), is(2)); assertThat(server03.getValues().get(0), is(2.0)); assertThat(server03.getValues().get(1), is(3.0)); assertThat(server03.getAttributesReference().get("host"), is("server03")); assertThat(server03.getAttributesReference().get("direction"), is("in"));
double point = points.get(i); if (point > threshold) { functionCtx.add(this, true, chronixTimeSeries.getJoinKey());