Ottomata has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/56623


Change subject: Adding class misc::monitoring::net::udp for generic udp 
statistics monitoring.
......................................................................

Adding class misc::monitoring::net::udp for generic udp statistics monitoring.

Including this class on udp2log hosts

Change-Id: I8d12d445d176b9231816e81d1abaa212c3987187
---
A files/ganglia/plugins/udp_stats.py
A files/ganglia/plugins/udp_stats.pyconf
M manifests/misc/monitoring.pp
M manifests/misc/udp2log.pp
4 files changed, 155 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/23/56623/1

diff --git a/files/ganglia/plugins/udp_stats.py 
b/files/ganglia/plugins/udp_stats.py
new file mode 100644
index 0000000..32dee1c
--- /dev/null
+++ b/files/ganglia/plugins/udp_stats.py
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+    Python Gmond Module for UDP Statistics
+    Original: https://github.com/atdt/python-udp-gmond
+
+    :copyright: (c) 2012 Wikimedia Foundation
+    :author: Ori Livneh <[email protected]>
+    :license: GPL
+    
+"""
+from __future__ import print_function
+
+import logging
+from ast import literal_eval
+from threading import Timer
+
+
+UPDATE_INTERVAL = 5  # seconds
+
+defaults = {
+    "slope"      : "both",
+    "time_max"   : 60,
+    "format"     : "%u",
+    "value_type" : "uint",
+    "groups"     : "network,udp",
+    "units"      : "packets"
+}
+
+udp_fields = {
+    "InDatagrams"  : "UDP Packets Received",
+    "NoPorts"      : "UDP Packets to Unknown Port Received",
+    "InErrors"     : "UDP Packet Receive Errors",
+    "OutDatagrams" : "UDP Packets Sent",
+    "RcvbufErrors" : "UDP Receive Buffer Errors",
+    "SndbufErrors" : "UDP Send Buffer Errors"
+}
+
+netstats = {}
+
+
+def get_netstats():
+    """Parse /proc/net/snmp"""
+    with open('/proc/net/snmp', 'rt') as snmp:
+        raw = {}
+        for line in snmp:
+            key, vals = line.split(':', 1)
+            key = key.lower()
+            vals = vals.strip().split()
+            raw.setdefault(key, []).append(vals)
+    return dict((k, dict(zip(*vs))) for (k, vs) in raw.items())
+
+
+def update_stats():
+    """Update netstats and schedule the next run"""
+    netstats.update(get_netstats())
+    logging.info("Updated: %s", netstats['udp'])
+    Timer(UPDATE_INTERVAL, update_stats).start()
+
+
+def metric_handler(name):
+    """Get value of particular metric; part of Gmond interface"""
+    logging.debug('metric_handler(): %s', name)
+    return literal_eval(netstats['udp'][name])
+
+
+def metric_init(params):
+    """Initialize; part of Gmond interface"""
+    descriptors = []
+    defaults['call_back'] = metric_handler
+    for name, description in udp_fields.items():
+        descriptor = dict(name=name, description=description)
+        descriptor.update(defaults)
+        descriptors.append(descriptor)
+    update_stats()
+    return descriptors
+
+
+def metric_cleanup():
+    """Teardown; part of Gmond interface"""
+    pass
+
+
+if __name__ == '__main__':
+    # When invoked as standalone script, run a self-test by querying each
+    # metric descriptor and printing it out.
+    logging.basicConfig(level=logging.DEBUG)
+    for metric in metric_init({}):
+        value = metric['call_back'](metric['name'])
+        print(( "%s => " + metric['format'] ) % ( metric['name'], value ))
diff --git a/files/ganglia/plugins/udp_stats.pyconf 
b/files/ganglia/plugins/udp_stats.pyconf
new file mode 100644
index 0000000..776ce46
--- /dev/null
+++ b/files/ganglia/plugins/udp_stats.pyconf
@@ -0,0 +1,47 @@
+# Gmond configuration for UDP metric module
+# Install to /etc/ganglia/conf.d
+#
+# Original: https://github.com/atdt/python-udp-gmond
+
+modules {
+  module {
+    name = "udp_stats"
+    language = "python"
+  }
+}
+
+collection_group {
+  collect_every = 10
+  time_threshold = 60
+  
+  metric {
+    name = "InDatagrams"
+    title = "UDP Packets Received"
+    value_threshold = 0
+  }
+  metric {
+    name = "NoPorts"
+    title = "UDP Packets to Unknown Port Received"
+    value_threshold = 0
+  }
+  metric {
+    name = "InErrors"
+    title = "UDP Packet Receive Errors"
+    value_threshold = 0
+  }
+  metric {
+    name = "OutDatagrams"
+    title = "UDP Packets Sent"
+    value_threshold = 0
+  }
+  metric {
+    name = "RcvbufErrors"
+    title = "UDP Receive Buffer Errors"
+    value_threshold = 0
+  }
+  metric {
+    name = "SndbufErrors"
+    title = "UDP Send Buffer Errors"
+    value_threshold = 0
+  }
+}
diff --git a/manifests/misc/monitoring.pp b/manifests/misc/monitoring.pp
index 311f27a..d1ccbc8 100644
--- a/manifests/misc/monitoring.pp
+++ b/manifests/misc/monitoring.pp
@@ -26,3 +26,18 @@
                        #source => 
"puppet:///files/ganglia/plugins/htcpseqcheck.pyconf";
        }
 }
+
+# == Class misc::monitoring::net::udp
+# Sends UDP statistics to ganglia.
+class misc::monitoring::net::udp {
+       file {
+               '/usr/lib/ganglia/python_modules/udp_stats.py':
+                       require => File['/usr/lib/ganglia/python_modules'],
+                       source => 
'puppet:///files/ganglia/plugins/udp_stats.py',
+                       notify => Service[gmond];
+               '/etc/ganglia/conf.d/udp_stats.pyconf':
+                       require => 
File["/usr/lib/ganglia/python_modules/udp_stats.py"],
+                       source => 
"puppet:///files/ganglia/plugins/udp_stats.pyconf",
+                       notify => Service[gmond];
+       }
+}
\ No newline at end of file
diff --git a/manifests/misc/udp2log.pp b/manifests/misc/udp2log.pp
index 8b46c65..f38f98d 100644
--- a/manifests/misc/udp2log.pp
+++ b/manifests/misc/udp2log.pp
@@ -330,6 +330,9 @@
                        source => 
"puppet:///files/ganglia/plugins/udp2log_socket.pyconf",
                        notify => Service[gmond];
        }
+
+       # include general UDP statistic monitoring.
+       include misc::monitoring::net::udp
 }
 
 class misc::udp2log::iptables_purges {

-- 
To view, visit https://gerrit.wikimedia.org/r/56623
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8d12d445d176b9231816e81d1abaa212c3987187
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ottomata <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to