Search in sources :

Example 1 with CollectorException

use of ddf.metrics.collector.CollectorException in project ddf by codice.

the class RrdJmxCollector method createRrdFile.

/**
     * Create an RRD file based on the metric's name (path) in the DDF metrics sub-directory. An RRD
     * DB instance is created from this RRD file's definition (if the RRD file did not already
     * exist, which can occur if the RRD file is created then DDF is restarted and this method is
     * called). If the RRD file already exists, then just create an RRD DB instance based on the
     * existing RRD file.
     *
     * @param metricName
     *            path where the RRD file is to be created. This is required.
     * @param dsName
     *            data source name for the RRD file. This is required.
     * @param dsType
     *            data source type, i.e., DERIVE, COUNTER or GAUGE (This is required.) (ABSOLUTE is
     *            not currently supported)
     * @param minValue
     *            the minimum value that will be stored in the data source; any values smaller than
     *            this will be stored as NaN (aka Unknown)
     * @param maxValue
     *            the maximum value that will be stored in the data source; any values larger than
     *            this will be stored as NaN (aka Unknown)
     *
     * @throws IOException
     * @throws CollectorException
     */
private void createRrdFile(final String metricName, final String dsName, final DsType dsType, double minValue, double maxValue) throws IOException, CollectorException {
    LOGGER.trace("ENTERING: createRrdFile");
    if (StringUtils.isEmpty(metricName)) {
        throw new CollectorException("Path where RRD file is to be created must be specified.");
    } else {
        rrdPath = metricsDir + metricName + RRD_FILENAME_SUFFIX;
    }
    if (StringUtils.isEmpty(dsName)) {
        throw new CollectorException("The name of the data source used in the RRD file must be specified.");
    }
    if (!dsType.equals(DsType.COUNTER) && !dsType.equals(DsType.GAUGE) && !dsType.equals(DsType.DERIVE)) {
        throw new CollectorException("Data Source type for the RRD file must be either DERIVE, COUNTER or GAUGE.");
    }
    File file = new File(rrdPath);
    if (!file.exists()) {
        // Create necessary parent directories
        if (!file.getParentFile().exists()) {
            if (!file.getParentFile().mkdirs()) {
                LOGGER.debug("Could not create parent file: {}", file.getParentFile().getAbsolutePath());
            }
        }
        LOGGER.debug("Creating new RRD file {}", rrdPath);
        RrdDef def = new RrdDef(rrdPath, rrdStep);
        // NOTE: Currently restrict each RRD file to only have one data source
        // (even though RRD supports multiple data sources in a single RRD file)
        def.addDatasource(dsName, dsType, 90, minValue, maxValue);
        // since all JMX MBeans are recreated).
        if (dsType == DsType.COUNTER || dsType == DsType.DERIVE) {
            // 1 minute resolution for last 60 minutes
            def.addArchive(ConsolFun.TOTAL, DEFAULT_XFF_FACTOR, 1, 60);
            // 15 minute resolution for the last year
            def.addArchive(ConsolFun.TOTAL, DEFAULT_XFF_FACTOR, 15, ONE_YEAR_IN_15_MINUTE_STEPS);
            // 1 minute resolution for last 60 minutes
            def.addArchive(ConsolFun.AVERAGE, DEFAULT_XFF_FACTOR, 1, 60);
            // 15 minute resolution for the last year
            def.addArchive(ConsolFun.AVERAGE, DEFAULT_XFF_FACTOR, 15, ONE_YEAR_IN_15_MINUTE_STEPS);
            // 1 minute resolution for last 60 minutes
            def.addArchive(ConsolFun.MAX, DEFAULT_XFF_FACTOR, 1, 60);
            // 15 minute resolution for the last year
            def.addArchive(ConsolFun.MAX, DEFAULT_XFF_FACTOR, 15, ONE_YEAR_IN_15_MINUTE_STEPS);
            // 1 minute resolution for last 60 minutes
            def.addArchive(ConsolFun.MIN, DEFAULT_XFF_FACTOR, 1, 60);
            // 15 minute resolution for the last year
            def.addArchive(ConsolFun.MIN, DEFAULT_XFF_FACTOR, 15, ONE_YEAR_IN_15_MINUTE_STEPS);
        // Use a GAUGE to store the values we measure directly as they are,
        // e.g., response time for an ingest or query
        } else if (dsType == DsType.GAUGE) {
            // If you want to know the amount, look at the averages.
            // If you want to know the rate, look at the maximum.
            // 1 minute resolution for last 60 minutes
            def.addArchive(ConsolFun.TOTAL, DEFAULT_XFF_FACTOR, 1, 60);
            // 15 minute resolution for the last year
            def.addArchive(ConsolFun.TOTAL, DEFAULT_XFF_FACTOR, 15, ONE_YEAR_IN_15_MINUTE_STEPS);
            // 1 minute resolution for last 60 minutes
            def.addArchive(ConsolFun.AVERAGE, DEFAULT_XFF_FACTOR, 1, 60);
            // 15 minute resolution for the last year
            def.addArchive(ConsolFun.AVERAGE, DEFAULT_XFF_FACTOR, 15, ONE_YEAR_IN_15_MINUTE_STEPS);
            // 1 minute resolution for last 60 minutes
            def.addArchive(ConsolFun.MAX, DEFAULT_XFF_FACTOR, 1, 60);
            // 15 minute resolution for the last year
            def.addArchive(ConsolFun.MAX, DEFAULT_XFF_FACTOR, 15, ONE_YEAR_IN_15_MINUTE_STEPS);
            // 1 minute resolution for last 60 minutes
            def.addArchive(ConsolFun.MIN, DEFAULT_XFF_FACTOR, 1, 60);
            // 15 minute resolution for the last year
            def.addArchive(ConsolFun.MIN, DEFAULT_XFF_FACTOR, 15, ONE_YEAR_IN_15_MINUTE_STEPS);
        }
        // Create RRD file based on the RRD file definition
        rrdDb = pool.requestRrdDb(def);
    } else {
        LOGGER.debug("rrd file {} already exists - absolute path = {}", rrdPath, file.getAbsolutePath());
        rrdDb = pool.requestRrdDb(rrdPath);
    }
    LOGGER.trace("EXITING: createRrdFile");
}
Also used : RrdDef(org.rrd4j.core.RrdDef) CollectorException(ddf.metrics.collector.CollectorException) File(java.io.File)

Aggregations

CollectorException (ddf.metrics.collector.CollectorException)1 File (java.io.File)1 RrdDef (org.rrd4j.core.RrdDef)1