lib/statsd.js
function makeStatsD(options, logger) {
    let statsd;
    const srvName = options._prefix ? options._prefix : normalizeName(options.name);
    const statsdOptions = {
        host: options.host,
        port: options.port,
        prefix: `${srvName}.`,
        suffix: '',
        globalize: false,
        cacheDns: false,
        mock: false
    };

    // Batch metrics unless `batch` option is `false`
    if (typeof options.batch !== 'boolean' || options.batch) {
        options.batch = options.batch || {};
        statsdOptions.maxBufferSize = options.batch.max_size || DEFAULT_MAX_BATCH_SIZE;
        statsdOptions.bufferFlushInterval = options.batch.max_delay || 1000;
    }

    if (options.type === 'log') {
        statsd = new LogStatsD(logger, srvName);
    } else {
        statsd = new StatsD(statsdOptions);
    }

    // Support creating sub-metric clients with a fixed prefix. This is useful
    // for systematically categorizing metrics per-request, by using a
    // specific logger.
    statsd.makeChild = (name) => {
        const child = statsd.childClient();
        // We can't use the prefix in clientOptions,
        // because it will be prepended to existing prefix.
        child.prefix = statsd.prefix + normalizeName(name) + '.';

        // Attach normalizeName to make the childClient instance backwards-compatible
        // with the previously used StatsD instance
        child.normalizeName = normalizeName;

        return child;
    };

    // Add a static utility method for stat name normalization
    statsd.normalizeName = normalizeName;

    return statsd;
}
function makeStatsD(options, logger) {
    let statsd;
    const srvName = options._prefix ? options._prefix : normalizeName(options.name);
    const statsdOptions = {
        host: options.host,
        port: options.port,
        prefix: `${srvName}.`,
        suffix: '',
        globalize: false,
        cacheDns: false,
        mock: false
    };

    // Batch metrics unless `batch` option is `false`
    if (typeof options.batch !== 'boolean' || options.batch) {
        options.batch = options.batch || {};
        statsdOptions.maxBufferSize = options.batch.max_size || DEFAULT_MAX_BATCH_SIZE;
        statsdOptions.bufferFlushInterval = options.batch.max_delay || 1000;
    }

    if (options.type === 'log') {
        statsd = new LogStatsD(logger, srvName);
    } else {
        statsd = new StatsD(statsdOptions);
    }

    // Support creating sub-metric clients with a fixed prefix. This is useful
    // for systematically categorizing metrics per-request, by using a
    // specific logger.
    statsd.makeChild = (name) => {
        const child = statsd.childClient();
        // We can't use the prefix in clientOptions,
        // because it will be prepended to existing prefix.
        child.prefix = statsd.prefix + normalizeName(name) + '.';

        // Attach normalizeName to make the childClient instance backwards-compatible
        // with the previously used StatsD instance
        child.normalizeName = normalizeName;

        return child;
    };

    // Add a static utility method for stat name normalization
    statsd.normalizeName = normalizeName;

    return statsd;
}
function makeStatsD ( options , logger ) { let statsd ; const srvName = options . _prefix ? options . _prefix : normalizeName ( options . name ) ; const statsdOptions = { host : options . host , port : options . port , prefix : ` ${ srvName } ` , suffix : '' , globalize : false , cacheDns : false , mock : false } ; // Batch metrics unless `batch` option is `false` if ( typeof options . batch !== 'boolean' || options . batch ) { options . batch = options . batch || { } ; statsdOptions . maxBufferSize = options . batch . max_size || DEFAULT_MAX_BATCH_SIZE ; statsdOptions . bufferFlushInterval = options . batch . max_delay || 1000 ; } if ( options . type === 'log' ) { statsd = new LogStatsD ( logger , srvName ) ; } else { statsd = new StatsD ( statsdOptions ) ; } // Support creating sub-metric clients with a fixed prefix. This is useful // for systematically categorizing metrics per-request, by using a // specific logger. statsd . makeChild = ( name ) => { const child = statsd . childClient ( ) ; // We can't use the prefix in clientOptions, // because it will be prepended to existing prefix. child . prefix = statsd . prefix + normalizeName ( name ) + '.' ; // Attach normalizeName to make the childClient instance backwards-compatible // with the previously used StatsD instance child . normalizeName = normalizeName ; return child ; } ; // Add a static utility method for stat name normalization statsd . normalizeName = normalizeName ; return statsd ; }
Minimal StatsD wrapper
Minimal StatsD wrapper