(self, version)
return res
Add NEWER_92_METRICS to the default set of COMMON_METRICS when server
        version is 9.2 or later.

        Store the list of metrics in the check instance to avoid rebuilding it at
        every collection cycle.

        In case we have multiple instances pointing to the same postgres server
        monitoring different databases, we want to collect server metrics
        only once. See https://github.com/DataDog/dd-agent/issues/1211
Add NEWER_92_METRICS to the default set of COMMON_METRICS when server
        version is 9.2 or later.
Add NEWER_92_METRICS to the default set of COMMON_METRICS when server version is 9 . 2 or later .
def get_instance_metrics(self, version):
        """
        Add NEWER_92_METRICS to the default set of COMMON_METRICS when server
        version is 9.2 or later.

        Store the list of metrics in the check instance to avoid rebuilding it at
        every collection cycle.

        In case we have multiple instances pointing to the same postgres server
        monitoring different databases, we want to collect server metrics
        only once. See https://github.com/DataDog/dd-agent/issues/1211
        """
        metrics = self.instance_metrics
        if metrics is None:
            # if DBM enabled, do not collect postgresql.connections metric in the main check
            c_metrics = COMMON_METRICS
            if not self.config.dbm_enabled:
                c_metrics = dict(c_metrics, **DBM_MIGRATED_METRICS)
            # select the right set of metrics to collect depending on postgres version
            if version >= V9_2:
                self.instance_metrics = dict(c_metrics, **NEWER_92_METRICS)
            else:
                self.instance_metrics = dict(c_metrics)

            # add size metrics if needed
            if self.config.collect_database_size_metrics:
                self.instance_metrics.update(DATABASE_SIZE_METRICS)

            metrics = self.instance_metrics

        res = {
            'descriptors': [('psd.datname', 'db')],
            'metrics': metrics,
            'query': "SELECT psd.datname, {metrics_columns} "
            "FROM pg_stat_database psd "
            "JOIN pg_database pd ON psd.datname = pd.datname",
            'relation': False,
        }

        res["query"] += " WHERE " + " AND ".join(
            "psd.datname not ilike '{}'".format(db) for db in self.config.ignore_databases
        )

        if self.config.dbstrict:
            res["query"] += " AND psd.datname in('{}')".format(self.config.dbname)

        return res
def get_instance_metrics ( self , version ) : metrics = self . instance_metrics if metrics is None : # if DBM enabled, do not collect postgresql.connections metric in the main check c_metrics = COMMON_METRICS if not self . config . dbm_enabled : c_metrics = dict ( c_metrics , * * DBM_MIGRATED_METRICS ) # select the right set of metrics to collect depending on postgres version if version >= V9_2 : self . instance_metrics = dict ( c_metrics , * * NEWER_92_METRICS ) else : self . instance_metrics = dict ( c_metrics ) # add size metrics if needed if self . config . collect_database_size_metrics : self . instance_metrics . update ( DATABASE_SIZE_METRICS ) metrics = self . instance_metrics res = { 'descriptors' : [ ( 'psd.datname' , 'db' ) ] , 'metrics' : metrics , 'query' : "SELECT psd.datname, {metrics_columns} " "FROM pg_stat_database psd " "JOIN pg_database pd ON psd.datname = pd.datname" , 'relation' : False , } res [ "query" ] += " WHERE " + " AND " . join ( "psd.datname not ilike '{}'" . format ( db ) for db in self . config . ignore_databases ) if self . config . dbstrict : res [ "query" ] += " AND psd.datname in('{}')" . format ( self . config . dbname ) return res