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); } }
/** * 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(); }
/** * Method used to calculate datasource values which should be presented on the graph * based on the desired graph width. Each value returned represents a single pixel on the graph. * Corresponding timestamp can be found in the array returned from {@link #getTimestampsPerPixel()} * method. * * @param sourceName Datasource name * @param pixelCount Graph width * @return Per-pixel datasource values * @throws RrdException Thrown if datasource values are not yet calculated (method {@link #processData()} * was not called) */ public double[] getValuesPerPixel(String sourceName, int pixelCount) throws RrdException { setPixelCount(pixelCount); return getValuesPerPixel(sourceName); }
final DataProcessor dproc = new DataProcessor(startInSeconds, endInSeconds); if (maxrows > 0) { dproc.setPixelCount(maxrows); dproc.setFetchRequestResolution(stepInSeconds); dproc.addDatasource(source.getLabel(), rrdFile, source.getEffectiveDataSource(), source.getAggregation()); dproc.processData(); } catch (IOException e) { throw new RrdException("JRB processing failed.", e); final long[] timestamps = dproc.getTimestamps(); columns.put(source.getLabel(), dproc.getValues(source.getLabel())); return new FetchResults(timestamps, columns, dproc.getStep() * 1000, constants, metadata);
DataProcessor dp = new DataProcessor(t1, t2); dp.addDatasource("X", rrdPath, "sun", "AVERAGE"); dp.addDatasource("Y", rrdPath, "shade", "AVERAGE"); dp.addDatasource("Z", "X,Y,+,2,/"); dp.addDatasource("DERIVE[Z]", "Z,PREV(Z),-,STEP,/"); dp.addDatasource("TREND[Z]", "DERIVE[Z],SIGN"); dp.addDatasource("AVG[Z]", "Z", "AVERAGE"); dp.addDatasource("DELTA", "Z,AVG[Z],-"); dp.processData(); System.out.println("Data processed in " + (System.currentTimeMillis() - laptime) + " milliseconds\n---"); System.out.println(dp.dump()); Aggregates agg = dp.getAggregates("X"); System.out.println(agg.dump()); System.out.println("\nAggregates for Y"); agg = dp.getAggregates("Y"); System.out.println(agg.dump()); System.out.println("\n95-percentile for X: " + Util.formatDouble(dp.get95Percentile("X"))); System.out.println("95-percentile for Y: " + Util.formatDouble(dp.get95Percentile("Y"))); System.out.println("\nLast archive update time was: " + dp.getLastRrdArchiveUpdateTime());
protected void addVdefDs(RrdGraphDef graphDef, String sourceName, String[] rhs, double start, double end, Map<String,List<String>> defs) throws RrdException { if (rhs.length == 2) { graphDef.datasource(sourceName, rhs[0], rhs[1]); } else if (rhs.length == 3 && "PERCENT".equals(rhs[2])) { // Is there a better way to do this than with a separate DataProcessor? final double pctRank = Double.valueOf(rhs[1]); final DataProcessor dataProcessor = new DataProcessor((int)start, (int)end); for (final Entry<String, List<String>> entry : defs.entrySet()) { final String dsName = entry.getKey(); final List<String> thisDef = entry.getValue(); if (thisDef.size() == 3) { dataProcessor.addDatasource(dsName, thisDef.get(0), thisDef.get(1), thisDef.get(2)); } else if (thisDef.size() == 1) { dataProcessor.addDatasource(dsName, thisDef.get(0)); } } try { dataProcessor.processData(); } catch (IOException e) { throw new RrdException("Caught IOException: " + e.getMessage()); } double result = dataProcessor.getPercentile(rhs[0], pctRank); ConstantStaticDef csDef = new ConstantStaticDef((long)start, (long)end, result); graphDef.datasource(sourceName, csDef); } }
private void fetchData() throws RrdException, IOException { dproc = new DataProcessor(gdef.startTime, gdef.endTime); dproc.setPoolUsed(gdef.poolUsed); if (gdef.step > 0) { dproc.setStep(gdef.step); } for (Source src : gdef.sources) { src.requestData(dproc); } dproc.processData(); //long[] t = dproc.getTimestamps(); //im.start = t[0]; //im.end = t[t.length - 1]; im.start = gdef.startTime; im.end = gdef.endTime; }
private DataProcessor createDataProcessor(String rpnExpression) throws RrdException { DataProcessor dataProcessor = new DataProcessor(request.getFetchStart(), request.getFetchEnd()); for (String dsName : dsNames) { dataProcessor.addDatasource(dsName, this); } if (rpnExpression != null) { dataProcessor.addDatasource(RPN_SOURCE_NAME, rpnExpression); try { dataProcessor.processData(); } catch (IOException ioe) { // highly unlikely, since all datasources have already calculated values throw new RuntimeException("Impossible error: " + ioe); } } return dataProcessor; } }
@Override void requestData(DataProcessor dproc) { dproc.addDatasource(name, m_sourceName, m_percentile, m_includenan); }
private String xport() throws IOException, RrdException { dproc.processData(); long[] timestamps = dproc.getTimestamps(); for (XPort xport : xports) { xport.values = dproc.getValues(xport.name);
final DataProcessor dbHelper = new DataProcessor(this); // dbHelper is local to onCreate // re-declared and initialized. While the instance variable is null
void assignValues(DataProcessor dproc) throws RrdException { values = dproc.getValues(srcName); }
/** * Dumps timestamps and values of all datasources in a tabelar form. Very useful for debugging. * * @return Dumped object content. * @throws RrdException Thrown if nothing is calculated so far (the method {@link #processData()} * was not called). */ public String dump() throws RrdException { String[] names = getSourceNames(); double[][] values = getValues(); StringBuilder buffer = new StringBuilder(); buffer.append(format("timestamp", 12)); for (String name : names) { buffer.append(format(name, 20)); } buffer.append("\n"); for (int i = 0; i < timestamps.length; i++) { buffer.append(format("" + timestamps[i], 12)); for (int j = 0; j < names.length; j++) { buffer.append(format(Util.formatDouble(values[j][i]), 20)); } buffer.append("\n"); } return buffer.toString(); }
String endStr = getOptionValue("e", "end", DEFAULT_END); long span[] = Util.getTimestamps(startStr, endStr); dproc = new DataProcessor(span[0], span[1]); xports = new ArrayList<XPort>(); long step = parseLong(getOptionValue(null, "step", "1")); long minStep = (long) Math.ceil((span[1] - span[0]) / (double) (maxRows - 1)); step = Math.max(step, minStep); dproc.setStep(step); String[] words = getRemainingWords(); if (words.length < 2) {
/** * Returns an array of all datasource values for all datasources. Each row in this two-dimensional * array represents an array of calculated values for a single datasource. The order of rows is the same * as the order in which datasources were added to this DataProcessor object. * * @return All datasource values for all datasources. The first index is the index of the datasource, * the second index is the index of the datasource value. The number of datasource values is equal * to the number of timestamps returned with {@link #getTimestamps()} method. * @throws RrdException Thrown if invalid datasource name is specified, * or if datasource values are not yet calculated (method {@link #processData()} * was not called) */ public double[][] getValues() throws RrdException { String[] names = getSourceNames(); double[][] values = new double[names.length][]; for (int i = 0; i < names.length; i++) { values[i] = getValues(names[i]); } return values; }
RpnCalculator(String rpnExpression, String sourceName, DataProcessor dataProcessor) throws RrdException { this.rpnExpression = rpnExpression; this.sourceName = sourceName; this.dataProcessor = dataProcessor; this.timestamps = dataProcessor.getTimestamps(); this.timeStep = this.timestamps[1] - this.timestamps[0]; this.calculatedValues = new double[this.timestamps.length]; StringTokenizer st = new StringTokenizer(rpnExpression, ", "); tokens = new Token[st.countTokens()]; for (int i = 0; st.hasMoreTokens(); i++) { tokens[i] = createToken(st.nextToken()); } }
/** * Used by ISPs which charge for bandwidth utilization on a "95th percentile" basis. * <p> * The 95th percentile is the highest source value left when the top 5% of a numerically sorted set * of source data is discarded. It is used as a measure of the peak value used when one discounts * a fair amount for transitory spikes. This makes it markedly different from the average. * <p> * Read more about this topic at * <a href="http://www.red.net/support/resourcecentre/leasedline/percentile.php">Rednet</a> or * <a href="http://www.bytemark.co.uk/support/tech/95thpercentile.html">Bytemark</a>. * * @param sourceName Datasource name * @return 95th percentile of fetched source values * @throws RrdException Thrown if invalid source name is supplied */ public double getPercentile(String sourceName) throws RrdException { return getPercentile(sourceName, DEFAULT_PERCENTILE); }
final DataProcessor dproc = new DataProcessor(startInSeconds, endInSeconds); if (maxrows > 0) { dproc.setPixelCount(maxrows); dproc.setFetchRequestResolution(stepInSeconds); dproc.addDatasource(source.getLabel(), rrdFile, source.getEffectiveDataSource(), source.getAggregation()); dproc.processData(); } catch (IOException e) { throw new RrdException("JRB processing failed.", e); final long[] timestamps = dproc.getTimestamps(); columns.put(source.getLabel(), dproc.getValues(source.getLabel())); return new FetchResults(timestamps, columns, dproc.getStep() * 1000, constants);