(self)
Collects statement metrics and plans.
        :return:
Collects statement metrics and plans.
        :return:
Collects statement metrics and plans . : return :
def collect_statement_metrics_and_plans(self):
        """
        Collects statement metrics and plans.
        :return:
        """
        plans_submitted = 0
        deadline = time.time() + self.collection_interval

        # re-use the check's conn module, but set extra_key=dbm- to ensure we get our own
        # raw connection. adodbapi and pyodbc modules are thread safe, but connections are not.
        with self.check.connection.open_managed_default_connection(key_prefix=self._conn_key_prefix):
            with self.check.connection.get_managed_cursor(key_prefix=self._conn_key_prefix) as cursor:
                rows = self._collect_metrics_rows(cursor)
                if not rows:
                    return
                for event in self._rows_to_fqt_events(rows):
                    self.check.database_monitoring_query_sample(json.dumps(event, default=default_json_event_encoding))
                payload = self._to_metrics_payload(rows)
                self.check.database_monitoring_query_metrics(json.dumps(payload, default=default_json_event_encoding))
                for event in self._collect_plans(rows, cursor, deadline):
                    self.check.database_monitoring_query_sample(json.dumps(event, default=default_json_event_encoding))
                    plans_submitted += 1

        self.check.count(
            "dd.sqlserver.statements.plans_submitted.count", plans_submitted, **self.check.debug_stats_kwargs()
        )
        self.check.gauge(
            "dd.sqlserver.statements.seen_plans_cache.len",
            len(self._seen_plans_ratelimiter),
            **self.check.debug_stats_kwargs()
        )
        self.check.gauge(
            "dd.sqlserver.statements.fqt_cache.len",
            len(self._full_statement_text_cache),
            **self.check.debug_stats_kwargs()
        )
def collect_statement_metrics_and_plans ( self ) : plans_submitted = 0 deadline = time . time ( ) + self . collection_interval # re-use the check's conn module, but set extra_key=dbm- to ensure we get our own # raw connection. adodbapi and pyodbc modules are thread safe, but connections are not. with self . check . connection . open_managed_default_connection ( key_prefix = self . _conn_key_prefix ) : with self . check . connection . get_managed_cursor ( key_prefix = self . _conn_key_prefix ) as cursor : rows = self . _collect_metrics_rows ( cursor ) if not rows : return for event in self . _rows_to_fqt_events ( rows ) : self . check . database_monitoring_query_sample ( json . dumps ( event , default = default_json_event_encoding ) ) payload = self . _to_metrics_payload ( rows ) self . check . database_monitoring_query_metrics ( json . dumps ( payload , default = default_json_event_encoding ) ) for event in self . _collect_plans ( rows , cursor , deadline ) : self . check . database_monitoring_query_sample ( json . dumps ( event , default = default_json_event_encoding ) ) plans_submitted += 1 self . check . count ( "dd.sqlserver.statements.plans_submitted.count" , plans_submitted , * * self . check . debug_stats_kwargs ( ) ) self . check . gauge ( "dd.sqlserver.statements.seen_plans_cache.len" , len ( self . _seen_plans_ratelimiter ) , * * self . check . debug_stats_kwargs ( ) ) self . check . gauge ( "dd.sqlserver.statements.fqt_cache.len" , len ( self . _full_statement_text_cache ) , * * self . check . debug_stats_kwargs ( ) )