Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optional custom tags in SQL Server check. #654

Merged
merged 1 commit into from
Sep 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions checks.d/sqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def check(self, instance):
username = instance.get('username')
password = instance.get('password')
database = instance.get('database', 'master')
tags = instance.get('tags', [])
conn_key = self._conn_key(host, username, password, database)

if conn_key not in self.connections:
Expand All @@ -75,9 +76,9 @@ def check(self, instance):

conn = self.connections[conn_key]
cursor = conn.cursor()
self._fetch_metrics(cursor)
self._fetch_metrics(cursor, tags)

def _fetch_metrics(self, cursor):
def _fetch_metrics(self, cursor, custom_tags):
''' Fetch the metrics from the sys.dm_os_performance_counters table
'''
for metric in self.METRICS:
Expand All @@ -93,7 +94,7 @@ def _fetch_metrics(self, cursor):
# to loop over multiple results and tag the metrics
if instance_n == ALL_INSTANCES:
try:
self._fetch_all_instances(metric, cursor)
self._fetch_all_instances(metric, cursor, custom_tags)
except Exception, e:
self.log.exception('Unable to fetch metric: %s' % mname)
self.warning('Unable to fetch metric: %s' % mname)
Expand All @@ -113,9 +114,9 @@ def _fetch_metrics(self, cursor):

# Save the metric
metric_func = getattr(self, mtype)
metric_func(mname, value)
metric_func(mname, value, tags=custom_tags)

def _fetch_all_instances(self, metric, cursor):
def _fetch_all_instances(self, metric, cursor, custom_tags):
mname, mtype, counter, instance_n, tag_by = metric
cursor.execute("""
select instance_name, cntr_value
Expand All @@ -127,7 +128,7 @@ def _fetch_all_instances(self, metric, cursor):

for instance_name, cntr_value in rows:
value = cntr_value
tags = ['%s:%s' % (tag_by, instance_name.strip())]
tags = ['%s:%s' % (tag_by, instance_name.strip())] + custom_tags
metric_func = getattr(self, mtype)
metric_func(mname, value, tags=tags)

2 changes: 2 additions & 0 deletions conf.d/sqlserver.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ instances:
- host: HOST,PORT
username: my_username
password: my_password
tags:
- optional_tag