コード例 #1
0
ファイル: JniRrdStrategy.java プロジェクト: rljohnsn/opennms
  /**
   * Creates a the rrd file from the rrdDefinition. Since this definition is really just the create
   * command string it just executes it.
   *
   * @param createCommand a {@link java.lang.String} object.
   * @throws java.lang.Exception if any.
   */
  @Override
  public void createFile(CreateCommand createCommand, Map<String, String> attributeMappings)
      throws Exception {
    if (createCommand == null) {
      LOG.debug("createRRD: skipping RRD file");
      return;
    }
    LOG.debug("Executing: rrdtool {}", createCommand.toString());
    Interface.launch(createCommand.toString());

    String filenameWithoutExtension = createCommand.filename.replace(RrdUtils.getExtension(), "");
    int lastIndexOfSeparator = filenameWithoutExtension.lastIndexOf(File.separator);

    RrdUtils.createMetaDataFile(
        filenameWithoutExtension.substring(0, lastIndexOfSeparator),
        filenameWithoutExtension.substring(lastIndexOfSeparator),
        attributeMappings);
  }
コード例 #2
0
ファイル: JniRrdStrategy.java プロジェクト: rljohnsn/opennms
  /** {@inheritDoc} */
  @Override
  public CreateCommand createDefinition(
      String creator,
      String directory,
      String rrdName,
      int step,
      List<RrdDataSource> dataSources,
      List<String> rraList)
      throws Exception {
    File f = new File(directory);
    f.mkdirs();

    String fileName = directory + File.separator + rrdName + RrdUtils.getExtension();

    if (new File(fileName).exists()) {
      LOG.debug(
          "createDefinition: filename [{}] already exists returning null as definition", fileName);
      return null;
    }

    StringBuffer parameter = new StringBuffer();

    parameter.append(" --start=" + (System.currentTimeMillis() / 1000L - 10L));

    parameter.append(" --step=" + step);

    for (RrdDataSource dataSource : dataSources) {
      parameter.append(" DS:");
      parameter.append(dataSource.getName()).append(':');
      parameter.append(dataSource.getType()).append(":");
      parameter.append(dataSource.getHeartBeat()).append(':');
      parameter.append(dataSource.getMin()).append(':');
      parameter.append(dataSource.getMax());
    }

    for (String rra : rraList) {
      parameter.append(' ');
      parameter.append(rra);
    }

    return new CreateCommand(fileName, parameter.toString());
  }
コード例 #3
0
 /**
  * getRrdSuffix
  *
  * @return a {@link java.lang.String} object.
  */
 public static String getRrdSuffix() {
   return RrdUtils.getExtension();
 }
コード例 #4
0
  /**
   * fetchLastValue
   *
   * @param latIface a {@link org.opennms.netmgt.threshd.LatencyInterface} object.
   * @param latParms a {@link org.opennms.netmgt.threshd.LatencyParameters} object.
   * @return a {@link java.lang.Double} object.
   * @throws org.opennms.netmgt.threshd.ThresholdingException if any.
   */
  public Double fetchLastValue(LatencyInterface latIface, LatencyParameters latParms)
      throws ThresholdingException {
    // Assume that this only happens on a simple "Threshold", not an "Expression"
    // If it is an Expression, then we don't yet know what to do - this will likely just fail with
    // some sort of exception.
    // perhaps we should figure out how to expand it (or at least use code elsewhere to do so
    // sensibly)
    String datasource = getDataSourceExpression();

    // Use RRD strategy to "fetch" value of the datasource from the RRD file
    Double dsValue = null;
    try {
      if (getDatasourceType().equals("if")) {
        if (log().isDebugEnabled()) {
          log().debug("Fetching last value from dataSource '" + datasource + "'");
        }

        File rrdFile = new File(latIface.getLatencyDir(), datasource + RrdUtils.getExtension());
        if (!rrdFile.exists()) {
          log().info("rrd file " + rrdFile + " does not exist");
          return null;
        }

        if (!rrdFile.canRead()) {
          log().error("Unable to read existing rrd file " + rrdFile);
          return null;
        }

        if (latParms.getRange() == 0) {
          dsValue =
              RrdUtils.fetchLastValue(
                  rrdFile.getAbsolutePath(), datasource, latParms.getInterval());
        } else {
          dsValue =
              RrdUtils.fetchLastValueInRange(
                  rrdFile.getAbsolutePath(),
                  datasource,
                  latParms.getInterval(),
                  latParms.getRange());
        }
      } else {
        throw new ThresholdingException(
            "expr types not yet implemented", LatencyThresholder.THRESHOLDING_FAILED);
      }

      if (log().isDebugEnabled()) {
        log().debug("Last value from dataSource '" + datasource + "' was " + dsValue);
      }
    } catch (NumberFormatException nfe) {
      log()
          .warn(
              "Unable to convert retrieved value for datasource '"
                  + datasource
                  + "' to a double, skipping evaluation.");
    } catch (RrdException e) {
      log()
          .error(
              "An error occurred retriving the last value for datasource '"
                  + datasource
                  + "': "
                  + e,
              e);
    }

    return dsValue;
  }