org.rrd4j.DsType Java Examples

The following examples show how to use org.rrd4j.DsType. 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: MetricsHistoryHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private RrdDef createDef(String registry, Group group) {
  registry = SolrMetricManager.enforcePrefix(registry);

  // base sampling period is collectPeriod - samples more frequent than
  // that will be dropped, samples less frequent will be interpolated
  RrdDef def = new RrdDef(URI_PREFIX + registry, collectPeriod);
  // set the start time early enough so that the first sample is always later
  // than the start of the archive
  def.setStartTime(TimeUnit.SECONDS.convert(timeSource.getEpochTimeNs(), TimeUnit.NANOSECONDS) - def.getStep());

  // add datasources
  List<Group> groups = new ArrayList<>();
  groups.add(group);
  if (group == Group.collection) {
    groups.add(Group.core);
  }
  for (Group g : groups) {
    // use NaN when more than 1 sample is missing
    counters.get(g.toString()).forEach(name ->
        def.addDatasource(name, DsType.COUNTER, collectPeriod * 2, Double.NaN, Double.NaN));
    gauges.get(g.toString()).forEach(name ->
        def.addDatasource(name, DsType.GAUGE, collectPeriod * 2, Double.NaN, Double.NaN));
  }
  if (groups.contains(Group.node)) {
    // add nomNodes gauge
    def.addDatasource(NUM_NODES_KEY, DsType.GAUGE, collectPeriod * 2, Double.NaN, Double.NaN);
  }

  // add archives

  // use AVERAGE consolidation,
  // use NaN when >50% samples are missing
  def.addArchive(ConsolFun.AVERAGE, 0.5, 1, 240); // 4 hours
  def.addArchive(ConsolFun.AVERAGE, 0.5, 10, 288); // 48 hours
  def.addArchive(ConsolFun.AVERAGE, 0.5, 60, 336); // 2 weeks
  def.addArchive(ConsolFun.AVERAGE, 0.5, 240, 180); // 2 months
  def.addArchive(ConsolFun.AVERAGE, 0.5, 1440, 365); // 1 year
  return def;
}
 
Example #2
Source File: SolrRrdBackendFactoryTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private RrdDef createDef(long startTime) {
  RrdDef def = new RrdDef("solr:foo", 60);
  def.setStartTime(startTime);
  def.addDatasource("one", DsType.COUNTER, 120, Double.NaN, Double.NaN);
  def.addDatasource("two", DsType.GAUGE, 120, Double.NaN, Double.NaN);
  def.addArchive(ConsolFun.AVERAGE, 0.5, 1, 120); // 2 hours
  def.addArchive(ConsolFun.AVERAGE, 0.5, 10, 288); // 48 hours
  def.addArchive(ConsolFun.AVERAGE, 0.5, 60, 336); // 2 weeks
  def.addArchive(ConsolFun.AVERAGE, 0.5, 240, 180); // 2 months
  return def;
}
 
Example #3
Source File: RRD4jService.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
public void setDef(String defString) {
    String[] opts = defString.split(",");
    if (opts.length != 5) { // check if correct number of parameters
        logger.warn("invalid number of parameters {}: {}", name, defString);
        return;
    }

    if (opts[0].equals("ABSOLUTE")) { // dsType
        dsType = DsType.ABSOLUTE;
    } else if (opts[0].equals("COUNTER")) {
        dsType = DsType.COUNTER;
    } else if (opts[0].equals("DERIVE")) {
        dsType = DsType.DERIVE;
    } else if (opts[0].equals("GAUGE")) {
        dsType = DsType.GAUGE;
    } else {
        logger.warn("{}: dsType {} not supported", name, opts[0]);
    }

    heartbeat = Integer.parseInt(opts[1]);

    if (opts[2].equals("U")) {
        min = Double.NaN;
    } else {
        min = Double.parseDouble(opts[2]);
    }

    if (opts[3].equals("U")) {
        max = Double.NaN;
    } else {
        max = Double.parseDouble(opts[3]);
    }

    step = Integer.parseInt(opts[4]);

    isInitialized = true; // successfully initialized

    return;
}
 
Example #4
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());
    }
}