Skip to content

Instantly share code, notes, and snippets.

@stefan-lz
Last active December 21, 2015 10:38
Show Gist options
  • Save stefan-lz/6292841 to your computer and use it in GitHub Desktop.
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/
#!/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