Skip to content

Instantly share code, notes, and snippets.

@foxiepaws
Last active October 13, 2016 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxiepaws/33abc1a655713471861b090d7c6cde1c to your computer and use it in GitHub Desktop.
Save foxiepaws/33abc1a655713471861b090d7c6cde1c to your computer and use it in GitHub Desktop.
require 'net/telnet'
# ilo_powermeter.rb by Allison Rachel Fox
# I release this file into the public domain
# or CC0 in areas where there isn't one.
#
# Really dirt simple tool to fetch
# power consumption information from
# iLO. Logs in over telnet as SSH is
# broken on iLO 2 due to a bug.
hostname = ""
username = ""
password = ""
time_period = 5
csv = File.new("server_power.csv", "a")
ilo = Net::Telnet::new("Host" => hostname,
"Timeout" => 10,
"Prompt" => /<\/(\w+\/?)+>hpiLO-> \z/n )
ilo.write("#{username}\r\n");
sleep 1
ilo.write("#{password}\r\n");
while 1 do
time = Time.new().to_i
begin
ilo.cmd("show system1") { |c|
c.lines.select {|v| v =~ /oemhp_\w+Power/ }.each { |c|
def getwatts(c)
/=(\d+) Watts/.match(c)[1].to_i
end
case c
when /Average/
@average = getwatts(c)
when /Max/
@max = getwatts(c)
when /Min/
@min = getwatts(c)
when /Present/
@present = getwatts(c)
end
}
}
rescue
end
puts "Power Consumption:"
puts "\tPresent: #{@present} Watts"
puts "\tAverage: #{@average} Watts"
puts "\tMin: #{@min} Watts"
puts "\tMax: #{@max} Watts"
csv.puts "#{time},#{@present},#{@average},#{@min},#{@max}"
csv.flush
sleep time_period * 60
end
ilo.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment