Created
March 29, 2013 21:11
-
-
Save skymob/5273674 to your computer and use it in GitHub Desktop.
Increment a statsd counter for each metric received (not yet working!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Increment a counter in Statsd | |
# == | |
# | |
# Copyright 2013 Bethany Erskine bethany@paperlesspost.com | |
# | |
require 'rubygems' if RUBY_VERSION < '1.9.0' | |
require 'statsd' | |
module Sensu | |
module Extension | |
class StastdIncrementCounter < Handler | |
def name | |
'statsd_increment_counter' | |
end | |
def description | |
'sends event output to statsd' | |
end | |
def definition | |
{ | |
:type => 'handler', | |
:name => name | |
} | |
end | |
def run(event, settings, &block) | |
opts = settings['statsd'] | |
opts['statsd_host'] ||= "localhost" | |
opts['statsd_port'] ||= 8125 | |
metric_count = event['check']['output'].split("\n").count | |
# need to pull these from a snippet or dynamically set them | |
namespace = "sensu" | |
key = "metric_count" | |
statsd = Statsd.new(opts['statsd_host'], opts['statsd_port']).tap{ | |
|sd| sd.namespace = namespace } | |
statsd.increment key,metric_count | |
block.call("incremented counter #{namespace}.#{key} #{metric_count} times", 0) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment