(self)
Fetch the metrics from all of the associated database tables.
Fetch the metrics from all of the associated database tables.
Fetch the metrics from all of the associated database tables .
def collect_metrics(self):
        """Fetch the metrics from all of the associated database tables."""

        with self.connection.open_managed_default_connection():
            with self.connection.get_managed_cursor() as cursor:
                # initiate autodiscovery or if the server was down at check __init__ key could be missing.
                if self.autodiscover_databases(cursor) or not self.instance_metrics:
                    self._make_metric_list_to_collect(self.custom_metrics)

                instance_results = {}

                # Execute the `fetch_all` operations first to minimize the database calls
                for cls, metric_names in six.iteritems(self.instance_per_type_metrics):
                    if not metric_names:
                        instance_results[cls] = None, None
                    else:
                        try:
                            db_names = self.databases or [
                                self.instance.get('database', self.connection.DEFAULT_DATABASE)
                            ]
                            rows, cols = getattr(metrics, cls).fetch_all_values(
                                cursor, list(metric_names), self.log, databases=db_names
                            )
                        except Exception as e:
                            self.log.error("Error running `fetch_all` for metrics %s - skipping.  Error: %s", cls, e)
                            rows, cols = None, None

                        instance_results[cls] = rows, cols

                # Using the cached data, extract and report individual metrics
                for metric in self.instance_metrics:
                    if type(metric) is metrics.SqlIncrFractionMetric:
                        # special case, since it uses the same results as SqlFractionMetric
                        key = 'SqlFractionMetric'
                    else:
                        key = metric.__class__.__name__

                    if key not in instance_results:
                        self.log.warning("No %s metrics found, skipping", str(key))
                    else:
                        rows, cols = instance_results[key]
                        if rows is not None:
                            metric.fetch_metric(rows, cols)

            # reuse connection for any custom queries
            self._query_manager.execute()
def collect_metrics ( self ) : with self . connection . open_managed_default_connection ( ) : with self . connection . get_managed_cursor ( ) as cursor : # initiate autodiscovery or if the server was down at check __init__ key could be missing. if self . autodiscover_databases ( cursor ) or not self . instance_metrics : self . _make_metric_list_to_collect ( self . custom_metrics ) instance_results = { } # Execute the `fetch_all` operations first to minimize the database calls for cls , metric_names in six . iteritems ( self . instance_per_type_metrics ) : if not metric_names : instance_results [ cls ] = None , None else : try : db_names = self . databases or [ self . instance . get ( 'database' , self . connection . DEFAULT_DATABASE ) ] rows , cols = getattr ( metrics , cls ) . fetch_all_values ( cursor , list ( metric_names ) , self . log , databases = db_names ) except Exception as e : self . log . error ( "Error running `fetch_all` for metrics %s - skipping.  Error: %s" , cls , e ) rows , cols = None , None instance_results [ cls ] = rows , cols # Using the cached data, extract and report individual metrics for metric in self . instance_metrics : if type ( metric ) is metrics . SqlIncrFractionMetric : # special case, since it uses the same results as SqlFractionMetric key = 'SqlFractionMetric' else : key = metric . __class__ . __name__ if key not in instance_results : self . log . warning ( "No %s metrics found, skipping" , str ( key ) ) else : rows , cols = instance_results [ key ] if rows is not None : metric . fetch_metric ( rows , cols ) # reuse connection for any custom queries self . _query_manager . execute ( )