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);
}
}
}
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);
}
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);
}
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));
}
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());
}
Aggregations