code: def _get_bgw_metrics(self, key, db):
          
          # Extended 9.2+ metrics if needed
          metrics = self.bgw_metrics.get(key)
  
          if metrics is None:
              # Hack to make sure that if we have multiple instances that connect to
              # the same host, port, we don't collect metrics twice
              # as it will result in https://github.com/DataDog/dd-agent/issues/1211
              sub_key = key[:2]
              if sub_key in self.db_bgw_metrics:
                  self.bgw_metrics[key] = None
                  self.log.debug(
                      "Not collecting bgw metrics for key: {0} as "
                      "they are already collected by another instance".format(key)
                  )
                  return None
  
              self.db_bgw_metrics.append(sub_key)
  
              self.bgw_metrics[key] = dict(self.COMMON_BGW_METRICS)
              if self._is_9_1_or_above(key, db):
                  self.bgw_metrics[key].update(self.NEWER_91_BGW_METRICS)
              if self._is_9_2_or_above(key, db):
                  self.bgw_metrics[key].update(self.NEWER_92_BGW_METRICS)
  
              metrics = self.bgw_metrics.get(key)
  
          if not metrics:
              return None
  
          return {'descriptors': [], 'metrics': metrics, 'query': "select %s FROM pg_stat_bgwriter", 'relation': False}
docs: Use either COMMON_BGW_METRICS or COMMON_BGW_METRICS + NEWER_92_BGW_METRICS
          depending on the postgres version.
          Uses a dictionnary to save the result for each instance