Last active
October 13, 2016 06:59
-
-
Save foxiepaws/33abc1a655713471861b090d7c6cde1c to your computer and use it in GitHub Desktop.
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
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