@@ -821,6 +821,7 @@ def _check_database_conns(self):
821
821
self ._check_connections_by_use_db ()
822
822
823
823
def check (self , _ ):
824
+ self .log .error ("[EG] blooob" )
824
825
if self .do_check :
825
826
self .load_static_information ()
826
827
# configure custom queries for the check
@@ -830,11 +831,15 @@ def check(self, _):
830
831
self , self .execute_query_raw , tags = self .tag_manager .get_tags (), hostname = self .reported_hostname
831
832
)
832
833
self ._query_manager .compile_queries ()
834
+
833
835
self ._send_database_instance_metadata ()
836
+
834
837
if self ._config .proc :
835
838
self .do_stored_procedure_check ()
836
839
else :
837
840
self .collect_metrics ()
841
+
842
+ self .log .error ("[EG] I am right here!!!! blub" )
838
843
if self ._config .autodiscovery and self ._config .autodiscovery_db_service_check :
839
844
self ._check_database_conns ()
840
845
if self ._config .dbm_enabled :
@@ -852,6 +857,7 @@ def check(self, _):
852
857
handler .run_job_loop (self .tag_manager .get_tags ())
853
858
except Exception as e :
854
859
self .log .error ("Error running XE session handler for %s: %s" , handler .session_name , e )
860
+
855
861
else :
856
862
self .log .debug ("Skipping check" )
857
863
@@ -926,52 +932,56 @@ def log_missing_metric(self, metric_name, major_version, engine_version):
926
932
else :
927
933
self .log .warning ("%s metrics are not supported on Azure engine version: %s" , metric_name , engine_version )
928
934
929
- def collect_metrics (self ):
930
- """Fetch the metrics from all the associated database tables."""
935
+ # queries for default integration metrics from the database
936
+ def load_basic_metrics (self , cursor ):
937
+ # initiate autodiscovery or if the server was down at check __init__ key could be missing.
938
+ if self .autodiscover_databases (cursor ) or not self .instance_metrics :
939
+ self ._make_metric_list_to_collect (self ._config .custom_metrics )
940
+
941
+ instance_results = {}
942
+ engine_edition = self .static_info_cache .get (STATIC_INFO_ENGINE_EDITION , "" )
943
+ # Execute the `fetch_all` operations first to minimize the database calls
944
+ for cls , metric_names in self .instance_per_type_metrics .items ():
945
+ if not metric_names :
946
+ instance_results [cls ] = None , None
947
+ else :
948
+ try :
949
+ db_names = [d .name for d in self .databases ] or [
950
+ self .instance .get ("database" , self .connection .DEFAULT_DATABASE )
951
+ ]
952
+ metric_cls = getattr (metrics , cls )
953
+ with tracked_query (self , operation = metric_cls .OPERATION_NAME ):
954
+ rows , cols = metric_cls .fetch_all_values (
955
+ cursor ,
956
+ list (metric_names ),
957
+ self .log ,
958
+ databases = db_names ,
959
+ engine_edition = engine_edition ,
960
+ )
961
+ except Exception as e :
962
+ self .log .error ("Error running `fetch_all` for metrics %s - skipping. Error: %s" , cls , e )
963
+ rows , cols = None , None
931
964
932
- with self .connection .open_managed_default_connection ():
933
- with self .connection .get_managed_cursor () as cursor :
934
- # initiate autodiscovery or if the server was down at check __init__ key could be missing.
935
- if self .autodiscover_databases (cursor ) or not self .instance_metrics :
936
- self ._make_metric_list_to_collect (self ._config .custom_metrics )
965
+ instance_results [cls ] = rows , cols
937
966
938
- instance_results = {}
939
- engine_edition = self .static_info_cache .get (STATIC_INFO_ENGINE_EDITION , "" )
940
- # Execute the `fetch_all` operations first to minimize the database calls
941
- for cls , metric_names in self .instance_per_type_metrics .items ():
942
- if not metric_names :
943
- instance_results [cls ] = None , None
967
+ for metric in self .instance_metrics :
968
+ key = metric .__class__ .__name__
969
+ if key not in instance_results :
970
+ self .log .warning ("No %s metrics found, skipping" , str (key ))
971
+ else :
972
+ rows , cols = instance_results [key ]
973
+ if rows is not None :
974
+ if key == "SqlIncrFractionMetric" :
975
+ metric .fetch_metric (rows , cols , self .sqlserver_incr_fraction_metric_previous_values )
944
976
else :
945
- try :
946
- db_names = [d .name for d in self .databases ] or [
947
- self .instance .get ("database" , self .connection .DEFAULT_DATABASE )
948
- ]
949
- metric_cls = getattr (metrics , cls )
950
- with tracked_query (self , operation = metric_cls .OPERATION_NAME ):
951
- rows , cols = metric_cls .fetch_all_values (
952
- cursor ,
953
- list (metric_names ),
954
- self .log ,
955
- databases = db_names ,
956
- engine_edition = engine_edition ,
957
- )
958
- except Exception as e :
959
- self .log .error ("Error running `fetch_all` for metrics %s - skipping. Error: %s" , cls , e )
960
- rows , cols = None , None
961
-
962
- instance_results [cls ] = rows , cols
977
+ metric .fetch_metric (rows , cols )
963
978
964
- for metric in self .instance_metrics :
965
- key = metric .__class__ .__name__
966
- if key not in instance_results :
967
- self .log .warning ("No %s metrics found, skipping" , str (key ))
968
- else :
969
- rows , cols = instance_results [key ]
970
- if rows is not None :
971
- if key == "SqlIncrFractionMetric" :
972
- metric .fetch_metric (rows , cols , self .sqlserver_incr_fraction_metric_previous_values )
973
- else :
974
- metric .fetch_metric (rows , cols )
979
+ def collect_metrics (self ):
980
+ """Fetch the metrics from all the associated database tables."""
981
+ with self .connection .open_managed_default_connection ():
982
+ if not self ._config .only_custom_queries :
983
+ with self .connection .get_managed_cursor () as cursor :
984
+ self .load_basic_metrics (cursor )
975
985
976
986
# Neither pyodbc nor adodbapi are able to read results of a query if the number of rows affected
977
987
# statement are returned as part of the result set, so we disable for the entire connection
@@ -980,14 +990,15 @@ def collect_metrics(self):
980
990
with self .connection .get_managed_cursor () as cursor :
981
991
cursor .execute ("SET NOCOUNT ON" )
982
992
try :
983
- # restore the current database after executing dynamic queries
984
- # this is to ensure the current database context is not changed
985
- with self .connection .restore_current_database_context ():
986
- if self .database_metrics :
987
- for database_metric in self .database_metrics :
988
- database_metric .execute ()
989
-
990
- # reuse connection for any custom queries
993
+ if not self ._config .only_custom_queries :
994
+ # restore the current database after executing dynamic queries
995
+ # this is to ensure the current database context is not changed
996
+ with self .connection .restore_current_database_context ():
997
+ if self .database_metrics :
998
+ for database_metric in self .database_metrics :
999
+ database_metric .execute ()
1000
+
1001
+ # reuse the connection for custom queries
991
1002
self ._query_manager .execute ()
992
1003
finally :
993
1004
with self .connection .get_managed_cursor () as cursor :
0 commit comments