@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); } } } } } }
FetchRequest req = rrd.createFetchRequest(defSources[i].getConsolFun(), tStart, tEndFixed, fetchRequestResolution); req.setFilter(dsNames); FetchData data = req.fetchData(); defSources[i].setFetchData(data);