Skip to content

Instantly share code, notes, and snippets.

@christianmeichtry
Created August 2, 2009 07:00
Show Gist options
  • Save christianmeichtry/159974 to your computer and use it in GitHub Desktop.
Save christianmeichtry/159974 to your computer and use it in GitHub Desktop.
Simple script to report temp and memory to pachube
require 'rubygems'
require 'logger'
gem 'builder'
require 'net/http'
gem 'Floppy-eeml'
require 'eeml'
logger = Logger.new("#{File.dirname(__FILE__)}/pachube.log")
PACHUBE_KEY = #YOUR KEY HERE
digits = /\d+/
while true
begin
val = %x"/Applications/TemperatureMonitor.app/Contents/MacOS/tempmonitor".split[0] #install TemperatureMonitor for this to work.
mem = digits.match(%x"top -l 1 | awk '/PhysMem/ {print $10}'")[0]
$environment = EEML::Environment.new
$environment.description = "A ruby script reports some stats from my MacBook"
$environment.creator = "Christian Meichtry"
location = EEML::Location.new(:virtual)
location.lat = 46.326068311712596
location.lon = 7.787933349609375
$environment.location = location
data = EEML::Data.new(val)
data.unit = EEML::Unit.new('°C')
$environment << data
data = EEML::Data.new(mem)
data.unit = EEML::Unit.new('Mb')
$environment << data
http = Net::HTTP.new('www.pachube.com', 80)
http.start do |http|
req = Net::HTTP::Put.new('/api/2202.xml', {'X-PachubeApiKey' => PACHUBE_KEY})
req.body = $environment.to_eeml
resp = http.request(req)
end
logger.info "OK #{val}°C - #{mem}Mb"
rescue
# Probably not much we can do, lets hope that the next one works
logger.error $!
end
sleep(60)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment