org.rrd4j.ConsolFun Java Examples

The following examples show how to use org.rrd4j.ConsolFun. 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: RrdAccessor.java    From rheem with Apache License 2.0 6 votes vote down vote up
public double query(String dsName, long startTimestamp, long endTimestamp, ConsolFun consolidationFunction) {
    long tStart = convertToUnixTimestamp(startTimestamp);
    long tEnd = convertToUnixTimestamp(endTimestamp);
    if (tStart == tEnd) {
        this.logger.warn("Shifting end time by 1 second because it is identical with the start time.");
        tEnd++;
    }
    try {
        final FetchRequest request = this.rrdDb.createFetchRequest(consolidationFunction, tStart, tEnd);
        final FetchData fetchData = request.fetchData();
        return fetchData.getAggregate(dsName, consolidationFunction);
    } catch (IOException e) {
        e.printStackTrace();
        return Double.NaN;
    }
}
 
Example #2
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 #3
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/node_threads.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] nodeDispatcherThreads() throws IOException {

    final String path = rrdPath(THREAD_RRD);
    final RrdGraphDef graphDef = baseGraph("Node Dispatcher Queue", "threads/sec");

    graphDef.datasource("threads", path, "nodeActiveThreads", ConsolFun.AVERAGE);
    graphDef.datasource("queue", path, "nodeWaiting", ConsolFun.AVERAGE);

    graphDef.line("threads", new Color(152, 175, 54), "Active Threads");
    graphDef.area("queue", new Color(74, 104, 15), "Queued Work");

    graphDef.comment("\\r");

    graphDef.gprint("threads", MAX, "Max Threads = %.3f%S");
    graphDef.gprint("threads", AVERAGE, "Avg Threads = %.3f%S\n");

    graphDef.gprint("queue", MAX, "Max Queued = %.3f%s");
    graphDef.gprint("queue", AVERAGE, "Avg Queued = %.3f%S\n");

    return createImage(graphDef);
}
 
Example #4
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/rnd_traffic.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] rndTrafficGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Rnd Traffic", "ops/sec");

    graphDef.datasource("ping", path, "rndPingCount", ConsolFun.AVERAGE);
    graphDef.datasource("task", path, "rndTaskComplete", ConsolFun.AVERAGE);
    graphDef.area("ping", new Color(179, 96, 157), "Ping");
    graphDef.stack("task", new Color(255, 163, 231), "Task Complete");

    graphDef.comment("\\r");

    graphDef.gprint("ping", MAX, "Max Pings = %.3f%S");
    graphDef.gprint("ping", AVERAGE, "Avg Pings = %.3f%S\n");

    graphDef.gprint("task", MAX, "Max Task Complate = %.3f%s");
    graphDef.gprint("task", AVERAGE, "Avg Task Complete = %.3f%S\n");

    return createImage(graphDef);
}
 
Example #5
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/job_launch.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] jobLaunchGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Job Launch", "jobs/sec");

    graphDef.datasource("linea", path, "jobLaunchCount", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "jobLaunchFailCount", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "jobFinishCount", ConsolFun.AVERAGE);
    graphDef.datasource("lined", path, "jobKillCount", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(8, 175, 193), "Launched");
    graphDef.stack("linec", new Color(133, 225, 224), "Finished");
    graphDef.line("lineb", new Color(241, 93, 5), "Launch Fail", 2);
    graphDef.line("lined",  new Color(243, 165, 41), "Jobs Killed", 2);

    return createImage(graphDef);
}
 
Example #6
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/task_exec.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] taskCountsGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Task Executions", "task/sec");

    graphDef.datasource("linea", path, "taskStartedCount", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "taskStartedFailCount", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "taskStoppedCount", ConsolFun.AVERAGE);
    graphDef.datasource("lined", path, "taskStoppedFailCount", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(8, 175, 193), "Started");
    graphDef.stack("linec", new Color(133, 225, 224), "Stopped");
    graphDef.line("lineb", new Color(243, 165, 41), "Error Started", 2);
    graphDef.line("lined", new Color(241, 93, 5), "Error Stopped", 2);

    return createImage(graphDef);
}
 
Example #7
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/proc_dsp.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] procDispatcherStatsGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Proc Dispatcher Traffic", "dps/sec");

    graphDef.datasource("linea", path, "procDispatchHit", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "procDispatchMiss", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "procDispatchFail", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(152, 175, 54), "Hit");
    graphDef.area("lineb", new Color(74, 104, 15), "Miss");
    graphDef.area("linec", new Color(164, 11, 23), "Error");

    return createImage(graphDef);
}
 
Example #8
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/node_dsp.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] nodeDispatcherStatsGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Node Dispatcher Traffic", "dps/sec");

    graphDef.datasource("linea", path, "nodeDispatchHit", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "nodeDispatchMiss", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "nodeDispatchFail", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(152, 175, 54), "Hit");
    graphDef.area("lineb", new Color(74, 104, 15), "Miss");
    graphDef.area("linec", new Color(164, 11, 23), "Error");

    return createImage(graphDef);
}
 
Example #9
Source File: RMRestTest.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
private JSONObject callGetStatHistory(byte[] rrdb, ConsolFun function) throws Exception {
    RMProxyUserInterface rmMock = mock(RMProxyUserInterface.class);
    String sessionId = SharedSessionStoreTestUtils.createValidSession(rmMock);

    AttributeList value = new AttributeList(Collections.singletonList(new Attribute("test", rrdb)));
    when(rmMock.getMBeanAttributes(Matchers.<ObjectName> any(), Matchers.<String[]> any())).thenReturn(value);
    RMRestInterface client = ProxyFactory.create(RMRestInterface.class, "http://localhost:" + port + "/");

    String statHistory = client.getStatHistory(sessionId, "hhhhh", function.name());
    return (JSONObject) new JSONParser().parse(statHistory);
}
 
Example #10
Source File: RMRestTest.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testStatsHistory_Locale_Fr() throws Exception {
    Locale.setDefault(Locale.FRANCE);

    byte[] rrdb = createRrdDb().getBytes();
    JSONObject jsonObject = callGetStatHistory(rrdb, ConsolFun.AVERAGE);
    assertEquals(EXPECTED_RRD_VALUE, (Double) ((JSONArray) jsonObject.get("AverageActivity")).get(0), 0.001);

    jsonObject = callGetStatHistory(rrdb, ConsolFun.MIN);
    assertEquals(EXPECTED_RRD_VALUE, (Double) ((JSONArray) jsonObject.get("AverageActivity")).get(0), 0.001);

    jsonObject = callGetStatHistory(rrdb, ConsolFun.MAX);
    assertEquals(EXPECTED_RRD_VALUE, (Double) ((JSONArray) jsonObject.get("AverageActivity")).get(0), 0.001);
}
 
Example #11
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 #12
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 #13
Source File: RrdGraphController.java    From plow with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/proc_threads.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] procDispatcherThreads() throws IOException {

    final String path = rrdPath(THREAD_RRD);
    final RrdGraphDef graphDef = baseGraph("Proc Dispatcher Queue", "threads/sec");

    graphDef.datasource("linea", path, "procActiveThreads", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "procWaiting", ConsolFun.AVERAGE);
    graphDef.area("lineb", new Color(74, 104, 15), "Queued Work");
    graphDef.line("linea", new Color(152, 175, 54), "Active Threads");

    return createImage(graphDef);
}
 
Example #14
Source File: RrdGraphController.java    From plow with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/async_threads.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] asyncWorkQueueThreads() throws IOException {

    final String path = rrdPath(THREAD_RRD);
    final RrdGraphDef graphDef = baseGraph("Async Work Queue", "threads/sec");

    graphDef.datasource("linea", path, "asyncActiveThreads", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "asyncWaiting", ConsolFun.AVERAGE);
    graphDef.area("lineb", new Color(74, 104, 15), "Queued Work");
    graphDef.line("linea", new Color(152, 175, 54), "Active Threads");

    return createImage(graphDef);
}
 
Example #15
Source File: RRD4jChartServlet.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Adds a line for the item to the graph definition.
 * The color of the line is determined by the counter, it simply picks the according index from LINECOLORS (and
 * rolls over if necessary).
 * 
 * @param graphDef the graph definition to fill
 * @param item the item to add a line for
 * @param counter defines the number of the datasource and is used to determine the line color
 */
protected void addLine(RrdGraphDef graphDef, Item item, int counter) {
    Color color = LINECOLORS[counter % LINECOLORS.length];
    String label = itemUIRegistry.getLabel(item.getName());
    String rrdName = RRD4jService.DB_FOLDER + File.separator + item.getName() + ".rrd";
    ConsolFun consolFun;
    if (label != null && label.contains("[") && label.contains("]")) {
        label = label.substring(0, label.indexOf('['));
    }
    try {
        RrdDb db = new RrdDb(rrdName);
        consolFun = db.getRrdDef().getArcDefs()[0].getConsolFun();
        db.close();
    } catch (IOException e) {
        consolFun = ConsolFun.MAX;
    }
    if (item instanceof NumberItem) {
        // we only draw a line
        graphDef.datasource(Integer.toString(counter), rrdName, "state", consolFun); // RRD4jService.getConsolidationFunction(item));
        graphDef.line(Integer.toString(counter), color, label, 2);
    } else {
        // we draw a line and fill the area beneath it with a transparent color
        graphDef.datasource(Integer.toString(counter), rrdName, "state", consolFun); // RRD4jService.getConsolidationFunction(item));
        Color areaColor = AREACOLORS[counter % LINECOLORS.length];

        graphDef.area(Integer.toString(counter), areaColor);
        graphDef.line(Integer.toString(counter), color, label, 2);
    }
}
 
Example #16
Source File: RRD4jService.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
public ConsolFun getConsolidationFunction(RrdDb db) {
    try {
        return db.getRrdDef().getArcDefs()[0].getConsolFun();
    } catch (IOException e) {
        return ConsolFun.MAX;
    }
}
 
Example #17
Source File: SparkOperatorProfiler.java    From rheem with Apache License 2.0 5 votes vote down vote up
/**
 * Queries an average metric from a Ganglia RRD file. If the metric is not recent enough, this method waits
 * until the requested data points are available.
 */
private double waitAndQueryMetricAverage(String metric, String dataSeries, long startTime, long endTime) {
    final String rrdFile = this.gangliaRrdsDir + File.separator +
            this.gangliaClusterName + File.separator +
            "__SummaryInfo__" + File.separator +
            metric + ".rrd";

    double metricValue = Double.NaN;
    int numAttempts = 0;
    do {
        if (numAttempts++ > 0) {
            ProfilingUtils.sleep(5000);
        }

        try (RrdAccessor rrdAccessor = RrdAccessor.open(rrdFile)) {
            final long lastUpdateMillis = rrdAccessor.getLastUpdateMillis();
            if (lastUpdateMillis >= endTime) {
                metricValue = rrdAccessor.query(dataSeries, startTime, endTime, ConsolFun.AVERAGE);
            } else {
                this.logger.info("Last RRD file update is only from {} ({} attempts so far).", new Date(lastUpdateMillis), numAttempts);
            }
        } catch (Exception e) {
            this.logger.error(String.format("Could not access RRD %s.", rrdFile), e);
            return Double.NaN;
        }
    } while (Double.isNaN(metricValue));

    return metricValue;
}
 
Example #18
Source File: RRDDataStore.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
private void addArchives(RrdDef rrdDef, ConsolFun[] consolFunctions, double xff, int steps, int rows) {
    for (ConsolFun consolFun : consolFunctions) {
        rrdDef.addArchive(consolFun, xff, steps, rows);
    }
}
 
Example #19
Source File: MBeanInfoViewer.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String rrdContent(byte[] rrd4j, String newRange, String[] dataSources, String function)
        throws IOException {

    File rrd4jDb = File.createTempFile("database", "rr4dj");
    // construct the JSON response directly in a String
    StringBuilder result = new StringBuilder();
    try {
        try (OutputStream out = new FileOutputStream(rrd4jDb)) {
            out.write(rrd4j);
        }

        // create RRD4J DB, should be identical to the one held by the RM
        RrdDb db = new RrdDb(rrd4jDb.getAbsolutePath(), true);

        long timeEnd = db.getLastUpdateTime();
        // force float separator for JSON parsing
        DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
        otherSymbols.setDecimalSeparator('.');
        // formatting will greatly reduce response size
        DecimalFormat formatter = new DecimalFormat("###.###", otherSymbols);

        result.append("{");

        for (int i = 0; i < dataSources.length; i++) {
            String dataSource = dataSources[i];
            char zone = newRange.charAt(i);
            long timeStart = timeEnd - secondsInZone(zone);

            FetchRequest req = db.createFetchRequest(function != null ? ConsolFun.valueOf(function)
                                                                      : ConsolFun.AVERAGE,
                                                     timeStart,
                                                     timeEnd);
            req.setFilter(dataSource);
            FetchData fetchData = req.fetchData();
            result.append("\"").append(dataSource).append("\":[");

            double[] values = fetchData.getValues(dataSource);

            int nValuesToTake = values.length;
            // if the last value is NaN then we decide to not send it to the client
            // why? Because when we retrieve from RDD file, somehow the latest is
            // always NaN, which is not what we want.
            if (Double.compare(values[values.length - 1], Double.NaN) == 0) {
                --nValuesToTake;
            }

            String collect = Arrays.stream(values)
                                   .boxed()
                                   .collect(Collectors.toList())
                                   .subList(0, nValuesToTake)
                                   .stream()
                                   .map(value -> {
                                       if (Double.compare(Double.NaN, value) == 0) {
                                           return "null";
                                       } else {
                                           return formatter.format(value);
                                       }
                                   })
                                   .collect(Collectors.joining(","));
            result.append(collect);
            result.append(']');
            if (i < dataSources.length - 1) {
                result.append(',');
            }
        }
        result.append("}");

        db.close();
    } finally {
        FileUtils.deleteQuietly(rrd4jDb);
    }

    return result.toString();
}
 
Example #20
Source File: SigarProcesses.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public String getAttributesHistory(String objectName, String[] attrs, String range) throws IOException {

    RrdDb db = new RrdDb(statBaseName, true);

    long timeEnd = db.getLastUpdateTime();
    // force float separator for JSON parsing
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
    otherSymbols.setDecimalSeparator('.');
    // formatting will greatly reduce response size
    DecimalFormat formatter = new DecimalFormat("###.###", otherSymbols);

    // construct the JSON response directly in a String
    StringBuilder result = new StringBuilder();
    result.append("{");

    for (int i = 0; i < attrs.length; i++) {

        String dataSource = RRDSigarDataStore.toDataStoreName(attrs[i] + "-" + objectName);

        char zone = range.charAt(0);
        long timeStart = timeEnd - MBeanInfoViewer.secondsInZone(zone);

        FetchRequest req = db.createFetchRequest(ConsolFun.AVERAGE, timeStart, timeEnd);
        req.setFilter(dataSource);
        FetchData fetchData = req.fetchData();
        result.append("\"").append(dataSource).append("\":[");

        double[] values = fetchData.getValues(dataSource);
        for (int j = 0; j < values.length - 1; j++) {
            if (Double.compare(Double.NaN, values[j]) == 0) {
                result.append("null");
            } else {
                result.append(formatter.format(values[j]));
            }
            if (j < values.length - 2)
                result.append(',');
        }
        result.append(']');
        if (i < attrs.length - 1)
            result.append(',');
    }
    result.append("}");

    db.close();

    return result.toString();
}
 
Example #21
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());
    }
}
 
Example #22
Source File: RRD4jService.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
public ConsolFun getDefaultConsolFun() {
    return archives.iterator().next().fcn;
}
 
Example #23
Source File: RMNodeClient.java    From scheduling with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Return the statistic history contained in the RM's RRD database,
 * without redundancy, in a friendly JSON format.
 *
 * The following sources will be queried from the RRD DB :<pre>
 * 	{ AvailableNodesCount",
 * 	"FreeNodesCount",
 * 	"NeededNodesCount",
 * 	"BusyNodesCount",
 * 	"DeployingNodesCount",
 * 	"ConfigNodesCount",
 * 	"DownNodesCount",
 * 	"LostNodesCount",
 * 	"AverageActivity" };
 * 	</pre>
 *
 *
 * @param range a String of 9 chars, one for each stat history source, indicating the time range to fetch
 *      for each source. Each char can be:<ul>
 *            <li>'a' 1 minute</li>
 *            <li>'m' 10 minutes</li>
 *            <li>'n' 5 minutes</li>
 *            <li>'t' 30 minutes</li>
 *            <li>'h' 1 hour</li>
 *            <li>'j' 2 hours</li>
 *            <li>'k' 4 hours</li>
 *            <li>'H' 8 hours</li>
 *            <li>'d' 1 day</li>
 *            <li>'w' 1 week</li>
 *            <li>'M' 1 month</li>
 *            <li>'y' 1 year</li></ul>
 * @return a JSON object containing a key for each source
 */
public String getStatHistory(String range) throws ReflectionException, InterruptedException, IntrospectionException,
        NotConnectedException, InstanceNotFoundException, MalformedObjectNameException, IOException {
    checkNonEmptySession();
    return rm.getStatHistory(sessionId, range, ConsolFun.AVERAGE.name());
}