Ema has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/326132 )
Change subject: varnish: add varnish hitrate dstat plugin ...................................................................... varnish: add varnish hitrate dstat plugin dstat_varnish_hit is a plugin for dstat allowing to display varnish hitrate statistics in dstat. Usage: dstat --varnish-hit Change-Id: I40684205b4b6dd28afe62d5aae8419712fe5c29d --- A modules/varnish/files/dstat_varnish_hit.py 1 file changed, 86 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/puppet refs/changes/32/326132/1 diff --git a/modules/varnish/files/dstat_varnish_hit.py b/modules/varnish/files/dstat_varnish_hit.py new file mode 100644 index 0000000..446669a --- /dev/null +++ b/modules/varnish/files/dstat_varnish_hit.py @@ -0,0 +1,86 @@ +""" +Display varnish hitrate in dstat + +Usage: dstat --varnish-hit + + Copyright 2016 Emanuele Rocca <e...@wikimedia.org> + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +""" + +class dstat_plugin(dstat): # noqa F821 undefined name 'dstat' + """ + Display varnish cache miss/hit percentages in dstat + """ + def __init__(self): + self.name = 'hitrate' + self.vars = ('fe-hitrate', 'be-hitrate') + self.nick = ('fe%', 'be%') + self.type = 'd' + #self.width = 6 + self.scale = 10 + + # Initial values + self.values = { + 'be': self.varnishstat(frontend=False), + 'fe': self.varnishstat(frontend=True), + } + + def check(self): + if os.system("varnishstat -1 > /dev/null") != 0: + raise Exception, 'Non-zero exit code from varnishstat' + + def varnishstat(self, frontend=False): + """ + {'be-cache_hit': 185.61, 'be-cache_miss': 52.42, 'be-s_req': 2480.98, 'be-s_pass': 0.21, 'be-s_synth': 2242.82} + {'fe-s_pass': 0.71, 'fe-cache_miss': 317.95, 'fe-cache_hit': 556.74, 'fe-s_synth': 2245.61, 'fe-s_req': 3121.01} + """ + cmd = "varnishstat -1 -f MAIN.cache_hit -f MAIN.cache_miss" + + if frontend: + cmd += " -n frontend" + + data = os.popen(cmd) + total = {} + for line in data.readlines(): + row = line.split() + if not row: + continue + + item = row[0].replace("MAIN.", "") + # Use third column, change per second + value = float(row[1]) + total[item] = value + + return total + + def hitrate(self, frontend=False): + if frontend: + label = "fe" + else: + label = "be" + + values = self.varnishstat(frontend) + hit = values['cache_hit'] - self.values[label]['cache_hit'] + miss = values['cache_miss'] - self.values[label]['cache_miss'] + self.val[label + "-hitrate"] = 100 * (hit / (0.0001 + hit + miss)) + + if frontend: + self.values['fe'] = values + else: + self.values['be'] = values + + def extract(self): + self.hitrate(frontend=False) + self.hitrate(frontend=True) -- To view, visit https://gerrit.wikimedia.org/r/326132 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I40684205b4b6dd28afe62d5aae8419712fe5c29d Gerrit-PatchSet: 1 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Ema <e...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits