Search in sources :

Example 1 with AggregationFunction

use of org.opennms.newts.api.query.AggregationFunction in project opennms by OpenNMS.

the class NewtsFetchStrategy method getMeasurementsForResourceCallable.

private Callable<Collection<Row<Measurement>>> getMeasurementsForResourceCallable(final String newtsResourceId, final List<Source> listOfSources, final Optional<Timestamp> start, final Optional<Timestamp> end, final LateAggregationParams lag) {
    return new Callable<Collection<Row<Measurement>>>() {

        @Override
        public Collection<Row<Measurement>> call() throws Exception {
            ResultDescriptor resultDescriptor = new ResultDescriptor(lag.getInterval());
            for (Source source : listOfSources) {
                final String metricName = source.getAttribute();
                final String name = source.getLabel();
                final AggregationFunction fn = toAggregationFunction(source.getAggregation());
                resultDescriptor.datasource(name, metricName, lag.getHeartbeat(), fn);
                resultDescriptor.export(name);
            }
            LOG.debug("Querying Newts for resource id {} with result descriptor: {}", newtsResourceId, resultDescriptor);
            Results<Measurement> results = m_sampleRepository.select(m_context, new Resource(newtsResourceId), start, end, resultDescriptor, Optional.of(Duration.millis(lag.getStep())), limitConcurrentAggregationsCallback);
            Collection<Row<Measurement>> rows = results.getRows();
            LOG.debug("Found {} rows.", rows.size());
            return rows;
        }
    };
}
Also used : AggregationFunction(org.opennms.newts.api.query.AggregationFunction) Measurement(org.opennms.newts.api.Measurement) OnmsResource(org.opennms.netmgt.model.OnmsResource) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) Callable(java.util.concurrent.Callable) Source(org.opennms.netmgt.measurements.model.Source)

Aggregations

Callable (java.util.concurrent.Callable)1 Source (org.opennms.netmgt.measurements.model.Source)1 OnmsResource (org.opennms.netmgt.model.OnmsResource)1 Measurement (org.opennms.newts.api.Measurement)1 Resource (org.opennms.newts.api.Resource)1 Row (org.opennms.newts.api.Results.Row)1 AggregationFunction (org.opennms.newts.api.query.AggregationFunction)1 ResultDescriptor (org.opennms.newts.api.query.ResultDescriptor)1