Rush has uploaded a new change for review.

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

Change subject: send user and channel count to statsd for ircd
......................................................................

send user and channel count to statsd for ircd

looks like:

    servers.argon.ircd_users.users 5 1400868275
    servers.argon.ircd_users.channels 271 1400868275

Change-Id: I8352e4804d225a8bcb03a6ab28b82c935a3c4d67
---
A modules/mw-rc-irc/files/monitor/ircd_stats.py
M modules/mw-rc-irc/manifests/ircserver.pp
2 files changed, 69 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/74/135074/1

diff --git a/modules/mw-rc-irc/files/monitor/ircd_stats.py 
b/modules/mw-rc-irc/files/monitor/ircd_stats.py
new file mode 100644
index 0000000..9c7e246
--- /dev/null
+++ b/modules/mw-rc-irc/files/monitor/ircd_stats.py
@@ -0,0 +1,61 @@
+import diamond.collector
+import socket
+import sys
+import re
+
+"""
+
+Collects the number of connected users and created channels from IRCD
+
+Tested with Python 2.7, IRCD 2.9 (MW patch)
+
+"""
+
+
+class IRCDStatsCollector(diamond.collector.Collector):
+
+    def get_default_config(self):
+        """
+        Returns the default collector settings
+        """
+        config = super(IRCDStatsCollector, self).get_default_config()
+        config.update({
+            'path':     'ircd_users',
+            'server':   'localhost',
+            'user':     'ircd_users_bot',
+            'port':     6667,
+        })
+        return config
+
+    def recv_until(self, the_socket, end):
+        total_data = []
+        while True:
+            data = the_socket.recv(8192)
+            total_data.append(data)
+            if end in data:
+                break
+        return ''.join(total_data).rstrip('\0')
+
+    def collect(self):
+        irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        try:
+            irc.connect((self.config['server'], int(self.config['port'])))
+            #making ircd happy with # of args
+            irc.send("USER %s %s %s :%s\n" % (self.config['user'],
+                                          self.config['user'],
+                                          self.config['user'],
+                                          self.config['user']))
+
+            irc.send("NICK %s\n" % (self.config['user'],))
+            termout = self.recv_until(irc, 'End of /MOTD command')
+            users = re.search("There\sare\s(\d+)\susers", termout)
+            chans = re.search("(\d+)\s:channels\sformed", termout)
+            if users and chans:
+                self.publish('users', users.groups()[0].strip())
+                self.publish('channels', chans.groups()[0].strip())
+
+        finally:
+            try:
+                irc.close()
+            except:
+                pass
diff --git a/modules/mw-rc-irc/manifests/ircserver.pp 
b/modules/mw-rc-irc/manifests/ircserver.pp
index 17cee75..a92ef42 100644
--- a/modules/mw-rc-irc/manifests/ircserver.pp
+++ b/modules/mw-rc-irc/manifests/ircserver.pp
@@ -24,6 +24,14 @@
         binary   => '/usr/bin/ircd';
     }
 
+    diamond::collector { 'IRCDStats':
+        source => 'puppet:///modules/mw-rc-irc/ircd_stats.py'
+        settings => {
+            enable => 'true',
+            method => 'Threaded',
+         },
+    }
+
     monitor_service { 'ircd':
         description   => 'ircd',
         check_command => 'check_ircd',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8352e4804d225a8bcb03a6ab28b82c935a3c4d67
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Rush <r...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to