Search in sources :

Example 1 with ComputationResult

use of org.graylog2.plugin.dashboards.widgets.ComputationResult in project graylog2-server by Graylog2.

the class QuickvaluesWidgetStrategy method compute.

@Override
public ComputationResult compute() {
    String filter = null;
    if (!isNullOrEmpty(streamId)) {
        filter = "streams:" + streamId;
    }
    final TermsResult terms = searches.terms(field, 50, query, filter, this.timeRange);
    Map<String, Object> result = Maps.newHashMap();
    result.put("terms", terms.getTerms());
    result.put("total", terms.getTotal());
    result.put("other", terms.getOther());
    result.put("missing", terms.getMissing());
    return new ComputationResult(result, terms.took().millis());
}
Also used : ComputationResult(org.graylog2.plugin.dashboards.widgets.ComputationResult) TermsResult(org.graylog2.indexer.results.TermsResult)

Example 2 with ComputationResult

use of org.graylog2.plugin.dashboards.widgets.ComputationResult in project graylog2-server by Graylog2.

the class SearchResultChartWidgetStrategy method compute.

@Override
public ComputationResult compute() {
    String filter = null;
    if (!isNullOrEmpty(streamId)) {
        filter = "streams:" + streamId;
    }
    HistogramResult histogram = searches.histogram(query, interval, filter, this.timeRange);
    return new ComputationResult(histogram.getResults(), histogram.took().millis(), histogram.getHistogramBoundaries());
}
Also used : HistogramResult(org.graylog2.indexer.results.HistogramResult) ComputationResult(org.graylog2.plugin.dashboards.widgets.ComputationResult)

Example 3 with ComputationResult

use of org.graylog2.plugin.dashboards.widgets.ComputationResult in project graylog2-server by Graylog2.

the class SearchResultCountWidgetStrategy method computeInternal.

protected ComputationResult computeInternal(String filter) {
    final TimeRange timeRange = this.timeRange;
    CountResult cr = searches.count(query, timeRange, filter);
    if (trend && timeRange instanceof RelativeRange) {
        DateTime toPrevious = timeRange.getFrom();
        DateTime fromPrevious = toPrevious.minus(Seconds.seconds(((RelativeRange) timeRange).getRange()));
        TimeRange previousTimeRange = AbsoluteRange.create(fromPrevious, toPrevious);
        CountResult previousCr = searches.count(query, previousTimeRange);
        Map<String, Object> results = Maps.newHashMap();
        results.put("now", cr.count());
        results.put("previous", previousCr.count());
        long tookMs = cr.tookMs() + previousCr.tookMs();
        return new ComputationResult(results, tookMs);
    } else {
        return new ComputationResult(cr.count(), cr.tookMs());
    }
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) ComputationResult(org.graylog2.plugin.dashboards.widgets.ComputationResult) CountResult(org.graylog2.indexer.results.CountResult) DateTime(org.joda.time.DateTime)

Example 4 with ComputationResult

use of org.graylog2.plugin.dashboards.widgets.ComputationResult in project graylog2-server by Graylog2.

the class StackedChartWidgetStrategy method compute.

@Override
public ComputationResult compute() {
    String filter = null;
    if (!isNullOrEmpty(streamId)) {
        filter = "streams:" + streamId;
    }
    final List<Map> results = new ArrayList<>(chartSeries.size());
    DateTime from = null;
    DateTime to = null;
    long tookMs = 0;
    for (Series series : chartSeries) {
        try {
            final HistogramResult histogramResult = searches.fieldHistogram(series.query, series.field, Searches.DateHistogramInterval.valueOf(interval.toString().toUpperCase(Locale.ENGLISH)), filter, this.timeRange, "cardinality".equalsIgnoreCase(series.statisticalFunction));
            if (from == null) {
                from = histogramResult.getHistogramBoundaries().getFrom();
            }
            to = histogramResult.getHistogramBoundaries().getTo();
            results.add(histogramResult.getResults());
            tookMs += histogramResult.took().millis();
        } catch (Searches.FieldTypeException e) {
            String msg = "Could not calculate [" + this.getClass().getCanonicalName() + "] widget <" + widgetId + ">. Not a numeric field? The field was [" + series.field + "]";
            LOG.error(msg, e);
            throw new RuntimeException(msg, e);
        }
    }
    final AbsoluteRange computationTimeRange = AbsoluteRange.create(from, to);
    return new ComputationResult(results, tookMs, computationTimeRange);
}
Also used : HistogramResult(org.graylog2.indexer.results.HistogramResult) Searches(org.graylog2.indexer.searches.Searches) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ArrayList(java.util.ArrayList) ComputationResult(org.graylog2.plugin.dashboards.widgets.ComputationResult) DateTime(org.joda.time.DateTime) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 5 with ComputationResult

use of org.graylog2.plugin.dashboards.widgets.ComputationResult in project graylog2-server by Graylog2.

the class StatisticalCountWidgetStrategy method compute.

@Override
public ComputationResult compute() {
    try {
        final String filter;
        if (!isNullOrEmpty(streamId)) {
            filter = "streams:" + streamId;
        } else {
            filter = null;
        }
        final TimeRange timeRange = this.timeRange;
        boolean needsCardinality = statsFunction.equals(StatisticalFunction.CARDINALITY);
        boolean needsCount = statsFunction.equals(StatisticalFunction.COUNT);
        final FieldStatsResult fieldStatsResult = getSearches().fieldStats(field, query, filter, timeRange, needsCardinality, !(needsCount || needsCardinality), needsCount);
        if (trend && timeRange instanceof RelativeRange) {
            DateTime toPrevious = timeRange.getFrom();
            DateTime fromPrevious = toPrevious.minus(Seconds.seconds(((RelativeRange) timeRange).getRange()));
            TimeRange previousTimeRange = AbsoluteRange.create(fromPrevious, toPrevious);
            final FieldStatsResult previousFieldStatsResult = getSearches().fieldStats(field, query, filter, previousTimeRange, needsCardinality, !(needsCount || needsCardinality), needsCount);
            Map<String, Object> results = Maps.newHashMap();
            results.put("now", getStatisticalValue(fieldStatsResult));
            results.put("previous", getStatisticalValue(previousFieldStatsResult));
            long tookMs = fieldStatsResult.took().millis() + previousFieldStatsResult.took().millis();
            return new ComputationResult(results, tookMs);
        } else {
            return new ComputationResult(getStatisticalValue(fieldStatsResult), fieldStatsResult.took().millis());
        }
    } catch (Searches.FieldTypeException e) {
        log.warn("Invalid field provided, returning 'NaN'", e);
        return new ComputationResult(Double.NaN, 0);
    }
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) FieldStatsResult(org.graylog2.indexer.results.FieldStatsResult) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) Searches(org.graylog2.indexer.searches.Searches) ComputationResult(org.graylog2.plugin.dashboards.widgets.ComputationResult) DateTime(org.joda.time.DateTime)

Aggregations

ComputationResult (org.graylog2.plugin.dashboards.widgets.ComputationResult)6 DateTime (org.joda.time.DateTime)3 HistogramResult (org.graylog2.indexer.results.HistogramResult)2 Searches (org.graylog2.indexer.searches.Searches)2 RelativeRange (org.graylog2.plugin.indexer.searches.timeranges.RelativeRange)2 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CountResult (org.graylog2.indexer.results.CountResult)1 FieldStatsResult (org.graylog2.indexer.results.FieldStatsResult)1 TermsResult (org.graylog2.indexer.results.TermsResult)1 WidgetStrategy (org.graylog2.plugin.dashboards.widgets.WidgetStrategy)1 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)1