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

[varnish] allow tags in varnish 3 xml style parsing #1645

Merged
merged 1 commit into from
May 27, 2015
Merged
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
9 changes: 5 additions & 4 deletions checks.d/varnish.py
Original file line number Diff line number Diff line change
@@ -35,13 +35,13 @@ def _reset(self):
def _start_element(self, name, attrs):
self._current_element = name

def _end_element(self, name):
def _end_element(self, name, tags):
if name == "stat":
m_name = self.normalize(self._current_metric)
if self._current_type in ("a", "c"):
self.rate(m_name, long(self._current_value))
self.rate(m_name, long(self._current_value), tags=tags)
elif self._current_type in ("i", "g"):
self.gauge(m_name, long(self._current_value))
self.gauge(m_name, long(self._current_value), tags=tags)
else:
# Unsupported data type, ignore
self._reset()
@@ -182,7 +182,8 @@ def _parse_varnishstat(self, output, use_xml, tags=None):
if use_xml:
p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = self._start_element
p.EndElementHandler = self._end_element
end_handler = lambda name: self._end_element(name, tags)
p.EndElementHandler = end_handler
p.CharacterDataHandler = self._char_data
self._reset()
p.Parse(output, True)
4 changes: 2 additions & 2 deletions tests/checks/integration/test_varnish.py
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ def test_check(self):
config = {
'instances': [{
'varnishstat': varnishstat_path,
'tags': 'cluster:webs'
'tags': ['cluster:webs']
}]
}

@@ -117,6 +117,6 @@ def test_check(self):
to_check.extend(METRICS_4_X)

for mname in to_check:
self.assertMetric(mname, count=1)
self.assertMetric(mname, count=1, tags=['cluster:webs', 'varnish_name:default'])

self.coverage_report()