RrdNode(RrdDb rrd, int dsIndex, int arcIndex) throws IOException { // archive node this.dsIndex = dsIndex; this.arcIndex = arcIndex; ArcDef[] arcDefs = rrd.getRrdDef().getArcDefs(); label = arcDefs[arcIndex].dump(); }
RrdNode(RrdDb rrd, int dsIndex) throws IOException { // datasource node this.dsIndex = dsIndex; RrdDef def = rrd.getRrdDef(); DsDef[] dsDefs = def.getDsDefs(); label = dsDefs[dsIndex].dump(); }
private static long extractStep(RrdDb aDb) { try { return aDb.getRrdDef().getStep(); } catch (IOException e) { throw new EtmException(e); } }
if (rrd.getRrdDef().getEstimatedSize() == files[i].length() && rrd.getDatasource(0).getHeartbeat() == heartbeat && rrd.getDatasource(1).getHeartbeat() == heartbeat) {
private void fillGraphCombo() { try { RrdDb rrdDb = new RrdDb(sourcePath, true); try { RrdDef rrdDef = rrdDb.getRrdDef(); final DsDef[] dsDefs = rrdDef.getDsDefs(); final ArcDef[] arcDefs = rrdDef.getArcDefs(); GraphComboItem[] items = new GraphComboItem[rrdDef.getDsCount() * rrdDef.getArcCount()]; int selectedItem = -1; for (int i = 0, k = 0; i < rrdDef.getDsCount(); i++) { for (int j = 0; j < rrdDef.getArcCount(); k++, j++) { String description = dsDefs[i].dump() + " " + arcDefs[j].dump(); items[k] = new GraphComboItem(description, i, j); if (i == dsIndex && j == arcIndex) { selectedItem = k; } } } graphCombo.setModel(new DefaultComboBoxModel(items)); graphCombo.setSelectedIndex(selectedItem); } finally { rrdDb.close(); } } catch (Exception e) { Util.error(this, e); } }
/** * Creates a new RRD file with one more archive in it. RRD file is created based on the * existing one (the original RRD file is not modified at all). All data from * the original RRD file is copied to the new one. * * @param sourcePath path to a RRD file to import data from (will not be modified) * @param destPath path to a new RRD file (will be created) * @param newArchive Archive definition to be added to the new RRD file * @throws IOException Thrown in case of I/O error */ public static void addArchive(String sourcePath, String destPath, ArcDef newArchive) throws IOException { if (Util.sameFilePath(sourcePath, destPath)) { throw new IllegalArgumentException("Source and destination paths are the same"); } RrdDb rrdSource = new RrdDb(sourcePath); try { RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); rrdDef.addArchive(newArchive); RrdDb rrdDest = new RrdDb(rrdDef); try { rrdSource.copyStateTo(rrdDest); } finally { rrdDest.close(); } } finally { rrdSource.close(); } }
/** * Creates a new RRD file with one archive removed. RRD file is created based on the * existing one (the original RRD file is not modified at all). All relevant data from * the original RRD file is copied to the new one. * * @param sourcePath path to a RRD file to import data from (will not be modified) * @param destPath path to a new RRD file (will be created) * @param consolFun Consolidation function of Archive which should be removed * @param steps Number of steps for Archive which should be removed * @throws IOException Thrown in case of I/O error */ public static void removeArchive(String sourcePath, String destPath, ConsolFun consolFun, int steps) throws IOException { if (Util.sameFilePath(sourcePath, destPath)) { throw new IllegalArgumentException("Source and destination paths are the same"); } RrdDb rrdSource = new RrdDb(sourcePath); try { RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); rrdDef.removeArchive(consolFun, steps); RrdDb rrdDest = new RrdDb(rrdDef); try { rrdSource.copyStateTo(rrdDest); } finally { rrdDest.close(); } } finally { rrdSource.close(); } }
RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); for (DsDef newDatasource : newDatasources) {
/** * Creates a new RRD file with one datasource removed. RRD file is created based on the * existing one (the original RRD file is not modified at all). All remaining data from * the original RRD file is copied to the new one. * * @param sourcePath path to a RRD file to import data from (will not be modified) * @param destPath path to a new RRD file (will be created) * @param dsName Name of the Datasource to be removed from the new RRD file * @throws IOException Thrown in case of I/O error */ public static void removeDatasource(String sourcePath, String destPath, String dsName) throws IOException { if (Util.sameFilePath(sourcePath, destPath)) { throw new IllegalArgumentException("Source and destination paths are the same"); } RrdDb rrdSource = new RrdDb(sourcePath); try { RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); rrdDef.removeDatasource(dsName); RrdDb rrdDest = new RrdDb(rrdDef); try { rrdSource.copyStateTo(rrdDest); } finally { rrdDest.close(); } } finally { rrdSource.close(); } }
RrdDef rrdDef = rrdSource.getRrdDef(); ArcDef arcDef = rrdDef.findArchive(consolFun, numSteps); if (arcDef.getRows() != newRows) {
/** * Creates a new RRD file with one more archive in it. RRD file is created based on the * existing one (the original RRD file is not modified at all). All data from * the original RRD file is copied to the new one. * * @param sourcePath path to a RRD file to import data from (will not be modified) * @param destPath path to a new RRD file (will be created) * @param newArchive Archive definition to be added to the new RRD file * @throws java.io.IOException Thrown in case of I/O error */ public static void addArchive(String sourcePath, String destPath, ArcDef newArchive) throws IOException { if (Util.sameFilePath(sourcePath, destPath)) { throw new IllegalArgumentException(SOURCE_AND_DESTINATION_PATHS_ARE_THE_SAME); } try (RrdDb rrdSource = RrdDb.getBuilder().setPath(sourcePath).build()) { RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); rrdDef.addArchive(newArchive); try (RrdDb rrdDest = RrdDb.getBuilder().setRrdDef(rrdDef).build()) { rrdSource.copyStateTo(rrdDest); } } }
/** * Creates a new RRD file with one more datasource in it. RRD file is created based on the * existing one (the original RRD file is not modified at all). All data from * the original RRD file is copied to the new one. * * @param sourcePath path to a RRD file to import data from (will not be modified) * @param destPath path to a new RRD file (will be created) * @param newDatasources Datasource definitions to be added to the new RRD file * @throws java.io.IOException Thrown in case of I/O error */ public static void addDatasources(String sourcePath, String destPath, Iterable<DsDef> newDatasources) throws IOException { if (Util.sameFilePath(sourcePath, destPath)) { throw new IllegalArgumentException(SOURCE_AND_DESTINATION_PATHS_ARE_THE_SAME); } try (RrdDb rrdSource = RrdDb.getBuilder().setPath(sourcePath).build()) { RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); for (DsDef newDatasource : newDatasources) { rrdDef.addDatasource(newDatasource); } try (RrdDb rrdDest = RrdDb.getBuilder().setRrdDef(rrdDef).build()) { rrdSource.copyStateTo(rrdDest); } } }
/** * Creates a new RRD file with one datasource removed. RRD file is created based on the * existing one (the original RRD file is not modified at all). All remaining data from * the original RRD file is copied to the new one. * * @param sourcePath path to a RRD file to import data from (will not be modified) * @param destPath path to a new RRD file (will be created) * @param dsName Name of the Datasource to be removed from the new RRD file * @throws java.io.IOException Thrown in case of I/O error */ public static void removeDatasource(String sourcePath, String destPath, String dsName) throws IOException { if (Util.sameFilePath(sourcePath, destPath)) { throw new IllegalArgumentException(SOURCE_AND_DESTINATION_PATHS_ARE_THE_SAME); } try (RrdDb rrdSource = RrdDb.getBuilder().setPath(sourcePath).build()) { RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); rrdDef.removeDatasource(dsName); try (RrdDb rrdDest = RrdDb.getBuilder().setRrdDef(rrdDef).build()) { rrdSource.copyStateTo(rrdDest); } } }
/** * Creates a new RRD file with one archive removed. RRD file is created based on the * existing one (the original RRD file is not modified at all). All relevant data from * the original RRD file is copied to the new one. * * @param sourcePath path to a RRD file to import data from (will not be modified) * @param destPath path to a new RRD file (will be created) * @param consolFun Consolidation function of Archive which should be removed * @param steps Number of steps for Archive which should be removed * @throws java.io.IOException Thrown in case of I/O error */ public static void removeArchive(String sourcePath, String destPath, ConsolFun consolFun, int steps) throws IOException { if (Util.sameFilePath(sourcePath, destPath)) { throw new IllegalArgumentException(SOURCE_AND_DESTINATION_PATHS_ARE_THE_SAME); } try (RrdDb rrdSource = RrdDb.getBuilder().setPath(sourcePath).build()) { RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); rrdDef.removeArchive(consolFun, steps); try (RrdDb rrdDest = RrdDb.getBuilder().setRrdDef(rrdDef).build()) { rrdSource.copyStateTo(rrdDest); } } }
private void removeDatasource() { if (!inspectorModel.isOk()) { Util.error(this, "Open a valid RRD file first."); return; } RrdNode rrdNode = getSelectedRrdNode(); int dsIndex = -1; if (rrdNode == null || (dsIndex = rrdNode.getDsIndex()) < 0) { Util.error(this, "Select datasource first"); return; } try { String sourcePath = inspectorModel.getFile().getCanonicalPath(), dsName; RrdDb rrd = new RrdDb(sourcePath, true); try { dsName = rrd.getRrdDef().getDsDefs()[dsIndex].getDsName(); } finally { rrd.close(); } RrdToolkit.removeDatasource(sourcePath, dsName, SHOULD_CREATE_BACKUPS); inspectorModel.refresh(); tabbedPane.setSelectedIndex(0); } catch (Exception e) { Util.error(this, e); } }
RrdDb rrd = new RrdDb(sourcePath, true); try { ArcDef arcDef = rrd.getRrdDef().getArcDefs()[arcIndex]; consolFun = arcDef.getConsolFun(); steps = arcDef.getSteps();
/** * Splits single RRD file with several datasources into a number of smaller RRD files * with a single datasource in it. All archived values are preserved. If * you have a RRD file named 'traffic.rrd' with two datasources, 'in' and 'out', this * method will create two files (with a single datasource, in the same directory) * named 'in-traffic.rrd' and 'out-traffic.rrd'. * * @param sourcePath Path to a RRD file with multiple datasources defined * @throws IOException Thrown in case of I/O error */ public static void split(String sourcePath) throws IOException { RrdDb rrdSource = new RrdDb(sourcePath); try { String[] dsNames = rrdSource.getDsNames(); for (String dsName : dsNames) { RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(createSplitPath(dsName, sourcePath)); rrdDef.saveSingleDatasource(dsName); RrdDb rrdDest = new RrdDb(rrdDef); try { rrdSource.copyStateTo(rrdDest); } finally { rrdDest.close(); } } } finally { rrdSource.close(); } }
/** * Splits single RRD file with several datasources into a number of smaller RRD files * with a single datasource in it. All archived values are preserved. If * you have a RRD file named 'traffic.rrd' with two datasources, 'in' and 'out', this * method will create two files (with a single datasource, in the same directory) * named 'in-traffic.rrd' and 'out-traffic.rrd'. * * @param sourcePath Path to a RRD file with multiple datasources defined * @throws java.io.IOException Thrown in case of I/O error */ public static void split(String sourcePath) throws IOException { try (RrdDb rrdSource = RrdDb.getBuilder().setPath(sourcePath).build()) { String[] dsNames = rrdSource.getDsNames(); for (String dsName : dsNames) { RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(createSplitPath(dsName, sourcePath)); rrdDef.saveSingleDatasource(dsName); try (RrdDb rrdDest = RrdDb.getBuilder().setRrdDef(rrdDef).build()) { rrdSource.copyStateTo(rrdDest); } } } }
RrdDb rrd = new RrdDb(sourcePath, true); try { ArcDef arcDef = rrd.getRrdDef().getArcDefs()[arcIndex]; rrd.close(); ArcDef newArcDef = new EditArchiveDialog(this, arcDef).getArcDef();