use of org.opennms.newts.api.Resource in project newts by OpenNMS.
the class ResultProcessorTest method testCalculated.
@Test
public void testCalculated() {
Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.COUNTER).row(900000000).element("m0", 3000).element("m1", // Thu Jul 9 11:00:00 CDT 1998
3000).row(900000300).element("m0", 6000).element("m1", 6000).row(900000600).element("m0", 9000).element("m1", 9000).row(900000900).element("m0", 12000).element("m1", 12000).row(900001200).element("m0", 15000).element("m1", 15000).row(900001500).element("m0", 18000).element("m1", 18000).row(900001800).element("m0", 21000).element("m1", 21000).row(900002100).element("m0", 24000).element("m1", 24000).row(900002400).element("m0", 27000).element("m1", 27000).row(900002700).element("m0", 30000).element("m1", 30000).row(900003000).element("m0", 33000).element("m1", 33000).row(900003300).element("m0", 36000).element("m1", 36000).row(900003600).element("m0", 39000).element("m1", 39000).row(900003900).element("m0", 42000).element("m1", 42000).row(900004200).element("m0", 45000).element("m1", 45000).row(900004500).element("m0", 48000).element("m1", 48000).row(900004800).element("m0", 51000).element("m1", 51000).row(900005100).element("m0", 54000).element("m1", 54000).row(900005400).element("m0", 57000).element("m1", 57000).row(900005700).element("m0", 60000).element("m1", 60000).row(900006000).element("m0", 63000).element("m1", 63000).row(900006300).element("m0", 66000).element("m1", 66000).row(900006600).element("m0", 69000).element("m1", 69000).row(900006900).element("m0", 72000).element("m1", 72000).row(900007200).element("m0", 75000).element("m1", // Thu Jul 9 13:00:00 CDT 1998
75000).build();
// Function to add two values
BinaryFunction sum = new BinaryFunction() {
private static final long serialVersionUID = 0L;
@Override
public double apply(double a, double b) {
return a + b;
}
};
ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("m0", AVERAGE).datasource("m1", AVERAGE).calculate("total", sum, "m0", "m1").export("total");
Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900003600).element("total", 20).row(900007200).element("total", 20).build();
ResultProcessor processor = new ResultProcessor(new Resource("localhost"), Timestamp.fromEpochSeconds(900003600), Timestamp.fromEpochSeconds(900007200), rDescriptor, Duration.minutes(60));
assertRowsEqual(expected, processor.process(testData).iterator());
}
use of org.opennms.newts.api.Resource in project newts by OpenNMS.
the class ExportTest method test.
@Test
public void test() {
// Rows with measurements for "m0", "m1", and "m2".
Iterator<Row<Measurement>> testData = new MeasurementRowsBuilder(new Resource("localhost")).row(1).element("m0", 1).element("m1", 2).element("m2", 3).row(300).element("m0", 1).element("m1", 2).element("m2", 3).row(600).element("m0", 1).element("m1", 2).element("m2", 3).build();
// ResultDescriptor that exports only "m1".
ResultDescriptor rDescriptor = new ResultDescriptor().datasource("m1", null).export("m1");
// Expected results.
Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(1).element("m1", 2).row(300).element("m1", 2).row(600).element("m1", 2).build();
assertRowsEqual(expected, new Export(rDescriptor.getExports(), testData));
}
use of org.opennms.newts.api.Resource in project newts by OpenNMS.
the class PrimaryDataTest method testManyToOneSamples.
@Test
public void testManyToOneSamples() {
// Element interval is less than step size.
Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(0).element("m0", 0).element("m1", 1).row(300).element("m0", 1).element("m1", 2).row(600).element("m0", 2).element("m1", 3).row(900).element("m0", 3).element("m1", 4).row(1200).element("m0", 4).element("m1", 5).row(1500).element("m0", 5).element("m1", 6).row(1800).element("m0", 6).element("m1", 7).row(2100).element("m0", 7).element("m1", 8).build();
// Minimal result descriptor
ResultDescriptor rDescriptor = new ResultDescriptor().step(Duration.seconds(900)).datasource("m0", "m0", Duration.seconds(1800), null).datasource("m1", "m1", Duration.seconds(1800), null);
// Expected results
Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900).element("m0", 2).element("m1", 3).row(1800).element("m0", 5).element("m1", 6).build();
PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(900), Timestamp.fromEpochSeconds(1800), rDescriptor, testData);
assertRowsEqual(expected, primaryData);
}
use of org.opennms.newts.api.Resource in project newts by OpenNMS.
the class CassandraIndexerITCase method testDelete.
@Test
public void testDelete() {
ResourceMetadataCache cache = mock(ResourceMetadataCache.class);
when(cache.get(any(Context.class), any(Resource.class))).thenReturn(Optional.<ResourceMetadata>absent());
MetricRegistry registry = new MetricRegistry();
ContextConfigurations contextConfigurations = new ContextConfigurations();
CassandraSession session = newtsInstance.getCassandraSession();
CassandraIndexingOptions options = new CassandraIndexingOptions.Builder().withHierarchicalIndexing(false).build();
Indexer indexer = new CassandraIndexer(session, 86400, cache, registry, options, new SimpleResourceIdSplitter(), contextConfigurations);
CassandraSearcher searcher = new CassandraSearcher(session, registry, contextConfigurations);
Map<String, String> base = map("meat", "people", "bread", "beer");
List<Sample> samples = Lists.newArrayList();
samples.add(sampleFor(new Resource("aaa", Optional.of(base)), "m0"));
samples.add(sampleFor(new Resource("aab", Optional.of(map(base, "music", "metal", "beverage", "beer"))), "m0"));
samples.add(sampleFor(new Resource("aac:aaa", Optional.of(map(base, "music", "country"))), "m0"));
indexer.update(samples);
assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAnyValue("aaa")).size(), equalTo(2));
indexer.delete(Context.DEFAULT_CONTEXT, new Resource("aaa", Optional.of(base)));
assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAnyValue("aaa")).size(), equalTo(1));
indexer.delete(Context.DEFAULT_CONTEXT, new Resource("aaa", Optional.of(base)));
assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAnyValue("aaa")).size(), equalTo(1));
indexer.delete(Context.DEFAULT_CONTEXT, new Resource("aac:aaa", Optional.of(base)));
assertThat(searcher.search(Context.DEFAULT_CONTEXT, QueryBuilder.matchAnyValue("aaa")).size(), equalTo(0));
}
use of org.opennms.newts.api.Resource in project newts by OpenNMS.
the class CassandraIndexerTest method insertStatementsAreDeduplicatedWhenIndexingManySamples.
@Test
public void insertStatementsAreDeduplicatedWhenIndexingManySamples() {
CassandraSession session = mock(CassandraSession.class);
ArgumentCaptor<Statement> statementCaptor = ArgumentCaptor.forClass(Statement.class);
when(session.executeAsync(statementCaptor.capture())).thenReturn(mock(ResultSetFuture.class));
PreparedStatement statement = mock(PreparedStatement.class);
BoundStatement boundStatement = mock(BoundStatement.class);
when(session.prepare(any(RegularStatement.class))).thenReturn(statement);
when(statement.bind()).thenReturn(boundStatement);
when(boundStatement.setString(any(String.class), any(String.class))).thenReturn(boundStatement);
CassandraIndexingOptions options = new CassandraIndexingOptions.Builder().withHierarchicalIndexing(true).withMaxBatchSize(1).build();
MetricRegistry registry = new MetricRegistry();
GuavaResourceMetadataCache cache = new GuavaResourceMetadataCache(2048, registry);
CassandraIndexer indexer = new CassandraIndexer(session, 0, cache, registry, options, new EscapableResourceIdSplitter(), new ContextConfigurations());
Resource r = new Resource("snmp:1589:vmware5Cpu:2:vmware5Cpu");
List<Sample> samples = Lists.newArrayList();
samples.add(new Sample(Timestamp.now(), r, "CpuCostopSum", MetricType.GAUGE, new Gauge(0)));
samples.add(new Sample(Timestamp.now(), r, "CpuIdleSum", MetricType.GAUGE, new Gauge(19299.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuMaxLdSum", MetricType.GAUGE, new Gauge(0)));
samples.add(new Sample(Timestamp.now(), r, "CpuOverlapSum", MetricType.GAUGE, new Gauge(5.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuRdySum", MetricType.GAUGE, new Gauge(41.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuRunSum", MetricType.GAUGE, new Gauge(619.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuSpwaitSum", MetricType.GAUGE, new Gauge(0)));
samples.add(new Sample(Timestamp.now(), r, "CpuSystemSum", MetricType.GAUGE, new Gauge(0)));
samples.add(new Sample(Timestamp.now(), r, "CpuUsagemhzAvg", MetricType.GAUGE, new Gauge(32.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuUsedSum", MetricType.GAUGE, new Gauge(299.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuWaitSum", MetricType.GAUGE, new Gauge(19343)));
// Index the collection of samples
indexer.update(samples);
// Verify the number of exectuteAsync calls
verify(session, times(20)).executeAsync(any(Statement.class));
}
Aggregations