Skip to content

Instantly share code, notes, and snippets.

@trueheart78 trueheart78/fs-monitor.rb
Last active Aug 29, 2015

Embed
What would you like to do?
A simple ruby script to monitor filesizes during a large transfer. Setup to run through cron. Requires the mandrill-api gem to be installed, as well as a mandrill API key in your enviroment in MANDRILL_APIKEY
require 'mandrill'
files = ["mh-files-wo-lb-20141026_0009.tar.gz","mh-files-lb-only-20141026_0009.tar.gz"]
files.each do |f|
if File.exist?(f)
size = File.stat(f).size
gb = 1024 ** 3
mb = 1024 ** 2
status = "#{size / gb} gb (#{size / mb} mb)"
puts "File #{f} - as of #{Time.now}:\n"
puts "#{status}\n"
m = Mandrill::API.new
message = {
:subject=> "Status: #{status} [#{f}]",
:from_name=> "Your Friendly Neighborhood Server",
:text=>"See?",
:to=>[
{
:email=> "bill@example.com",
:name=> "Billy"
}
],
:html=>"#{status} for #{f}",
:from_email=>"bobby@example.com"
}
sending = m.messages.send message
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.