Skip to content

Commit

Permalink
[sqlserver] add command/connection timeout
Browse files Browse the repository at this point in the history
10s default, it shouldn't break any existing check, as it is
a timeout for each command.
[skip ci]
(as it is a Windows check not tested)
  • Loading branch information
degemer committed May 19, 2015
1 parent 4653764 commit 3a0a843
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions checks.d/sqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SQLServer(AgentCheck):

SOURCE_TYPE_NAME = 'sql server'
SERVICE_CHECK_NAME = 'sqlserver.can_connect'
DEFAULT_COMMAND_TIMEOUT = 10

METRICS = [
('sqlserver.buffer.cache_hit_ratio', 'Buffer cache hit ratio', ''), # RAW_LARGE_FRACTION
Expand Down Expand Up @@ -181,8 +182,11 @@ def get_cursor(self, instance):

if conn_key not in self.connections:
try:
conn_str = self._conn_string(instance)
conn = adodbapi.connect(conn_str)
conn = adodbapi.connect(
self._conn_string(instance),
timeout=int(instance.get('command_timeout',
self.DEFAULT_COMMAND_TIMEOUT))
)
self.connections[conn_key] = conn
self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.OK, tags=service_check_tags)
except Exception:
Expand Down
1 change: 1 addition & 0 deletions conf.d/sqlserver.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ instances:
- host: HOST,PORT
username: my_username
password: my_password
# command_timeout: 5 # Optional, timeout for each command run (so for each metric)
# database: my_database # Optional, defaults to "master"
tags:
- optional_tag

0 comments on commit 3a0a843

Please sign in to comment.