code: def add_measurement(measurement):
      global _buffer_size
      if not _enabled:
          LOGGER.debug('Discarding measurement for %s while not enabled',
                       measurement.database)
          return
      if _stopping:
          LOGGER.warning('Discarding measurement for %s while stopping',
                         measurement.database)
          return
      if _buffer_size > _max_buffer_size:
          LOGGER.warning('Discarding measurement due to buffer size limit')
          return
      if not measurement.fields:
          raise ValueError('Measurement does not contain a field')
      if measurement.database not in _measurements:
          _measurements[measurement.database] = []
      value = measurement.marshall()
      _measurements[measurement.database].append(value)
      if not _timeout:
          if (_batch_future and _batch_future.done()) or not _batch_future:
              _start_timeout()
      _buffer_size = _pending_measurements()
      if _buffer_size >= _trigger_size:
          _trigger_batch_write()