(self, instance_tags)
Query pg_stat_* for various metrics
        If relations is not an empty list, gather per-relation metrics
        on top of that.
        If custom_metrics is not an empty list, gather custom metrics defined in postgres.yaml
Query pg_stat_* for various metrics
        If relations is not an empty list, gather per-relation metrics
        on top of that.
        If custom_metrics is not an empty list, gather custom metrics defined in postgres.yaml
Query pg_stat_ * for various metrics If relations is not an empty list gather per - relation metrics on top of that . If custom_metrics is not an empty list gather custom metrics defined in postgres . yaml
def _collect_stats(self, instance_tags):
        """Query pg_stat_* for various metrics
        If relations is not an empty list, gather per-relation metrics
        on top of that.
        If custom_metrics is not an empty list, gather custom metrics defined in postgres.yaml
        """
        db_instance_metrics = self.metrics_cache.get_instance_metrics(self.version)
        bgw_instance_metrics = self.metrics_cache.get_bgw_metrics(self.version)
        archiver_instance_metrics = self.metrics_cache.get_archiver_metrics(self.version)

        metric_scope = [CONNECTION_METRICS]

        if self._config.collect_function_metrics:
            metric_scope.append(FUNCTION_METRICS)
        if self._config.collect_count_metrics:
            metric_scope.append(self.metrics_cache.get_count_metrics())

        # Do we need relation-specific metrics?
        if self._config.relations:
            metric_scope.extend(RELATION_METRICS)
            if self._config.collect_bloat_metrics:
                metric_scope.extend([INDEX_BLOAT, TABLE_BLOAT])

        replication_metrics = self.metrics_cache.get_replication_metrics(self.version, self.is_aurora)
        if replication_metrics:
            replication_metrics_query = copy.deepcopy(REPLICATION_METRICS)
            replication_metrics_query['metrics'] = replication_metrics
            metric_scope.append(replication_metrics_query)

        replication_stats_metrics = self.metrics_cache.get_replication_stats_metrics(self.version)
        if replication_stats_metrics:
            metric_scope.append(replication_stats_metrics)

        cursor = self.db.cursor()
        results_len = self._query_scope(cursor, db_instance_metrics, instance_tags, False)
        if results_len is not None:
            self.gauge(
                "postgresql.db.count",
                results_len,
                tags=[t for t in instance_tags if not t.startswith("db:")],
                hostname=self.resolved_hostname,
            )

        self._query_scope(cursor, bgw_instance_metrics, instance_tags, False)
        self._query_scope(cursor, archiver_instance_metrics, instance_tags, False)

        if self._config.collect_activity_metrics:
            activity_metrics = self.metrics_cache.get_activity_metrics(self.version)
            self._query_scope(cursor, activity_metrics, instance_tags, False)

        for scope in list(metric_scope) + self._config.custom_metrics:
            self._query_scope(cursor, scope, instance_tags, scope in self._config.custom_metrics)

        cursor.close()
def _collect_stats ( self , instance_tags ) : db_instance_metrics = self . metrics_cache . get_instance_metrics ( self . version ) bgw_instance_metrics = self . metrics_cache . get_bgw_metrics ( self . version ) archiver_instance_metrics = self . metrics_cache . get_archiver_metrics ( self . version ) metric_scope = [ CONNECTION_METRICS ] if self . _config . collect_function_metrics : metric_scope . append ( FUNCTION_METRICS ) if self . _config . collect_count_metrics : metric_scope . append ( self . metrics_cache . get_count_metrics ( ) ) # Do we need relation-specific metrics? if self . _config . relations : metric_scope . extend ( RELATION_METRICS ) if self . _config . collect_bloat_metrics : metric_scope . extend ( [ INDEX_BLOAT , TABLE_BLOAT ] ) replication_metrics = self . metrics_cache . get_replication_metrics ( self . version , self . is_aurora ) if replication_metrics : replication_metrics_query = copy . deepcopy ( REPLICATION_METRICS ) replication_metrics_query [ 'metrics' ] = replication_metrics metric_scope . append ( replication_metrics_query ) replication_stats_metrics = self . metrics_cache . get_replication_stats_metrics ( self . version ) if replication_stats_metrics : metric_scope . append ( replication_stats_metrics ) cursor = self . db . cursor ( ) results_len = self . _query_scope ( cursor , db_instance_metrics , instance_tags , False ) if results_len is not None : self . gauge ( "postgresql.db.count" , results_len , tags = [ t for t in instance_tags if not t . startswith ( "db:" ) ] , hostname = self . resolved_hostname , ) self . _query_scope ( cursor , bgw_instance_metrics , instance_tags , False ) self . _query_scope ( cursor , archiver_instance_metrics , instance_tags , False ) if self . _config . collect_activity_metrics : activity_metrics = self . metrics_cache . get_activity_metrics ( self . version ) self . _query_scope ( cursor , activity_metrics , instance_tags , False ) for scope in list ( metric_scope ) + self . _config . custom_metrics : self . _query_scope ( cursor , scope , instance_tags , scope in self . _config . custom_metrics ) cursor . close ( )