From c6b20011447f913c918d9291dbd7d0da4a32e09e Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Tue, 8 Oct 2013 09:55:26 +0100 Subject: Updated to send via UDP, without system. --- lib/custodian/alerts/graphite.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/custodian/alerts/graphite.rb b/lib/custodian/alerts/graphite.rb index abea54d..bc87beb 100644 --- a/lib/custodian/alerts/graphite.rb +++ b/lib/custodian/alerts/graphite.rb @@ -1,8 +1,11 @@ +require 'socket' + # # The graphite-alerter. # -# This only exists to record timing durations in the local graphite/carbon -# instance. +# This only exists to record timing durations in the local +# graphite/carbon instance. Updates are sent via UDP +# to localhost:2003. # module Custodian @@ -50,16 +53,22 @@ module Custodian # hostname + test-type # host = @test.target + host.gsub!(/[\/\\.]/, "_") test = @test.get_type # - # The key we'll send + # The payload + # + str = "#{test}.#{host}" + payload = "monitor.#{str} #{ms} #{Time.now.to_i}" + + # + # Send via UDP. # - str = "#{test}-#{host}" - str.gsub!(/[\/\\.]/, "-") - str = "monitor.#{str}" + socket = UDPSocket.new() + socket.send( payload, 0, "localhost", 2003 ); + socket.close() - system( "/bin/echo '#{str} #{ms} #{Time.now.to_i}' | nc localhost 2003 -q1" ) end register_alert_type "graphite" -- cgit v1.2.1