Filippo Giunchedi has submitted this change and it was merged. Change subject: VarnishStatusCollector for diamond. ......................................................................
VarnishStatusCollector for diamond. This is needed to collect specific request stats for T88705 Bug: T88705 Change-Id: I1b4448653d1cfe6420f23b87df792256e4d762be --- M manifests/role/beta.pp A modules/diamond/files/collector/varnishstatus.py 2 files changed, 101 insertions(+), 0 deletions(-) Approvals: Filippo Giunchedi: Verified; Looks good to me, approved diff --git a/manifests/role/beta.pp b/manifests/role/beta.pp index ec07dbc..ad994b6 100644 --- a/manifests/role/beta.pp +++ b/manifests/role/beta.pp @@ -47,3 +47,16 @@ logstash_port => 5229, } } + +# = Class: role::beta::availability_collector +# collect availability metrics for the beta / staging clusters +class role::beta::availability_collector { + include ::diamond + diamond::collector { 'VarnishStatus': + source => 'puppet:///modules/diamond/collector/varnishstatus.py', + settings => { + path_prefix => $::instanceproject, + path => 'availability', + } + } +} diff --git a/modules/diamond/files/collector/varnishstatus.py b/modules/diamond/files/collector/varnishstatus.py new file mode 100644 index 0000000..b949b3f --- /dev/null +++ b/modules/diamond/files/collector/varnishstatus.py @@ -0,0 +1,88 @@ +""" +Collect request status code metrics from varnish (by using varnishtop) +Used to collect beta / staging cluster availability metrics + +#### Dependencies + + * subprocess +""" + +from diamond.collector import Collector +import subprocess + + +class VarnishStatusCollector(Collector): + + def get_default_config(self): + """ + Returns the default collector settings + """ + config = super(VarnishStatusCollector, self).get_default_config() + config.update({ + 'path': 'availability', + 'bin': '/usr/bin/varnishtop', + }) + return config + + def collect(self): + """ + Publishes stats to the configured path. + e.g. /deployment-prep/hostname/availability/# + with one # for each http status code + """ + group_by_type = {'2xx': 0, '3xx': 0, '4xx': 0, '5xx': 0} + total = 0 + lines = self.poll() + # Publish Metric + for line in lines: + parts = line.split() + if (len(parts) == 3): + count = int(float(parts[0])) + total += count + code = parts[2] + type = code[:1] + 'xx' + group_by_type[type] = group_by_type.setdefault(type, 0) + count + self.publish_gauge(code, count) + + for k, v in group_by_type.iteritems(): + if v > 0: + self.publish_gauge(k, v) + + success_count = group_by_type['2xx'] + group_by_type['3xx'] + + # calculate the percentage of successful out of the total request count + if success_count > 0: + self.publish_gauge('ok', success_count) + ratio = float(success_count) / float(total) + self.publish_gauge('availability', 100 * ratio) + + def poll(self): + """ + This runs `varnishtop -c -i TxStatus -1` + which returns output like the following: + + 58888.00 TxStatus 200 + 1050.00 TxStatus 302 + 65.00 TxStatus 404 + 40.00 TxStatus 503 + 29.00 TxStatus 204 + 19.00 TxStatus 401 + 18.00 TxStatus 301 + 3.00 TxStatus 304 + + The 1st column is a request status counter, 2nd is irrelevant + 3rd is the http status code + + This method returns the output from the command, + split into 1 element per line. + """ + + try: + command = [self.config['bin'], "-c", "-i", "TxStatus", "-1"] + output = subprocess.check_output(command) + + except Exception as e: + self.log.error("Error: %s", e) + output = "" + + return output.splitlines() -- To view, visit https://gerrit.wikimedia.org/r/199302 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I1b4448653d1cfe6420f23b87df792256e4d762be Gerrit-PatchSet: 19 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: 20after4 <mmod...@wikimedia.org> Gerrit-Reviewer: 20after4 <mmod...@wikimedia.org> Gerrit-Reviewer: Chad <ch...@wikimedia.org> Gerrit-Reviewer: Filippo Giunchedi <fgiunch...@wikimedia.org> Gerrit-Reviewer: Yuvipanda <yuvipa...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits