Ori.livneh has uploaded a new change for review.

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


Change subject: Allow user to specify custom metric filters / preprocessors
......................................................................

Allow user to specify custom metric filters / preprocessors

Not all metrics that are appropriate for Graphite are also appropriate for
Ganglia. This patch adds an optional configuration option, "gangliaFilters",
that the user may set to an array of module paths. Each referenced module is
expected to export a "filter" function which takes a metric and either modifies
it in some way, returns it unmodified, or returns a false value to exclude it
from Ganglia reporting.

Change-Id: Ieca6e923b14278b243bd1ca80611f2cea7f751b3
---
M ganglia.js
1 file changed, 26 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/analytics/statsd-ganglia 
refs/changes/31/83131/1

diff --git a/ganglia.js b/ganglia.js
index c8c63af..8bff84e 100644
--- a/ganglia.js
+++ b/ganglia.js
@@ -30,7 +30,21 @@
  *   "gangliaMulticast": false,   // Use multicast?
  *   "gangliaSpoofHost": "slave", // Associate metrics w/this hostname
  *   "gangliaGroup": "statsd",    // Default metric group name
+ *   "gangliaFilters": [],        // Array of module paths (see below)
  * }
+ *
+ * Metric filters
+ *
+ * If you want to choose which metrics get sent to Ganglia, you may set
+ * the "gangliaFilters" configuration to an array of module paths.
+ * Each module should export a "filter" function which takes a metric
+ * object. The function may modify the metric object or return false to
+ * exclude it from Ganglia reporting. For example:
+ *
+ *   exports.filter = function ( metric ) {
+ *     // Exclude counters from Ganglia reporting.
+ *     return /count/.test( metric.name ) ? false : metric;
+ *   };
  *
  */
 
@@ -141,6 +155,10 @@
     }
 }
 
+function filterReduce( o, filter ) {
+    return filter.filter( o );
+}
+
 var os = require( 'os' );
 var util = require( 'util' );
 var dgram = require( 'dgram' );
@@ -183,6 +201,8 @@
     },
 };
 
+var filters = [];
+
 var socket = dgram.createSocket( 'udp4' );
 
 var ganglia = {
@@ -206,7 +226,8 @@
         if ( typeof opts.slope === 'string' ) {
             opts.slope = slopes.indexOf( opts.slope );
         }
-        ganglia.items.push( opts );
+        opts = filters.reduce( filterReduce, opts );
+        if ( typeof opts === 'object' ) ganglia.items.push( opts );
     },
     flush   : function ( timestamp, metrics ) {
         var delta = timestamp - ganglia.flushed;
@@ -273,6 +294,10 @@
         backendConfig.percentThreshold = [ backendConfig.percentThreshold ];
     }
 
+    if ( backendConfig.gangliaFilters ) {
+        filters.push.apply( filters, backendConfig.gangliaFilters.map( require 
) );
+    }
+
     if ( backendConfig.gangliaMulticast ) {
         socket.on( 'listening', function () {
             socket.setBroadcast( true );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieca6e923b14278b243bd1ca80611f2cea7f751b3
Gerrit-PatchSet: 1
Gerrit-Project: analytics/statsd-ganglia
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

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

Reply via email to