BryanDavis has uploaded a new change for review.
https://gerrit.wikimedia.org/r/77975
Change subject: Add ganglia monitoring for vhtcpd.
......................................................................
Add ganglia monitoring for vhtcpd.
Monitor vhtcpd's internal statistics to help spot trends and possible issues
with cache purge requests. See [[bugzilla:43449#c14]].
- Gmond monitoring script that reads from /tmp/vhtcpd.stats
- vhtcpd.pyconf
- New puppet class varnish::monitoring::ganglia::vhtcpd
- Apply puppet class wherever varnish::htcppurger is used
Change-Id: I1f581a94dae5e16353060d3b49f5fe411854e77a
---
M manifests/role/cache.pp
A modules/varnish/files/ganglia/ganglia-vhtcpd.py
A modules/varnish/manifests/monitoring/ganglia/vhtcpd.pp
A modules/varnish/templates/ganglia/vhtcpd.pyconf.erb
4 files changed, 256 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/puppet
refs/changes/75/77975/1
diff --git a/manifests/role/cache.pp b/manifests/role/cache.pp
index 333c7cb..3986fe8 100644
--- a/manifests/role/cache.pp
+++ b/manifests/role/cache.pp
@@ -539,6 +539,8 @@
class { "varnish::htcppurger": varnish_instances => [
"127.0.0.1:80", "127.0.0.1:3128" ] }
+ include varnish::monitoring::ganglia::vhtcpd
+
varnish::instance { "text-backend":
name => "",
vcl => "text-backend",
@@ -672,6 +674,8 @@
}
class { "varnish::htcppurger": varnish_instances => [
"127.0.0.1:80", "127.0.0.1:3128" ] }
+
+ include varnish::monitoring::ganglia::vhtcpd
case $::realm {
'production': {
@@ -937,6 +941,8 @@
class { "varnish::htcppurger": varnish_instances => [
"127.0.0.1:80", "127.0.0.1:3128" ] }
+ include varnish::monitoring::ganglia::vhtcpd
+
varnish::instance { "mobile-backend":
name => "",
vcl => "mobile-backend",
diff --git a/modules/varnish/files/ganglia/ganglia-vhtcpd.py
b/modules/varnish/files/ganglia/ganglia-vhtcpd.py
new file mode 100644
index 0000000..723edae
--- /dev/null
+++ b/modules/varnish/files/ganglia/ganglia-vhtcpd.py
@@ -0,0 +1,195 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (c) 2013 Bryan Davis and Wikimedia Foundation. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+"""Gmond module for vhtcpd statistics
+
+:copyright: (c) 2013 Bryan Davis and Wikimedia Foundation. All Rights Reserved.
+:author: Bryan Davis <[email protected]>
+:license: GPL
+"""
+
+import time
+import copy
+
+CONF = {
+ 'log': '/tmp/vhtcpd.stats',
+ 'prefix': 'vhtcpd_',
+ 'cache_secs': 5,
+ 'groups': 'vhtcpd',
+}
+METRICS = {
+ 'time': 0,
+ 'data': {
+ 'uptime': 0,
+ 'inpkts_recvd': 0,
+ 'inpkts_sane': 0,
+ 'inpkts_enqueued': 0,
+ 'inpkts_dequeued': 0,
+ 'queue_overflows': 0,
+ }
+}
+LAST_METRICS = copy.deepcopy(METRICS)
+
+
+def build_desc (skel, prop):
+ """Build a description dict from a template.
+
+ :param skel: template dict
+ :param prop: substitution dict
+ :returns: New dict
+ """
+ d = skel.copy()
+ for k,v in prop.iteritems():
+ d[k] = v
+ return d
+#end build_desc
+
+
+def get_metrics():
+ """Return all metrics"""
+ global METRICS, LAST_METRICS
+
+ if (time.time() - METRICS['time']) > CONF['cache_secs']:
+ #cache stale, re-read the source file
+ with open(CONF['log'], 'rb') as log_file:
+ raw = log_file.read()
+
+ metrics = {}
+ for chunk in raw.split():
+ (k,v) = chunk.split(':', 2)
+ try:
+ metrics[k] = int(v)
+ except ValueError:
+ metrics[k] = 0
+
+ #update cache
+ LAST_METRICS = copy.deepcopy(METRICS)
+ METRICS = {
+ 'time': time.time(),
+ 'data': metrics,
+ }
+
+ return [METRICS, LAST_METRICS]
+#end get_metrics
+
+
+def clean_name(name):
+ """Strip prefix from metric name."""
+ return name[len(CONF['prefix']):]
+#end clean_name
+
+
+def get_value(name):
+ """Get the current value for a metric."""
+ metrics = get_metrics()[0]
+ name = clean_name(name)
+ try:
+ val = metrics['data'][name]
+ except StandardError:
+ val = 0
+ return val
+#end get_value
+
+
+def get_delta(name):
+ """Get the delta since last sample for a metric."""
+ (curr, last) = get_metrics()
+
+ name = clean_name(name)
+ try:
+ delta = curr['data'][name] - last['data'][name]
+ except StandardError:
+ delta = 0
+ return delta
+#end get_delta
+
+
+def metric_init(params):
+ """Initialize module at gmond startup."""
+
+ global CONF
+
+ for k,v in params.iteritems():
+ CONF[key] = v
+
+ skel = {
+ 'name': 'XXX',
+ 'call_back': 'XXX',
+ 'time_max': 60,
+ 'value_type': 'uint',
+ 'units': 'XXX',
+ 'slope': 'both',
+ 'format': '%d',
+ 'description': 'XXX',
+ 'groups': CONF['groups'],
+ }
+
+ descriptors = []
+ descriptors.append(build_desc(skel, {
+ 'name': CONF['prefix'] + 'start',
+ 'call_back': get_value,
+ 'units': 'epoch',
+ 'description': 'Time service started',
+ }))
+ descriptors.append(build_desc(skel, {
+ 'name': CONF['prefix'] + 'uptime',
+ 'call_back': get_value,
+ 'units': 's',
+ 'description': 'Service uptime',
+ }))
+ descriptors.append(build_desc(skel, {
+ 'name': CONF['prefix'] + 'inpkts_recvd',
+ 'call_back': get_value,
+ 'units': 'pkts',
+ 'description': 'Multicast packets since startup',
+ }))
+ descriptors.append(build_desc(skel, {
+ 'name': CONF['prefix'] + 'inpkts_sane',
+ 'call_back': get_value,
+ 'units': 'pkts',
+ 'description': 'Sane packets since startup',
+ }))
+ descriptors.append(build_desc(skel, {
+ 'name': CONF['prefix'] + 'inpkts_enqueued',
+ 'call_back': get_value,
+ 'units': 'pkts',
+ 'description': 'Pakets enqueued since startup',
+ }))
+ descriptors.append(build_desc(skel, {
+ 'name': CONF['prefix'] + 'inpkts_dequeued',
+ 'call_back': get_value,
+ 'units': 'pkts',
+ 'description': 'Packets dequeued since startup',
+ }))
+ descriptors.append(build_desc(skel, {
+ 'name': CONF['prefix'] + 'queue_overflows',
+ 'call_back': get_value,
+ 'units': 'count',
+ 'description': 'Number of queue overflows since startup',
+ }))
+ return descriptors
+#end metric_init
+
+
+def metric_cleanup():
+ """Clean up on gmond shutdown."""
+ pass
+#end metric_cleanup
+
+
+if __name__ == '__main__':
+ descriptors = metric_init({})
+ for d in descriptors:
+ v = d['call_back'](d['name'])
+ print 'value for %s is %u' % (d['name'], v)
diff --git a/modules/varnish/manifests/monitoring/ganglia/vhtcpd.pp
b/modules/varnish/manifests/monitoring/ganglia/vhtcpd.pp
new file mode 100644
index 0000000..cff8944
--- /dev/null
+++ b/modules/varnish/manifests/monitoring/ganglia/vhtcpd.pp
@@ -0,0 +1,13 @@
+class varnish::monitoring::ganglia::vhtcpd() {
+ file { "/usr/lib/ganglia/python_modules/vhtcpd.py":
+ require => File["/usr/lib/ganglia/python_modules"],
+ source => "puppet:///modules/${module_name}/ganglia/ganglia-vhtcpd.py";
+
+ "/etc/ganglia/conf.d/vhtcpd.pyconf":
+ owner => root,
+ group => root,
+ mode => 0444,
+ content => template("${module_name}/ganglia/vhtcpd.pyconf.erb"),
+ notify => Service[gmond];
+ }
+}
diff --git a/modules/varnish/templates/ganglia/vhtcpd.pyconf.erb
b/modules/varnish/templates/ganglia/vhtcpd.pyconf.erb
new file mode 100644
index 0000000..5258084
--- /dev/null
+++ b/modules/varnish/templates/ganglia/vhtcpd.pyconf.erb
@@ -0,0 +1,42 @@
+# Vhtcpd plugin for Ganglia Monitor
+
+modules {
+ module {
+ name = "vhtcpd"
+ language = "python"
+ }
+}
+
+collection_group {
+ collect_every = 30
+ time_threshold = 120
+
+ metric {
+ name = "vhtcpd_start"
+ title = "Time service started (epoch)"
+ }
+ metric {
+ name = "vhtcpd_uptime"
+ title = "Service uptime (s)"
+ }
+ metric {
+ name = "vhtcpd_inpkts_recvd"
+ title = "Multicast packets since startup (pkts)"
+ }
+ metric {
+ name = "vhtcpd_inpkts_sane"
+ title = "Sane packets since startup (pkts)"
+ }
+ metric {
+ name = "vhtcpd_inpkts_enqueued"
+ title = "Pakets enqueued since startup (pkts)"
+ }
+ metric {
+ name = "vhtcpd_inpkts_dequeued"
+ title = "Packets dequeued since startup (pkts)"
+ }
+ metric {
+ name = "vhtcpd_queue_overflows"
+ title = "Number of queue overflows since startup (count)"
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/77975
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f581a94dae5e16353060d3b49f5fe411854e77a
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: BryanDavis <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits