lib/riemann/tools.rb in riemann-tools-0.1.6 vs lib/riemann/tools.rb in riemann-tools-0.1.7
- old
+ new
@@ -33,10 +33,11 @@
opt :interval, "Seconds between updates", :default => 5
opt :tag, "Tag to add to events", :type => String, :multi => true
opt :ttl, "TTL for events", :type => Integer
opt :attribute, "Attribute to add to the event", :type => String, :multi => true
opt :timeout, "Timeout (in seconds) when waiting for acknowledgements", :default => 30
+ opt :tcp, "Use TCP transport instead of UDP (improves reliability, slight overhead.", :default => true
end
end
# Returns parsed options (cached) from command line.
def options
@@ -57,13 +58,11 @@
if options[:tag]
# Work around a bug with beefcake which can't take frozen strings.
event[:tags] = options[:tag].map(&:dup)
end
- if options[:ttl]
- event[:ttl] = options[:ttl]
- end
+ event[:ttl] ||= (options[:ttl] || (options[:interval] * 2))
if options[:event_host]
event[:host] = options[:event_host].dup
end
@@ -76,14 +75,23 @@
rescue Timeout::Error
riemann.connect
end
end
- def riemann
- @riemann ||= Riemann::Client.new(
+ def new_riemann_client
+ r = Riemann::Client.new(
:host => options[:host],
:port => options[:port]
)
+ if options[:tcp]
+ r.tcp
+ else
+ r
+ end
+ end
+
+ def riemann
+ @riemann ||= new_riemann_client
end
alias :r :riemann
def run
t0 = Time.now