private DataProcessor processData(Range range) throws IOException, RrdException { final String dataSourceName = getDataSourceName(); final long endTime = range.getJRobinEndTime(); final long startTime = range.getJRobinStartTime(); final DataProcessor dproc = new DataProcessor(startTime, endTime); dproc.addDatasource("average", rrdFileName, dataSourceName, ConsolFuns.CF_AVERAGE); dproc.setPoolUsed(true); dproc.processData(); return dproc; }
private double get95PercentileValue(Range range) throws IOException { try { final DataProcessor dproc = processData(range); // 95th percentile et non un autre percentile par choix return dproc.get95Percentile("average"); } catch (final RrdException e) { throw createIOException(e); } }
double getMeanValue(Range range) throws IOException { assert range.getPeriod() == null; try { final DataProcessor dproc = processData(range); return dproc.getAggregate("average", ConsolFuns.CF_AVERAGE); } catch (final RrdException e) { throw createIOException(e); } }
private void calculateSDef(SDef sDef) throws RrdException { String defName = sDef.getDefName(); String consolFun = sDef.getConsolFun(); Source source = getSource(defName); if (consolFun.equals("MAXIMUM")) { consolFun = "MAX"; } else if (consolFun.equals("MINIMUM")) { consolFun = "MIN"; } double value = source.getAggregates(tStart, tEnd).getAggregate(consolFun); sDef.setValue(value); }
private void normalizeRrdValues() throws RrdException { Normalizer normalizer = new Normalizer(timestamps); for (Def def : defSources) { long[] rrdTimestamps = def.getRrdTimestamps(); double[] rrdValues = def.getRrdValues(); double[] values = normalizer.normalize(rrdTimestamps, rrdValues); def.setValues(values); } }
private void calculateCDef(CDef cDef) throws RrdException { RpnCalculator calc = new RpnCalculator(cDef.getRpnExpression(), cDef.getName(), this); cDef.setValues(calc.calculateValues()); }
double getPercentile(long tStart, long tEnd, double percentile) throws RrdException { long[] t = getRrdTimestamps(); double[] v = getRrdValues(); Aggregator agg = new Aggregator(t, v); return agg.getPercentile(tStart, tEnd, percentile); }
Aggregates getAggregates(long tStart, long tEnd) throws RrdException { long[] t = getRrdTimestamps(); double[] v = getRrdValues(); Aggregator agg = new Aggregator(t, v); return agg.getAggregates(tStart, tEnd); }
void requestData(DataProcessor dproc) { if (backend == null) { dproc.addDatasource(name, rrdPath, dsName, consolFun); } else { dproc.addDatasource(name, rrdPath, dsName, consolFun, backend); } } }
void calculateValues() { long[] times = getTimestamps(); double[] vals = new double[times.length]; for (int i = 0; i < times.length; i++) { vals[i] = plottable.getValue(times[i]); } setValues(vals); } }
/** * Calculates timestamps which correspond to individual pixels on the graph. * * @param pixelCount Graph width * @return Array of timestamps */ public long[] getTimestampsPerPixel(int pixelCount) { setPixelCount(pixelCount); return getTimestampsPerPixel(); }
/** * Returns all (MIN, MAX, LAST, FIRST, AVERAGE and TOTAL) aggregated values for a single datasource. * * @param sourceName Datasource name * @return Object containing all aggregated values * @throws RrdException Thrown if invalid datasource name is specified, * or if datasource values are not yet calculated (method {@link #processData()} * was not called) */ public Aggregates getAggregates(String sourceName) throws RrdException { Source source = getSource(sourceName); return source.getAggregates(tStart, tEnd); }
double getPercentile(long tStart, long tEnd, double percentile, boolean includenan) throws RrdException { Aggregator agg = new Aggregator(timestamps, values); return agg.getPercentile(tStart, tEnd, percentile, includenan); } }
void setValue(double value) { this.value = value; int count = getTimestamps().length; double[] values = new double[count]; for (int i = 0; i < count; i++) { values[i] = value; } setValues(values); }
/** * Realize the calculation of this definition, over the given time period * * @param tStart the time period start * @param tEnd the time period end * @throws RrdException Thrown if we cannot get a percentile value for the time period. */ public void calculate(long tStart, long tEnd) throws RrdException { if(m_source != null) { this.setValue(m_source.getPercentile(tStart, tEnd, m_percentile)); } }
@Override void setTimestamps(long[] timestamps) { super.setTimestamps(timestamps); //And now also call setValue with the current value, to sort out "values" setValue(m_value); }
/** * Method overriden from the base class. This method will be called by the framework. Call * this method only if you need spline-interpolated values in your code. * * @param timestamp timestamp in seconds * @return inteprolated datasource value */ public double getValue(long timestamp) { return getValue((double) timestamp); }
Aggregates getAggregates(long tStart, long tEnd) throws RrdException { Aggregates agg = new Aggregates(); agg.first = agg.last = agg.min = agg.max = agg.average = value; agg.total = value * (tEnd - tStart); return agg; }
PercentileDef(String name, Source source, double percentile, boolean ignorenan) { super(name); m_percentile = percentile; m_ignorenan = ignorenan; m_source = source; //The best we can do at this point; until this object has it's value realized over a // particular time period (with calculate()), there's not much else to do this.setValue(Double.NaN); }
@Override void requestData(DataProcessor dproc) { dproc.addDatasource(name, m_sourceName, m_percentile, m_includenan); }