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