/** * <p>Opens an existing RRD with read/write access. * The path will be parsed as an URI and checked against the active factories. * If it's a relative URI (no scheme given, or just a plain path), the default factory will be used.</p> * * @param path Path to existing RRD. * @throws java.io.IOException Thrown in case of I/O error. */ public static RrdDb of(String path) throws IOException { return new RrdDb(path, null, false, null, null); }
/** * <p>Opens an existing RRD with read/write access. * The URI will checked against the active factories. * If it's a relative URI (no scheme given, or just a plain path), the default factory will be used.</p> * * @param uri URI to existing RRD. * @throws java.io.IOException Thrown in case of I/O error. */ public static RrdDb of(URI uri) throws IOException { return new RrdDb(null, uri, false, null, null); }
private RrdDb openRrdDb(Path rrdPath) throws IOException { if ("text/xml".equalsIgnoreCase(Files.probeContentType(rrdPath))) { logger.debug(() -> "Attempting to import as an rrd XML dump"); Path temp = Files.createTempFile("binjr_", "_imported.rrd"); tempPathToCollect.add(temp); return new RrdDb(temp.toUri(), RrdDb.PREFIX_XML + rrdPath.toString()); } //TODO Peek into the rrd file's header to determine its producer rather than wait for an exception to be thrown. try { return new RrdDb(rrdPath.toUri()); } catch (InvalidRrdException e) { // Possibly a rrd db created with RrdTool. // Try to convert and import. logger.debug(() -> "Failed to open " + rrdPath + " as an Rrd4j db: attempting to import as an rrdTool db"); Path temp = Files.createTempFile("binjr_", "_imported.rrd"); tempPathToCollect.add(temp); return new RrdDb(temp.toUri(), RrdDb.PREFIX_RRDTool + rrdPath.toString()); } }
public RrdDb requestRrdDb(String path, String sourcePath) throws IOException { RrdEntry ref = null; try { ref = getUnusedEntry(path); ref.rrdDb = new RrdDb(path, sourcePath); ref.count.set(1); } catch (IOException e) { capacity.release(); throw e; } finally { ref.rlock.release(); } return ref.rrdDb; }
public synchronized RrdDb requestRrdDb(String path, String sourcePath) throws IOException { String canonicalPath = Util.getCanonicalPath(path); while (rrdMap.containsKey(canonicalPath) || rrdMap.size() >= capacity) { try { wait(); } catch (InterruptedException e) { throw new RuntimeException(e); } } RrdDb rrdDb = new RrdDb(canonicalPath, sourcePath); rrdMap.put(canonicalPath, new RrdEntry(rrdDb)); return rrdDb; }
public RrdDb requestRrdDb(RrdDef rrdDef) throws IOException { RrdEntry ref = null; try { ref = getUnusedEntry(rrdDef.getPath()); ref.rrdDb = new RrdDb(rrdDef); ref.count.set(1); } catch (IOException e) { capacity.release(); throw e; } finally { ref.rlock.release(); } return ref.rrdDb; }
public synchronized RrdDb requestRrdDb(RrdDef rrdDef) throws IOException { String canonicalPath = Util.getCanonicalPath(rrdDef.getPath()); while (rrdMap.containsKey(canonicalPath) || rrdMap.size() >= capacity) { try { wait(); } catch (InterruptedException e) { throw new RuntimeException(e); } } RrdDb rrdDb = new RrdDb(rrdDef); rrdMap.put(canonicalPath, new RrdEntry(rrdDb)); return rrdDb; }
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 RrdDb getRrd(Def def) throws IOException { String path = def.getPath(), backend = def.getBackend(); if (poolUsed && backend == null) { return RrdDbPool.getInstance().requestRrdDb(path); } else if (backend != null) { return new RrdDb(path, true, RrdBackendFactory.getFactory(backend)); } else { return new RrdDb(path, true); } }
/** * 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"); } }
public void start() { if ("*".equals(pattern)) { filter = new EtmFilter() { public boolean matches(EtmPoint aEtmPoint) { return true; } }; } else { filter = new RegexEtmFilter(pattern); } try { rrdDb = new RrdDb(rrdFilePath.getAbsolutePath()); } catch (IOException e) { throw new EtmException(e); } writer = new Rrd4jAggregationWriter(rrdDb); writer.onBegin(); }
/** * 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 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(); } }
/** * 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 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(); } } }