Examples of RrdDb


Examples of org.jrobin.core.RrdDb

                }
                else {
                    definitions = new StatDefinition[]{def};
                }

                RrdDb db = null;
                try {
                    newTime = getLastMinute();
                    if (def.lastSampleTime <= 0) {
                        for(StatDefinition definition : definitions) {
                            definition.lastSampleTime = newTime;
                            // It is possible that this plugin and thus the StatsEngine didn't
                            // start when Openfire started so we want to put the stats in a known
                            // state for proper sampling.
                            sampleStat(key, definition);
                        }
                        continue;
                    }

                    db = new RrdDb(def.getDbPath(), false);
                    // We want to double check the last sample time recorded in the db so as to
                    // prevent the log files from being inundated if more than one instance of
                    // Openfire is updating the same database. Also, if there is a task taking a
                    // long time to complete
                    if(newTime <= db.getLastArchiveUpdateTime()) {
                        Log.warn("Sample time of " + newTime +  " for statistic " + key + " is " +
                                "invalid.");
                    }
                    Sample sample = db.createSample(newTime);

                    if (Log.isDebugEnabled()) {
                        Log.debug("Stat: " + db.getPath() + ". Last sample: " + db.getLastUpdateTime() +
                                ". New sample: " + sample.getTime());
                    }

                    for (StatDefinition definition : definitions) {
                        // Get a statistic sample of this JVM
                        double statSample = sampleStat(key, definition);
                        // Add up samples of remote cluster nodes
                        for (Object nodeResult : remoteSamples) {
                            Map<String, Double> nodeSamples = (Map<String, Double>) nodeResult;
                            Double remoteSample = nodeSamples.get(key);
                            if (remoteSample != null) {
                                statSample += remoteSample;
                            }
                        }
                        // Update sample with values
                        sample.setValue(definition.getDatasourceName(), statSample);
                        sampledStats.add(definition.getDatasourceName());
                        definition.lastSampleTime = newTime;
                        definition.lastSample = statSample;
                    }
                    sample.update();
                }
                catch (IOException e) {
                    Log.error("Error sampling for statistic " + key, e);
                }
                catch (RrdException e) {
                    Log.error("Error sampling for statistic " + key, e);
                }
                finally {
                    if (db != null) {
                        try {
                            db.close();
                        }
                        catch (IOException e) {
                           Log.error("Error releasing db resource", e);
                        }
                    }
View Full Code Here

Examples of org.jrobin.core.RrdDb

            }
            return max;
        }

        private double[][] fetchData(String function, long startTime, long endTime, int dataPoints) {
            RrdDb db = null;
            try {
                db = new RrdDb(getDbPath(), true);

                FetchData data;
                if (dataPoints > 0) {
                    data = db.createFetchRequest(function, startTime, endTime,
                            getResolution(startTime, endTime, dataPoints)).fetchData();
                }
                else {
                    data = db.createFetchRequest(function, startTime, endTime).fetchData();
                }
                return data.getValues();
            }
            catch (IOException e) {
                Log.error("Error initializing Rrdb", e);
            }
            catch (RrdException e) {
                Log.error("Error initializing Rrdb", e);
            }
            finally {
                try {
                    if (db != null) {
                        db.close();
                    }
                }
                catch (IOException e) {
                    Log.error("Unable to release Rrdb resources",e);
                }
View Full Code Here

Examples of org.jrobin.core.RrdDb

            }
        }

        // check if the rrd exists
        if (!RrdSqlBackend.exists(def[0].getDbPath())) {
            RrdDb db = null;
            try {
                RrdDef rrdDef = new RrdDef(def[0].getDbPath(), STAT_RESOULUTION);
                for (StatDefinition stat : def) {
                    String dsType = determineDsType(stat.getStatistic().getStatType());
                    rrdDef.addDatasource(stat.getDatasourceName(), dsType, 5 * STAT_RESOULUTION, 0,
                            Double.NaN);
                }

                // Every minute for 1 hour.
                rrdDef.addArchive(((DefaultStatDefinition) def[0]).
                        consolidationFunction, 0.5, 1, 60);
                // Every half-hour for 1 day.
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 30, 48);
                // Every day for 5 years.
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 1440, 1825);
                // Every week for 5 years.
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 10080, 260);
                // Every month for 5 years.
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 43200, 60);

                db = new RrdDb(rrdDef);
            }
            finally {
                if(db != null) {
                    db.close();
                }
            }
        }
    }
View Full Code Here

Examples of org.jrobin.core.RrdDb

            return new double[] { engine.getDefinition(key)[0].getLastSample() };
        }
        else {
            try {
                if (RrdSqlBackend.exists(key)) {
                    RrdDb db = new RrdDb(key, true);
                    return new double[] { db.getLastDatasourceValues()[0] };
                }
            } catch (Exception e) {
                Log.error("Error retrieving last sample value for: " + key, e);
            }
            return new double[] { 0 };
View Full Code Here

Examples of org.jrobin.core.RrdDb

    String[] words = getRemainingWords();
    if (words.length != 2) {
      throw new RrdException("Invalid rrdinfo syntax");
    }
    String path = words[1], info;
    RrdDb rrd = getRrdDbReference(path);
    try {
      info = getInfo(rrd);
      println(info);
    }
    finally {
View Full Code Here

Examples of org.jrobin.core.RrdDb

    String[] words = getRemainingWords();
    if (words.length != 2) {
      throw new RrdException("Invalid rrddump syntax");
    }
    String path = words[1];
    RrdDb rrdDb = getRrdDbReference(path);
    try {
      String xml = rrdDb.getXml();
      println(xml);
      return xml;
    }
    finally {
      releaseRrdDbReference(rrdDb);
View Full Code Here

Examples of org.jrobin.core.RrdDb

  static RrdDb getRrdDbReference(String path) throws IOException, RrdException {
    if (rrdDbPoolUsed) {
      return RrdDbPool.getInstance().requestRrdDb(path);
    }
    else {
      return new RrdDb(path);
    }
  }
View Full Code Here

Examples of org.jrobin.core.RrdDb

  static RrdDb getRrdDbReference(String path, String xmlPath) throws IOException, RrdException {
    if (rrdDbPoolUsed) {
      return RrdDbPool.getInstance().requestRrdDb(path, xmlPath);
    }
    else {
      return new RrdDb(path, xmlPath);
    }
  }
View Full Code Here

Examples of org.jrobin.core.RrdDb

  static RrdDb getRrdDbReference(RrdDef rrdDef) throws IOException, RrdException {
    if (rrdDbPoolUsed) {
      return RrdDbPool.getInstance().requestRrdDb(rrdDef);
    }
    else {
      return new RrdDb(rrdDef);
    }
  }
View Full Code Here

Examples of org.jrobin.core.RrdDb

    String[] words = getRemainingWords();
    if (words.length < 3) {
      throw new RrdException("Insufficent number of parameters for rrdupdate command");
    }
    String path = words[1];
    RrdDb rrdDb = getRrdDbReference(path);
    try {
      if (dsNames != null) {
        // template specified, check datasource names
        for (String dsName : dsNames) {
          if (!rrdDb.containsDs(dsName)) {
            throw new RrdException("Invalid datasource name: " + dsName);
          }
        }
      }
      // parse update strings
      long timestamp = -1;
      for (int i = 2; i < words.length; i++) {
        String[] tokens = new ColonSplitter(words[i]).split();
        if (dsNames != null && dsNames.length + 1 != tokens.length) {
          throw new RrdException("Template requires " + dsNames.length + " values, " +
              (tokens.length - 1) + " value(s) found in: " + words[i]);
        }
        int dsCount = rrdDb.getHeader().getDsCount();
        if (dsNames == null && dsCount + 1 != tokens.length) {
          throw new RrdException("Expected " + dsCount + " values, " +
              (tokens.length - 1) + " value(s) found in: " + words[i]);
        }
        timestamp = Util.getTimestamp(tokens[0]);
        Sample sample = rrdDb.createSample(timestamp);
        for (int j = 1; j < tokens.length; j++) {
          if (dsNames == null) {
            sample.setValue(j - 1, parseDouble(tokens[j]));
          }
          else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.