Last active
December 21, 2015 10:38
-
-
Save stefan-lz/6292841 to your computer and use it in GitHub Desktop.
Play a notifying sound every time a librato count metric is logged. Inspired by https://choir.io/
This file contains 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 'librato/metrics' | |
POLL_TIME = 5 | |
METRIC_NAME = 'production.rates-service' | |
def play_sound | |
`mpg123 cashreg1.wav` | |
end | |
def get_metric metric_name | |
Librato::Metrics.fetch(metric_name, count: 1, resolution: 1)["unassigned"].first["value"] | |
end | |
Librato::Metrics.authenticate('email', 'token') | |
count = get_metric(METRIC_NAME) | |
while true | |
puts count | |
delta = get_metric(METRIC_NAME) - count | |
delta.times{ Thread.new { play_sound } ; sleep(POLL_TIME.to_f/delta) } | |
count += delta | |
sleep POLL_TIME | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment