/** * 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(); } }
try { RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); for (DsDef newDatasource : newDatasources) { rrdDef.addDatasource(newDatasource);
/** * 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(); } }
/** * 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); } } }
if (arcDef.getRows() != newRows) { arcDef.setRows(newRows); rrdDef.setPath(destPath); RrdDb rrdDest = new RrdDb(rrdDef); try {
if (arcDef.getRows() != newRows) { arcDef.setRows(newRows); rrdDef.setPath(destPath); RrdDb rrdDest = new RrdDb(rrdDef); try {
/** * 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); } } }
/** * 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(); } }
rrdDef.setPath(dest.getCanonicalPath()); RrdDb rrdDest = new RrdDb(rrdDef);
/** * 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); } } } }