Class: Lumbersexual::Plugin::Latency
- Inherits:
-
Object
- Object
- Lumbersexual::Plugin::Latency
- Defined in:
- lib/lumbersexual/plugin/latency.rb
Instance Method Summary collapse
-
#initialize(options, *args) ⇒ Latency
constructor
A new instance of Latency.
- #perform ⇒ Object
- #report ⇒ Object
Constructor Details
#initialize(options, *args) ⇒ Latency
Returns a new instance of Latency.
15 16 17 18 |
# File 'lib/lumbersexual/plugin/latency.rb', line 15 def initialize(, *args) @options = @found = false end |
Instance Method Details
#perform ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lumbersexual/plugin/latency.rb', line 20 def perform if @options[:log] elastic = Elasticsearch::Client.new url: @options[:uri], logger: Logger.new(STDERR), log: @options[:log] else elastic = Elasticsearch::Client.new url: @options[:uri] end if @options[:all] index_name = '_all' else index_name = Time.now.strftime('logstash-%Y.%m.%d') end @uuid = SecureRandom.uuid.delete('-') @sleep_count = 0 @start_time = Time.now Timeout::timeout(@options[:timeout]) { syslog = Syslog.open('lumbersexual-ping', Syslog::LOG_CONS | Syslog::LOG_NDELAY | Syslog::LOG_PID, Syslog::LOG_INFO) syslog.log(Syslog::LOG_WARNING, @uuid) puts "Logged #{@uuid} at #{Time.now} (#{Time.now.to_i})" syslog.close until @found do result = elastic.search index: index_name, q: @uuid @found = true if result['hits']['total'] > 0 @sleep_count += 1 sleep @options[:interval] end } @end_time = Time.now puts "Found #{@uuid} at #{Time.now} (#{Time.now.to_i})" raise Interrupt end |
#report ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/lumbersexual/plugin/latency.rb', line 55 def report statsd = Statsd.new(@options[:statsdhost]).tap { |s| s.namespace = "lumbersexual.latency" } if @options[:statsdhost] if @found latency = @end_time - @start_time adjusted_latency = latency - (@options[:interval] * @sleep_count) puts "Measured Latency: #{latency}" puts "Interval Adjusted Latency: #{adjusted_latency}" statsd.gauge 'runs.failed', 0 if @options[:statsdhost] statsd.gauge 'runs.successful', 1 if @options[:statsdhost] statsd.gauge 'rtt.measured', latency if @options[:statsdhost] if @options[:statsdhost] statsd.gauge 'rtt.adjusted', adjusted_latency if @options[:statsdhost] if @options[:statsdhost] else statsd.gauge 'runs.failed', 1 if @options[:statsdhost] statsd.gauge 'runs.successful', 0 if @options[:statsdhost] puts "Latency: unknown, uuid #{@uuid} not found" end end |