Created
June 27, 2012 23:07
-
-
Save auxesis/3007483 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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