Call this to install/setup the InfluxDB client collector. All arguments
    are optional.

    :param str url: The InfluxDB API URL. If URL is not specified, the
        ``INFLUXDB_SCHEME``, ``INFLUXDB_HOST`` and ``INFLUXDB_PORT``
        environment variables will be used to construct the base URL. Default:
        ``http://localhost:8086/write``
    :param str auth_username: A username to use for InfluxDB authentication. If
        not specified, the ``INFLUXDB_USER`` environment variable will
        be used. Default: ``None``
    :param str auth_password: A password to use for InfluxDB authentication. If
        not specified, the ``INFLUXDB_PASSWORD`` environment variable will
        be used. Default: ``None``
    :param int submission_interval: The maximum number of milliseconds to wait
        after the last batch submission before submitting a batch that is
        smaller than ``trigger_size``. Default: ``60000``
    :param int max_batch_size: The number of measurements to be submitted in a
        single HTTP request. Default: ``10000``
    :param int max_clients: The number of simultaneous batch submissions that
        may be made at any given time. Default: ``10``
    :param dict base_tags: Default tags that are to be submitted with each
        measurement.  Default: ``None``
    :param int max_buffer_size: The maximum number of pending measurements
        in the buffer before new measurements are discarded.
        Default: ``25000``
    :param int trigger_size: The minimum number of measurements that
        are in the buffer before a batch can be submitted. Default: ``5000``
    :param float sample_probability: Value between 0 and 1.0 specifying the
        probability that a batch will be submitted (0.25 == 25%)
    :returns: :data:`True` if the client was installed by this call
        and :data:`False` otherwise.

    If ``INFLUXDB_PASSWORD`` is specified as an environment variable, it will
    be masked in the Python process.

def install(url=None, auth_username=None, auth_password=None,
            submission_interval=None, max_batch_size=None, max_clients=10,
            base_tags=None, max_buffer_size=None, trigger_size=None,
            sample_probability=1.0):
    """Call this to install/setup the InfluxDB client collector. All arguments
    are optional.

    :param str url: The InfluxDB API URL. If URL is not specified, the
        ``INFLUXDB_SCHEME``, ``INFLUXDB_HOST`` and ``INFLUXDB_PORT``
        environment variables will be used to construct the base URL. Default:
        ``http://localhost:8086/write``
    :param str auth_username: A username to use for InfluxDB authentication. If
        not specified, the ``INFLUXDB_USER`` environment variable will
        be used. Default: ``None``
    :param str auth_password: A password to use for InfluxDB authentication. If
        not specified, the ``INFLUXDB_PASSWORD`` environment variable will
        be used. Default: ``None``
    :param int submission_interval: The maximum number of milliseconds to wait
        after the last batch submission before submitting a batch that is
        smaller than ``trigger_size``. Default: ``60000``
    :param int max_batch_size: The number of measurements to be submitted in a
        single HTTP request. Default: ``10000``
    :param int max_clients: The number of simultaneous batch submissions that
        may be made at any given time. Default: ``10``
    :param dict base_tags: Default tags that are to be submitted with each
        measurement.  Default: ``None``
    :param int max_buffer_size: The maximum number of pending measurements
        in the buffer before new measurements are discarded.
        Default: ``25000``
    :param int trigger_size: The minimum number of measurements that
        are in the buffer before a batch can be submitted. Default: ``5000``
    :param float sample_probability: Value between 0 and 1.0 specifying the
        probability that a batch will be submitted (0.25 == 25%)
    :returns: :data:`True` if the client was installed by this call
        and :data:`False` otherwise.

    If ``INFLUXDB_PASSWORD`` is specified as an environment variable, it will
    be masked in the Python process.

    """
    global _base_tags, _base_url, _credentials, _enabled, _installed, \
        _max_batch_size, _max_buffer_size, _max_clients, \
        _sample_probability, _timeout, _timeout_interval, _trigger_size

    _enabled = os.environ.get('INFLUXDB_ENABLED', 'true') == 'true'
    if not _enabled:
        LOGGER.warning('Disabling InfluxDB support')
        return

    if _installed:
        LOGGER.warning('InfluxDB client already installed')
        return False

    _base_url = url or '{}://{}:{}/write'.format(
        os.environ.get('INFLUXDB_SCHEME', 'http'),
        os.environ.get('INFLUXDB_HOST', 'localhost'),
        os.environ.get('INFLUXDB_PORT', 8086))

    _credentials = (auth_username or os.environ.get('INFLUXDB_USER', None),
                    auth_password or os.environ.get('INFLUXDB_PASSWORD', None))

    # Don't leave the environment variable out there with the password
    if os.environ.get('INFLUXDB_PASSWORD'):
        os.environ['INFLUXDB_PASSWORD'] = \
            'X' * len(os.environ['INFLUXDB_PASSWORD'])

    # Submission related values
    _timeout_interval = submission_interval or \
        int(os.environ.get('INFLUXDB_INTERVAL', _timeout_interval))
    _max_batch_size = max_batch_size or \
        int(os.environ.get('INFLUXDB_MAX_BATCH_SIZE', _max_batch_size))
    _max_clients = max_clients
    _max_buffer_size = max_buffer_size or \
        int(os.environ.get('INFLUXDB_MAX_BUFFER_SIZE', _max_buffer_size))
    _sample_probability = sample_probability or \
        float(os.environ.get('INFLUXDB_SAMPLE_PROBABILITY',
                             _sample_probability))
    _trigger_size = trigger_size or \
        int(os.environ.get('INFLUXDB_TRIGGER_SIZE', _trigger_size))

    # Set the base tags
    if os.environ.get('INFLUXDB_TAG_HOSTNAME', 'true') == 'true':
        _base_tags.setdefault('hostname', socket.gethostname())
    if os.environ.get('ENVIRONMENT'):
        _base_tags.setdefault('environment', os.environ['ENVIRONMENT'])
    _base_tags.update(base_tags or {})

    # Seed the random number generator for batch sampling
    random.seed()

    # Don't let this run multiple times
    _installed = True

    LOGGER.info('sprockets_influxdb v%s installed; %i measurements or %.2f '
                'seconds will trigger batch submission', __version__,
                _trigger_size, _timeout_interval / 1000.0)
    return True