summaryrefslogtreecommitdiff
path: root/lib/custodian/alerts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/custodian/alerts')
-rw-r--r--lib/custodian/alerts/graphite.rb24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/custodian/alerts/graphite.rb b/lib/custodian/alerts/graphite.rb
index 0244047..cca5ece 100644
--- a/lib/custodian/alerts/graphite.rb
+++ b/lib/custodian/alerts/graphite.rb
@@ -1,4 +1,5 @@
require 'socket'
+require 'timeout'
#
# The graphite-alerter.
@@ -61,12 +62,25 @@ module Custodian
payload = "custodian.#{test}.#{host}.test_duration_ms #{ms} #{Time.now.to_i}"
#
- # Send via UDP.
+ # Send metrics via TCP.
#
- socket = UDPSocket.new
- socket.send(payload, 0, @target, 2003)
- socket.close
-
+ begin
+ Timeout.timeout(10) do
+ begin
+ socket = TCPSocket.new(@target,2003)
+ puts payload
+ socket.write(payload)
+ socket.flush
+ socket.close
+ rescue Errno::ENETUNREACH
+ puts("Metrics host unreachable: #{e}")
+ rescue StandardError => e
+ puts("Error submitting metrics: #{e}")
+ end
+ end
+ rescue Timeout::Error
+ puts('Timeout submitting metrics')
+ end
end
register_alert_type 'graphite'