Faidon Liambotis has submitted this change and it was merged. Change subject: statsd-ganglia: node 0.10+ compat; add custom filters feature ......................................................................
statsd-ganglia: node 0.10+ compat; add custom filters feature - 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. - Ensure compatibility with async sock.bind() in node 0.10+ Per <http://nodejs.org/api/dgram.html#dgram_event_listening>: "the behavior of dgram.Socket#bind() has changed in v0.10 and is always asynchronous now." This means that setting the broadcast flag has to be deferred to a callback to ensure it does not execute before the socket is bound. Setting the flag in a 'listening' event handler is compatible with both old and new versions of node. Change-Id: I978c86f4686f37facc44ca6f1af4b697ea9b83a2 --- M modules/statsd/files/backends/ganglia.js 1 file changed, 31 insertions(+), 4 deletions(-) Approvals: Faidon Liambotis: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/statsd/files/backends/ganglia.js b/modules/statsd/files/backends/ganglia.js index f8d7408..8bff84e 100644 --- a/modules/statsd/files/backends/ganglia.js +++ b/modules/statsd/files/backends/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,11 +294,17 @@ 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 ); + socket.setMulticastTTL( 128 ); + socket.addMembership( backendConfig.gangliaHost ); + } ); socket.bind(); - socket.setBroadcast( true ); - socket.setMulticastTTL( 128 ); - socket.addMembership( backendConfig.gangliaHost ); } templates.base.group = backendConfig.gangliaGroup; -- To view, visit https://gerrit.wikimedia.org/r/83132 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I978c86f4686f37facc44ca6f1af4b697ea9b83a2 Gerrit-PatchSet: 1 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Ori.livneh <[email protected]> Gerrit-Reviewer: Faidon Liambotis <[email protected]> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
