/** * Prepares fetch request to be executed on this RRD. Use returned * <code>FetchRequest</code> object and its {@link org.rrd4j.core.FetchRequest#fetchData() fetchData()} * method to actually fetch data from the RRD file. * * @param consolFun Consolidation function to be used in fetch request. * @param fetchStart Starting timestamp for fetch request. * @param fetchEnd Ending timestamp for fetch request. * @param resolution Fetch resolution (see RRDTool's * <a href="http://oss.oetiker.ch/rrdtool/doc/rrdfetch.en.html" target="man">rrdfetch man page</a> for an * explanation of this parameter. * @return Request object that should be used to actually fetch data from RRD */ public FetchRequest createFetchRequest(ConsolFun consolFun, long fetchStart, long fetchEnd, long resolution) { return new FetchRequest(this, consolFun, fetchStart, fetchEnd, resolution); }
String getRrdToolCommand() { return dump(); }
ConsolFun consolFun = request.getConsolFun(); long fetchStart = request.getFetchStart(); long fetchEnd = request.getFetchEnd(); long resolution = request.getResolution(); Archive bestFullMatch = null; Archive bestPartialMatch = null;
@Override public Map<TimeSeriesInfo<Double>, TimeSeriesProcessor<Double>> fetchData(String path, Instant begin, Instant end, List<TimeSeriesInfo<Double>> seriesInfo, boolean bypassCache) throws DataAdapterException { if (this.isClosed()) { throw new IllegalStateException("An attempt was made to fetch data from a closed adapter"); } Path dsPath = Path.of(path); try { FetchRequest request = rrdDbMap.get(dsPath.getParent()).createFetchRequest(ConsolFun.valueOf(dsPath.getFileName().toString()), begin.getEpochSecond(), end.getEpochSecond()); request.setFilter(seriesInfo.stream().map(s -> s.getBinding().getLabel()).toArray(String[]::new)); FetchData data = request.fetchData(); Map<TimeSeriesInfo<Double>, TimeSeriesProcessor<Double>> series = new HashMap<>(); for (int i = 0; i < data.getRowCount(); i++) { ZonedDateTime timeStamp = Instant.ofEpochSecond(data.getTimestamps()[i]).atZone(getTimeZoneId()); for (TimeSeriesInfo<Double> info : seriesInfo) { Double val = data.getValues(info.getBinding().getLabel())[i]; XYChart.Data<ZonedDateTime, Double> point = new XYChart.Data<>(timeStamp, val.isNaN() ? 0 : val); TimeSeriesProcessor<Double> seriesProcessor = series.computeIfAbsent(info, k -> new DoubleTimeSeriesProcessor()); seriesProcessor.addSample(point); } } logger.trace(() -> String.format("Built %d series with %d samples each (%d total samples)", seriesInfo.size(), data.getRowCount(), seriesInfo.size() * data.getRowCount())); return series; } catch (IOException e) { throw new FetchingDataFromAdapterException("IO Error while retrieving data from rrd db", e); } }
public void printStatistics() { if(statSample != null) { try { long time = System.currentTimeMillis() / 1000; FetchRequest minRequest = statDB.createFetchRequest(ConsolFun.AVERAGE, time - 60 , time); FetchData minData = minRequest.fetchData(); double triplesLastMin = minData.getAggregate("triples", ConsolFun.AVERAGE); FetchRequest hourRequest = statDB.createFetchRequest(ConsolFun.AVERAGE, time - (60 * 60) , time); FetchData hourData = hourRequest.fetchData(); double triplesLastHour = hourData.getAggregate("triples", ConsolFun.AVERAGE); if(triplesLastMin != Double.NaN) { log.info("imported {} triples; statistics: {}/sec (last min), {}/sec (last hour)", UnitFormatter.formatSize(handler.triples), UnitFormatter.formatSize(triplesLastMin), UnitFormatter.formatSize(triplesLastHour)); } previous = System.currentTimeMillis(); } catch (IOException e) { log.warn("error updating statistics: {}", e.getMessage()); } } else { } }
FetchData fetchData(FetchRequest request) throws IOException { long arcStep = getArcStep(); long fetchStart = Util.normalize(request.getFetchStart(), arcStep); long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep); if (fetchEnd < request.getFetchEnd()) { fetchEnd += arcStep; String[] dsToFetch = request.getFilter(); if (dsToFetch == null) { dsToFetch = parentDb.getDsNames();
private DataProcessor createDataProcessor(String rpnExpression) { 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; } }
Def(String name, String dsName, FetchData fetchData) { this(name, fetchData.getRequest().getParentDb().getPath(), dsName, fetchData.getRequest().getConsolFun(), fetchData.getRequest().getParentDb().getRrdBackend().getFactory() ); this.fetchData = fetchData; }
FetchData(Archive matchingArchive, FetchRequest request) throws IOException { this.matchingArchive = matchingArchive; this.arcStep = matchingArchive.getArcStep(); this.arcEndTime = matchingArchive.getEndTime(); this.dsNames = request.getFilter(); if (this.dsNames == null) { this.dsNames = matchingArchive.getParentDb().getDsNames(); } this.request = request; }
public Archive findMatchingArchive(FetchRequest request) throws IOException { ConsolFun consolFun = request.getConsolFun(); long fetchStart = request.getFetchStart(); long fetchEnd = request.getFetchEnd(); long resolution = request.getResolution(); Archive bestFullMatch = null, bestPartialMatch = null; long bestStepDiff = 0, bestMatch = 0;
private void fetchRrdData() throws IOException { long tEndFixed = (tEnd == 0) ? Util.getTime() : tEnd; for (int i = 0; i < defSources.length; i++) { if (!defSources[i].isLoaded()) { // not fetched yet Set<String> dsNames = new HashSet<String>(); dsNames.add(defSources[i].getDsName()); // look for all other datasources with the same path and the same consolidation function for (int j = i + 1; j < defSources.length; j++) { if (defSources[i].isCompatibleWith(defSources[j])) { dsNames.add(defSources[j].getDsName()); } } // now we have everything try (RrdDb rrd = getRrd(defSources[i])){ lastRrdArchiveUpdateTime = Math.max(lastRrdArchiveUpdateTime, rrd.getLastArchiveUpdateTime()); FetchRequest req = rrd.createFetchRequest(defSources[i].getConsolFun(), tStart, tEndFixed, fetchRequestResolution); req.setFilter(dsNames); FetchData data = req.fetchData(); defSources[i].setFetchData(data); for (int j = i + 1; j < defSources.length; j++) { if (defSources[i].isCompatibleWith(defSources[j])) { defSources[j].setFetchData(data); } } } } } }
public void printStatistics() { if(statSample != null) { try { long time = System.currentTimeMillis() / 1000; FetchRequest minRequest = statDB.createFetchRequest(ConsolFun.AVERAGE, time - 60 , time); FetchData minData = minRequest.fetchData(); double triplesLastMin = minData.getAggregate("triples", ConsolFun.AVERAGE); FetchRequest hourRequest = statDB.createFetchRequest(ConsolFun.AVERAGE, time - (60 * 60) , time); FetchData hourData = hourRequest.fetchData(); double triplesLastHour = hourData.getAggregate("triples", ConsolFun.AVERAGE); if(triplesLastMin != Double.NaN) { log.info("imported {} triples; statistics: {}/sec (last min), {}/sec (last hour)", UnitFormatter.formatSize(handler.triples), UnitFormatter.formatSize(triplesLastMin), UnitFormatter.formatSize(triplesLastHour)); } previous = System.currentTimeMillis(); } catch (IOException e) { log.warn("error updating statistics: {}", e.getMessage()); } } else { } }
FetchData fetchData(FetchRequest request) throws IOException { long arcStep = getArcStep(); long fetchStart = Util.normalize(request.getFetchStart(), arcStep); long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep); if (fetchEnd < request.getFetchEnd()) { fetchEnd += arcStep; String[] dsToFetch = request.getFilter(); if (dsToFetch == null) { dsToFetch = parentDb.getDsNames();
private DataProcessor createDataProcessor(String rpnExpression) { 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; } }
FetchData(Archive matchingArchive, FetchRequest request) throws IOException { this.matchingArchive = matchingArchive; this.arcStep = matchingArchive.getArcStep(); this.arcEndTime = matchingArchive.getEndTime(); this.dsNames = request.getFilter(); if (this.dsNames == null) { this.dsNames = matchingArchive.getParentDb().getDsNames(); } this.request = request; }
writer.startTag("fetch_data"); writer.startTag("request"); writer.writeTag("file", request.getParentDb().getPath()); writer.writeComment(Util.getDate(request.getFetchStart())); writer.writeTag("start", request.getFetchStart()); writer.writeComment(Util.getDate(request.getFetchEnd())); writer.writeTag("end", request.getFetchEnd()); writer.writeTag("resolution", request.getResolution()); writer.writeTag("cf", request.getConsolFun());
/** * * @throws IOException */ public void update() throws IOException { logger.debug("RRDRequestCounter.update() rrdFileName is {}", rrdFileName); RrdDb rrdDb = new RrdDb(rrdFileName); Sample sample = rrdDb.createSample(); long currentTimeSecs = Util.getTime(); StringBuilder sb = new StringBuilder(); sb.append(currentTimeSecs).append(':'); sb.append(counter.getTotalRequests()).append(':'); sb.append(counter.getFailed()); sample.setAndUpdate(sb.toString()); logger.debug("RRDRequestCounter.update() updated with : {}", sb); rrdDb.close(); logger.debug("RRDRequestCounter.update() succeeded"); logger.debug("RRDRequestCounter.update() let us try to fetch data"); rrdDb = new RrdDb(rrdFileName); if(dumpstart == null) { dumpstart = currentTimeSecs - 100; } FetchRequest fetchRequest = rrdDb.createFetchRequest(ConsolFun.AVERAGE, dumpstart, currentTimeSecs+1); FetchData fetchData = fetchRequest.fetchData(); logger.debug("RRDRequestCounter.update() dump is: {}", fetchData.dump()); rrdDb.close(); }
String getRrdToolCommand() { return dump(); }