Search in sources :

Example 1 with Metric

use of org.apache.storm.metricstore.Metric in project storm by apache.

the class Nimbus method processWorkerMetrics.

@Override
public void processWorkerMetrics(WorkerMetrics metrics) throws TException {
    processWorkerMetricsCalls.mark();
    checkAuthorization(null, null, "processWorkerMetrics");
    if (this.metricsStore == null) {
        return;
    }
    for (WorkerMetricPoint m : metrics.get_metricList().get_metrics()) {
        try {
            Metric metric = new Metric(m.get_metricName(), m.get_timestamp(), metrics.get_topologyId(), m.get_metricValue(), m.get_componentId(), m.get_executorId(), metrics.get_hostname(), m.get_streamId(), metrics.get_port(), AggLevel.AGG_LEVEL_NONE);
            this.metricsStore.insert(metric);
        } catch (Exception e) {
            LOG.error("Failed to save metric", e);
        }
    }
}
Also used : WorkerMetricPoint(org.apache.storm.generated.WorkerMetricPoint) Metric(org.apache.storm.metricstore.Metric) WrappedAuthorizationException(org.apache.storm.utils.WrappedAuthorizationException) IOException(java.io.IOException) IllegalStateException(org.apache.storm.generated.IllegalStateException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException) WrappedInvalidTopologyException(org.apache.storm.utils.WrappedInvalidTopologyException) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) WrappedAlreadyAliveException(org.apache.storm.utils.WrappedAlreadyAliveException) InterruptedIOException(java.io.InterruptedIOException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) TException(org.apache.storm.thrift.TException) WrappedIllegalStateException(org.apache.storm.utils.WrappedIllegalStateException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Example 2 with Metric

use of org.apache.storm.metricstore.Metric in project storm by apache.

the class RocksDbValueTest method testMetricConstructor.

@Test
public void testMetricConstructor() throws MetricException {
    Metric m = new Metric("cpu", 1L, "myTopologyId123", 1, "componentId1", "executorId1", "hostname1", "streamid1", 7777, AggLevel.AGG_LEVEL_NONE);
    Metric m2 = new Metric(m);
    Metric m3 = new Metric(m);
    m.addValue(238);
    RocksDbValue value = new RocksDbValue(m);
    value.populateMetric(m2);
    Assert.assertEquals(m.getValue(), m2.getValue(), 0x001);
    Assert.assertEquals(m.getCount(), m2.getCount(), 0x001);
    Assert.assertEquals(m.getSum(), m2.getSum(), 0x001);
    Assert.assertEquals(m.getMin(), m2.getMin(), 0x001);
    Assert.assertEquals(m.getMax(), m2.getMax(), 0x001);
    RocksDbValue value2 = new RocksDbValue(value.getRaw());
    value2.populateMetric(m3);
    Assert.assertEquals(m.getValue(), m3.getValue(), 0x001);
    Assert.assertEquals(m.getCount(), m3.getCount(), 0x001);
    Assert.assertEquals(m.getSum(), m3.getSum(), 0x001);
    Assert.assertEquals(m.getMin(), m3.getMin(), 0x001);
    Assert.assertEquals(m.getMax(), m3.getMax(), 0x001);
}
Also used : Metric(org.apache.storm.metricstore.Metric) Test(org.junit.Test)

Example 3 with Metric

use of org.apache.storm.metricstore.Metric in project storm by apache.

the class RocksDbStoreTest method testPopulateFailure.

@Test
public void testPopulateFailure() throws Exception {
    Metric m = new Metric("cpu", 3000L, "myTopologyId456", 1.0, "componentId2", "executorId2", "hostname2", "streamid2", 7778, AggLevel.AGG_LEVEL_NONE);
    store.insert(m);
    waitForInsertFinish(m);
    Metric toFind = new Metric(m);
    toFind.setTopologyId("somethingBogus");
    boolean res = store.populateValue(toFind);
    Assert.assertEquals(false, res);
}
Also used : Metric(org.apache.storm.metricstore.Metric) Test(org.junit.Test)

Example 4 with Metric

use of org.apache.storm.metricstore.Metric in project storm by apache.

the class RocksDbStoreTest method waitForInsertFinish.

private void waitForInsertFinish(Metric m) throws Exception {
    Metric last = new Metric(m);
    int attempts = 0;
    do {
        Thread.sleep(1);
        attempts++;
        if (attempts > 5000) {
            throw new Exception("Insertion timing out");
        }
    } while (!store.populateValue(last));
}
Also used : Metric(org.apache.storm.metricstore.Metric) MetricException(org.apache.storm.metricstore.MetricException) IOException(java.io.IOException)

Example 5 with Metric

use of org.apache.storm.metricstore.Metric in project storm by apache.

the class RocksDbStoreTest method testAggregation.

@Test
public void testAggregation() throws Exception {
    double sum0 = 0.0;
    double sum1 = 0.0;
    double sum10 = 0.0;
    double sum60 = 0.0;
    Metric toPopulate = null;
    for (int i = 0; i < 20; i++) {
        double value = 5 + i;
        long timestamp = 1L + i * 60 * 1000;
        Metric m = new Metric("cpu", timestamp, "myTopologyId123", value, "componentId1", "executorId1", "hostname1", "streamid1", 7777, AggLevel.AGG_LEVEL_NONE);
        toPopulate = new Metric(m);
        store.insert(m);
        if (timestamp < 60 * 1000) {
            sum0 += value;
            sum1 += value;
            sum10 += value;
            sum60 += value;
        } else if (timestamp < 600 * 1000) {
            sum10 += value;
            sum60 += value;
        } else {
            sum60 += value;
        }
    }
    waitForInsertFinish(toPopulate);
    toPopulate.setTimestamp(1L);
    toPopulate.setAggLevel(AggLevel.AGG_LEVEL_NONE);
    boolean res = store.populateValue(toPopulate);
    Assert.assertEquals(true, res);
    Assert.assertEquals(sum0, toPopulate.getSum(), 0.001);
    Assert.assertEquals(sum0, toPopulate.getValue(), 0.001);
    Assert.assertEquals(5.0, toPopulate.getMin(), 0.001);
    Assert.assertEquals(5.0, toPopulate.getMax(), 0.001);
    Assert.assertEquals(1, toPopulate.getCount());
    toPopulate.setTimestamp(0L);
    toPopulate.setAggLevel(AggLevel.AGG_LEVEL_1_MIN);
    res = store.populateValue(toPopulate);
    Assert.assertEquals(true, res);
    Assert.assertEquals(sum1, toPopulate.getSum(), 0.001);
    Assert.assertEquals(sum1, toPopulate.getValue(), 0.001);
    Assert.assertEquals(5.0, toPopulate.getMin(), 0.001);
    Assert.assertEquals(5.0, toPopulate.getMax(), 0.001);
    Assert.assertEquals(1, toPopulate.getCount());
    toPopulate.setTimestamp(0L);
    toPopulate.setAggLevel(AggLevel.AGG_LEVEL_10_MIN);
    res = store.populateValue(toPopulate);
    Assert.assertEquals(true, res);
    Assert.assertEquals(sum10, toPopulate.getSum(), 0.001);
    Assert.assertEquals(sum10 / 10.0, toPopulate.getValue(), 0.001);
    Assert.assertEquals(5.0, toPopulate.getMin(), 0.001);
    Assert.assertEquals(14.0, toPopulate.getMax(), 0.001);
    Assert.assertEquals(10, toPopulate.getCount());
    toPopulate.setTimestamp(0L);
    toPopulate.setAggLevel(AggLevel.AGG_LEVEL_60_MIN);
    res = store.populateValue(toPopulate);
    Assert.assertEquals(true, res);
    Assert.assertEquals(sum60, toPopulate.getSum(), 0.001);
    Assert.assertEquals(sum60 / 20.0, toPopulate.getValue(), 0.001);
    Assert.assertEquals(5.0, toPopulate.getMin(), 0.001);
    Assert.assertEquals(24.0, toPopulate.getMax(), 0.001);
    Assert.assertEquals(20, toPopulate.getCount());
}
Also used : Metric(org.apache.storm.metricstore.Metric) Test(org.junit.Test)

Aggregations

Metric (org.apache.storm.metricstore.Metric)10 Test (org.junit.Test)5 MetricException (org.apache.storm.metricstore.MetricException)3 IOException (java.io.IOException)2 AggLevel (org.apache.storm.metricstore.AggLevel)2 FilterOptions (org.apache.storm.metricstore.FilterOptions)2 RocksDBException (org.rocksdb.RocksDBException)2 InterruptedIOException (java.io.InterruptedIOException)1 BindException (java.net.BindException)1 HashMap (java.util.HashMap)1 ListIterator (java.util.ListIterator)1 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)1 AuthorizationException (org.apache.storm.generated.AuthorizationException)1 IllegalStateException (org.apache.storm.generated.IllegalStateException)1 InvalidTopologyException (org.apache.storm.generated.InvalidTopologyException)1 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)1 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)1 NotAliveException (org.apache.storm.generated.NotAliveException)1 WorkerMetricPoint (org.apache.storm.generated.WorkerMetricPoint)1 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)1