Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement