protected void finalize() throws Throwable { try { close(); } finally { super.finalize(); } }
private void closeRrdDb() { rrdDbMap.forEach((s, rrdDb) -> { logger.debug(() -> "Closing RRD db " + s); try { rrdDb.close(); } catch (IOException e) { logger.error("Error attempting to close RRD db " + s, e); } }); rrdDbMap.clear(); }
@Override public void close() throws IOException { if (rrdDb == null || rrdDb.isClosed()) return; try { rrdDb.close(); } catch (IOException e) { LOGGER.log(Level.WARNING, e, e::getMessage); } }
/** * @param db */ public final static void releaseRrd(RrdDb db) { try { long start = System.currentTimeMillis(); if(usepool) instance.release(db); else db.close(); long finish = System.currentTimeMillis(); waitTime.addAndGet(finish - start); lockCount.incrementAndGet(); } catch (Exception e) { logger.debug("Strange error " + e); } }
/** * @param db */ public void releaseRrd(RrdDb db) { try { long start = System.currentTimeMillis(); if(usepool) instance.release(db); else db.close(); long finish = System.currentTimeMillis(); waitTime.addAndGet(finish - start); lockCount.incrementAndGet(); } catch (Exception e) { logger.debug("Strange error " + e); } }
public void stopSampling() { if(statSampler != null) { statSampler.shutdown(); } if (diagramUpdater != null) { diagramUpdater.run(); } if(statDB != null) { try { statDB.close(); } catch (IOException e) { log.warn("could not close statistics database..."); } } try { Files.deleteIfExists(statFile); } catch (IOException e) { log.warn("could not cleanup statistics database: {}",e.getMessage()); } }
public synchronized void release(RrdDb rrdDb) throws IOException { // null pointer should not kill the thread, just ignore it if (rrdDb == null) { return; } String canonicalPath = Util.getCanonicalPath(rrdDb.getPath()); if (!rrdMap.containsKey(canonicalPath)) { throw new IllegalStateException("Could not release [" + canonicalPath + "], the file was never requested"); } RrdEntry entry = rrdMap.get(canonicalPath); if (--entry.count <= 0) { // no longer used rrdMap.remove(canonicalPath); notifyAll(); entry.rrdDb.close(); } }
public void stop() { writer.onFinish(); try { if (rrdDb != null) { rrdDb.close(); } } catch (IOException e) { throw new EtmException(e); } }
private void convertFile(String path) { long start = System.currentTimeMillis(); totalCount++; try { File rrdFile = new File(path); print(countFormatter.format(totalCount) + "/" + countFormatter.format(files.length) + " " + rrdFile.getName() + " "); String sourcePath = rrdFile.getCanonicalPath(); String destPath = sourcePath + SUFFIX; RrdDb rrd = new RrdDb(destPath, RrdDb.PREFIX_RRDTool + sourcePath); rrd.close(); goodCount++; double seconds = (System.currentTimeMillis() - start) / 1000.0; println("[OK, " + secondsFormatter.format(seconds) + " sec]"); } catch (Exception e) { badCount++; println("[" + e + "]"); } }
private void releaseRrd(RrdDb rrd, Def def) throws IOException { String backend = def.getBackend(); if (poolUsed && backend == null) { RrdDbPool.getInstance().release(rrd); } else { rrd.close(); } }
/** * Create the probe file * * @throws IOException */ protected void create(ArchivesSet archives) throws IOException { log(Level.INFO, "Need to create rrd"); RrdDef def = getRrdDef(archives); RrdDb rrdDb = new RrdDb(def); rrdDb.close(); }
/** * Performs update of the rrd with the current value of the gauge * @throws IOException */ public void update() throws IOException { logger.debug("RRDRequestExecutionTimeGauge.update() rrdFileName is {}", rrdFileName); RrdDb rrdDb = new RrdDb(rrdFileName); try { Sample sample = rrdDb.createSample(); long currentTimeSecs = Util.getTime(); String update = Long.toString(currentTimeSecs) +':'+ (long) gauge.resetAndGetAverageExecutionTime()+':'; sample.setAndUpdate(update); logger.debug("RRDRequestExecutionTimeGauge.update() updated with : {}", update); } finally { rrdDb.close(); logger.debug("RRDRequestExecutionTimeGauge.update() succeeded"); } }
/** * Sets datasource heartbeat to a new value. * * @param sourcePath Path to exisiting RRD file (will be updated) * @param datasourceName Name of the datasource in the specified RRD file * @param newHeartbeat New datasource heartbeat * @throws IOException Thrown in case of I/O error */ public static void setDsHeartbeat(String sourcePath, String datasourceName, long newHeartbeat) throws IOException { RrdDb rrd = new RrdDb(sourcePath); try { Datasource ds = rrd.getDatasource(datasourceName); ds.setHeartbeat(newHeartbeat); } finally { rrd.close(); } }
/** * Sets datasource heartbeat to a new value. * * @param sourcePath Path to exisiting RRD file (will be updated) * @param dsIndex Index of the datasource in the specified RRD file * @param newHeartbeat New datasource heartbeat * @throws IOException Thrown in case of I/O error */ public static void setDsHeartbeat(String sourcePath, int dsIndex, long newHeartbeat) throws IOException { RrdDb rrd = new RrdDb(sourcePath); try { Datasource ds = rrd.getDatasource(dsIndex); ds.setHeartbeat(newHeartbeat); } finally { rrd.close(); } }
/** * Sets datasource min value to a new value * * @param sourcePath Path to exisiting RRD file (will be updated) * @param datasourceName Name of the datasource in the specified RRD file * @param newMinValue New min value for the datasource * @param filterArchivedValues set to <code>true</code> if archived values less than * <code>newMinValue</code> should be set to NaN; set to false, otherwise. * @throws IOException Thrown in case of I/O error */ public static void setDsMinValue(String sourcePath, String datasourceName, double newMinValue, boolean filterArchivedValues) throws IOException { RrdDb rrd = new RrdDb(sourcePath); try { Datasource ds = rrd.getDatasource(datasourceName); ds.setMinValue(newMinValue, filterArchivedValues); } finally { rrd.close(); } }
/** * Sets single archive's X-files factor to a new value. * * @param sourcePath Path to existing RRD file (will be updated) * @param consolFun Consolidation function of the target archive * @param steps Number of sptes of the target archive * @param newXff New X-files factor for the target archive * @throws IOException Thrown in case of I/O error */ public static void setArcXff(String sourcePath, ConsolFun consolFun, int steps, double newXff) throws IOException { RrdDb rrd = new RrdDb(sourcePath); try { Archive arc = rrd.getArchive(consolFun, steps); arc.setXff(newXff); } finally { rrd.close(); } }
/** * Updates valid value range for the given datasource. * * @param sourcePath Path to exisiting RRD file (will be updated) * @param datasourceName Name of the datasource in the specified RRD file * @param newMinValue New min value for the datasource * @param newMaxValue New max value for the datasource * @param filterArchivedValues set to <code>true</code> if archived values outside * of the specified min/max range should be replaced with NaNs. * @throws IOException Thrown in case of I/O error */ public static void setDsMinMaxValue(String sourcePath, String datasourceName, double newMinValue, double newMaxValue, boolean filterArchivedValues) throws IOException { RrdDb rrd = new RrdDb(sourcePath); try { Datasource ds = rrd.getDatasource(datasourceName); ds.setMinMaxValue(newMinValue, newMaxValue, filterArchivedValues); } finally { rrd.close(); } }
/** * Renames single datasource in the given RRD file. * * @param sourcePath Path to a RRD file * @param oldDsName Old datasource name * @param newDsName New datasource name * @throws IOException Thrown in case of I/O error */ public static void renameDatasource(String sourcePath, String oldDsName, String newDsName) throws IOException { RrdDb rrd = new RrdDb(sourcePath); try { if (rrd.containsDs(oldDsName)) { Datasource datasource = rrd.getDatasource(oldDsName); datasource.setDsName(newDsName); } else { throw new IllegalArgumentException("Could not find datasource [" + oldDsName + "] in file " + sourcePath); } } finally { rrd.close(); } }
/** * Sets datasource max value to a new value. * * @param sourcePath Path to exisiting RRD file (will be updated) * @param datasourceName Name of the datasource in the specified RRD file * @param newMaxValue New max value for the datasource * @param filterArchivedValues set to <code>true</code> if archived values greater than * <code>newMaxValue</code> should be set to NaN; set to false, otherwise. * @throws IOException Thrown in case of I/O error */ public static void setDsMaxValue(String sourcePath, String datasourceName, double newMaxValue, boolean filterArchivedValues) throws IOException { RrdDb rrd = new RrdDb(sourcePath); try { Datasource ds = rrd.getDatasource(datasourceName); ds.setMaxValue(newMaxValue, filterArchivedValues); } finally { rrd.close(); } }
public void testCreateDb() throws Exception { URL resource = Thread.currentThread().getContextClassLoader().getResource("etm/contrib/rrd/rrd4j/resources/basic_db_template.xml"); File path = File.createTempFile("test", ".rrd"); try { path.delete(); Rrd4jUtil rrd4jUtil = new Rrd4jUtil(); rrd4jUtil.createRrdDb(resource, path, null); assertTrue(path.exists()); RrdDb db = new RrdDb(path.getAbsolutePath(), true); assertEquals(4, db.getDsCount()); db.close(); } finally { if (path.exists()) { path.delete(); } } }