Skip to content

Commit

Permalink
Resolve unexpected errors when statuses other than 'running' or 'idle…
Browse files Browse the repository at this point in the history
…' is received

same as 9428
  • Loading branch information
ian28223 committed Oct 5, 2021
1 parent 181052c commit 23c6115
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions sap_hana/datadog_checks/sap_hana/sap_hana.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def check(self, instance):
self.log.error('Error querying %s: %s', e.source(), str(e))
continue
except Exception as e:
self.log.error('Unexpected error running `%s`: %s', query_method.__name__, str(e))
self.log.exception('Unexpected error running `%s`: %s', query_method.__name__, str(e))
continue
finally:
if self._connection_lost:
Expand Down Expand Up @@ -193,8 +193,9 @@ def query_licenses(self):
self.gauge('license.utilized', utilized, tags=tags, hostname=host)

def query_connection_overview(self):
# https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.02/en-US/20abcf1f75191014a254a82b3d0f66bf.html
db_counts = defaultdict(lambda: {'running': 0, 'idle': 0})
# https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.05/en-US/20abcf1f75191014a254a82b3d0f66bf.html
# Documented statuses: RUNNING, IDLE, QUEUING, EMPTY
db_counts = defaultdict(lambda: defaultdict(int))
for conn in self.iter_rows(queries.GlobalSystemConnectionsStatus):
db_counts[(conn['db_name'], conn['host'], conn['port'])][conn['status'].lower()] += conn['total']

Expand All @@ -206,10 +207,14 @@ def query_connection_overview(self):
host = self.get_hana_hostname(host)
running = counts['running']
idle = counts['idle']
queuing = counts['queuing']
empty = counts['empty']

self.gauge('connection.running', running, tags=tags, hostname=host)
self.gauge('connection.idle', idle, tags=tags, hostname=host)
self.gauge('connection.open', running + idle, tags=tags, hostname=host)
self.gauge('connection.queuing', queuing, tags=tags, hostname=host)
self.gauge('connection.empty', empty, tags=tags, hostname=host)

def query_disk_usage(self):
# https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.02/en-US/a2aac2ee72b341699fa8eb3988d8cecb.html
Expand Down
2 changes: 2 additions & 0 deletions sap_hana/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ sap_hana.backup.latest,gauge,,second,,The time elapsed since the latest database
sap_hana.connection.idle,gauge,,connection,,The current number of idle connections.,0,sap_hana,
sap_hana.connection.open,gauge,,connection,,The current number of connections.,0,sap_hana,
sap_hana.connection.running,gauge,,connection,,The current number of running connections.,0,sap_hana,
sap_hana.connection.queuing,gauge,,connection,,The current number of queued connections.,0,sap_hana,
sap_hana.connection.empty,gauge,,connection,,Historic connections that are removed after a period of time.,0,sap_hana,
sap_hana.cpu.service.utilized,gauge,,percent,,The CPU utilization of services as a percentage.,0,sap_hana,
sap_hana.disk.free,gauge,,byte,,The total free size of the disk in bytes.,1,sap_hana,
sap_hana.disk.size,gauge,,byte,,The total size of the disk in bytes.,0,sap_hana,
Expand Down
2 changes: 2 additions & 0 deletions sap_hana/tests/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
'sap_hana.connection.open',
'sap_hana.connection.running',
'sap_hana.cpu.service.utilized',
'sap_hana.connection.queuing',
'sap_hana.connection.empty',
'sap_hana.disk.free',
'sap_hana.disk.size',
'sap_hana.disk.used',
Expand Down
2 changes: 1 addition & 1 deletion sap_hana/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def query_master_database():
check.query_master_database = query_master_database

check.check(None)
check.log.error.assert_any_call('Unexpected error running `%s`: %s', 'query_master_database', 'test')
check.log.exception.assert_any_call('Unexpected error running `%s`: %s', 'query_master_database', 'test')


def test_custom_query_configuration(instance):
Expand Down

0 comments on commit 23c6115

Please sign in to comment.