Java Code Examples for org.rrd4j.ConsolFun#TOTAL

The following examples show how to use org.rrd4j.ConsolFun#TOTAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RRD4jService.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
public void addArchives(String archivesString) {
    String splitArchives[] = archivesString.split(":");
    for (String archiveString : splitArchives) {
        String[] opts = archiveString.split(",");
        if (opts.length != 4) { // check if correct number of parameters
            logger.warn("invalid number of parameters {}: {}", name, archiveString);
            return;
        }
        RrdArchiveDef arc = new RrdArchiveDef();

        if (opts[0].equals("AVERAGE")) {
            arc.fcn = ConsolFun.AVERAGE;
        } else if (opts[0].equals("MIN")) {
            arc.fcn = ConsolFun.MIN;
        } else if (opts[0].equals("MAX")) {
            arc.fcn = ConsolFun.MAX;
        } else if (opts[0].equals("LAST")) {
            arc.fcn = ConsolFun.LAST;
        } else if (opts[0].equals("FIRST")) {
            arc.fcn = ConsolFun.FIRST;
        } else if (opts[0].equals("TOTAL")) {
            arc.fcn = ConsolFun.TOTAL;
        } else {
            logger.warn("{}: consolidation function  {} not supported", name, opts[0]);
        }
        arc.xff = Double.parseDouble(opts[1]);
        arc.steps = Integer.parseInt(opts[2]);
        arc.rows = Integer.parseInt(opts[3]);
        archives.add(arc);
    }
}
 
Example 2
Source File: RRDDataStore.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
protected void initDatabase() throws IOException {
    if (!new File(dataBaseFile).exists()) {
        if (step <= 0) {
            logger.debug("Provided step is invalid, forcing it to " + DEFAULT_STEP_IN_SECONDS);
            step = DEFAULT_STEP_IN_SECONDS;
        }
        logger.info("Node's statistics are saved in " + dataBaseFile);

        RrdDef rrdDef = new RrdDef(dataBaseFile, System.currentTimeMillis() / 1000, step);

        for (String dataSource : dataSources.keySet()) {
            rrdDef.addDatasource(dataSource, DsType.GAUGE, 600, 0, Double.NaN);
        }

        // for step equals 4 seconds
        // Archive of 10 minutes = 600 seconds (4 * 1 * 150) of completely detailed data
        ConsolFun[] consolidationFunctions = new ConsolFun[] { ConsolFun.AVERAGE, ConsolFun.MIN, ConsolFun.MAX,
                                                               ConsolFun.LAST, ConsolFun.FIRST, ConsolFun.TOTAL };
        addArchives(rrdDef, consolidationFunctions, 0.5, 1, 150);

        // An archive of 1 hour = 3600 seconds (4 * 5 * 180) i.e. 180 averages of 5 steps
        addArchives(rrdDef, consolidationFunctions, 0.5, 5, 180);

        // An archive of 4 hours = 14400 seconds (4 * 10 * 360) i.e. 360 averages of 10 steps
        addArchives(rrdDef, consolidationFunctions, 0.5, 10, 360);

        // An archive of 8 hours = 28800 seconds (4 * 20 * 360) i.e. 360 averages of 20 steps
        addArchives(rrdDef, consolidationFunctions, 0.5, 20, 360);

        // An archive of 24 hours = 86400 seconds (4 * 30 * 720) i.e. 720 averages of 30 steps
        addArchives(rrdDef, consolidationFunctions, 0.5, 30, 720);

        // An archive of 1 week = 604800 seconds (4 * 210 * 720) i.e. 720 averages of 210 steps
        addArchives(rrdDef, consolidationFunctions, 0.5, 210, 720);

        // An archive of 1 month ~= 28 days = 604800 seconds (4 * 840 * 720) i.e. 720 averages of 840 steps
        addArchives(rrdDef, consolidationFunctions, 0.5, 840, 720);

        // An archive of 1 year = 364 days = 31449600 seconds (4 * 10920 * 720) i.e. 720 averages of 10920 steps
        addArchives(rrdDef, consolidationFunctions, 0.5, 10920, 720);

        RrdDb dataBase = new RrdDb(rrdDef);
        dataBase.close();
    } else {
        logger.info("Using existing RRD database: " + new File(dataBaseFile).getAbsolutePath());
    }
}