Created
December 11, 2011 13:16
-
-
Save cornet/1460561 to your computer and use it in GitHub Desktop.
Bunny + Graphite
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
#!/usr/bin/ruby | |
# | |
# Quick rewrite of producer.rb from @ripienaar's excellent article here: | |
# http://www.devco.net/archives/2011/12/11/common-messaging-patterns-using-stomp-%E2%80%93-part-2.php | |
# | |
# This assumes you have the following grapite's carbon.conf: | |
# | |
# AMQP_HOST = localhost | |
# AMQP_PORT = 5672 | |
# AMQP_VHOST = / | |
# AMQP_USER = guest | |
# AMQP_PASSWORD = guest | |
# AMQP_EXCHANGE = graphite | |
# AMQP_METRIC_NAME_IN_BODY = True | |
# | |
require 'rubygems' | |
require 'bunny' | |
raise "Please provide a metric and value on the command line" unless ARGV.size == 2 | |
raise "The metric value must be numeric" unless ARGV[1] =~ /^[\d\.]+$/ | |
msg = "%s.%s %s %d" % [Socket.gethostname, ARGV[0], ARGV[1], Time.now.utc.to_i] | |
begin | |
Timeout::timeout(2) do | |
bunny = Bunny.new() | |
bunny.start | |
exch = bunny.exchange("graphite", :type => 'topic', :durable => 'true') | |
exch.publish(msg) | |
bunny.stop | |
end | |
rescue Timeout::Error | |
STDERR.puts "Failed to send metric within the 2 second timeout" | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment