/** * 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 this RRD. Data will be fetched with the smallest * possible resolution (see RRDTool's * <a href="http://oss.oetiker.ch/rrdtool/doc/rrdfetch.en.html" target="man">rrdfetch man page</a> * for the explanation of the resolution parameter). * * @param consolFun Consolidation function to be used in fetch request. * @param fetchStart Starting timestamp for fetch request. * @param fetchEnd Ending timestamp for fetch request. * @return Request object that should be used to actually fetch data from RRD. */ public FetchRequest createFetchRequest(ConsolFun consolFun, long fetchStart, long fetchEnd) { return createFetchRequest(consolFun, fetchStart, fetchEnd, 1); }
/** * <p>Prepares fetch request to be executed on this RRD. Use returned * <code>FetchRequest</code> object and its {@link FetchRequest#fetchData() fetchData()} * method to actually fetch data from this RRD. Data will be fetched with the smallest * possible resolution (see RRDTool's * <a href="../../../../man/rrdfetch.html" target="man">rrdfetch man page</a> * for the explanation of the resolution parameter).</p> * * @param consolFun Consolidation function to be used in fetch request. Allowed values are * AVERAGE, MIN, MAX and LAST (see {@link ConsolFun} enum). * @param fetchStart Starting timestamp for fetch request. * @param fetchEnd Ending timestamp for fetch request. * @return Request object that should be used to actually fetch data from RRD. */ public FetchRequest createFetchRequest(ConsolFun consolFun, long fetchStart, long fetchEnd) { return createFetchRequest(consolFun, fetchStart, fetchEnd, 1); }
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 { } }
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 { } }
/** * * @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(); }
@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); } }
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); } } } } } }
rrd = getRrd(defSources[i]); lastRrdArchiveUpdateTime = Math.max(lastRrdArchiveUpdateTime, rrd.getLastArchiveUpdateTime()); FetchRequest req = rrd.createFetchRequest(defSources[i].getConsolFun(), tStart, tEndFixed, fetchRequestResolution); req.setFilter(dsNames);
FetchRequest request = rrdDb.createFetchRequest(AVERAGE, start, end); println(request.dump()); log.println(request.dump());