Skip to content

Instantly share code, notes, and snippets.

@auxesis
Created June 27, 2012 23:07
Show Gist options
  • Select an option

  • Save auxesis/3007483 to your computer and use it in GitHub Desktop.

Select an option

Save auxesis/3007483 to your computer and use it in GitHub Desktop.
$ watch -n1 ruby notus.rb
Every 1.0s: ruby notus.rb Thu Jun 28 09:08:11 2012
[1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0]
8
30667
Sending individual alerts
#!/usr/bin/env ruby
require 'rubygems'
require 'redis'
require 'chronic'
@redis = Redis.new(:host => "localhost", :port => 6379)
@redis.hincrby("events", Time.now.to_i, rand(2)) # generate some dummy events
def frequency_of_events_since(time)
range = (Chronic.parse(time).to_i .. Time.now.to_i)
window = range.to_a
@redis.hmget("events", *window).map {|i| i.to_i}
end
frequency = frequency_of_events_since("30 seconds ago")
threshold = 10
p frequency
p sum = frequency.inject(:+)
p @redis.hgetall("events").size
if sum >= threshold then
puts "Merging alerts"
else
puts "Sending individual alerts"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment