Advertisement
Guest User

Untitled

a guest
Oct 13th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. require 'net/telnet'
  2.  
  3. # ilo_powermeter.rb by Allison Rachel Fox
  4. # I release this file into the public domain
  5. # or CC0 in areas where there isn't one.
  6. #
  7. # Really dirt simple tool to fetch
  8. # power consumption information from
  9. # iLO. Logs in over telnet as SSH is
  10. # broken on iLO 2 due to a bug.
  11.  
  12. hostname = ""
  13. username = ""
  14. password = ""
  15. time_period = 5
  16.  
  17.  
  18. csv = File.new("server_power.csv", "a")
  19. ilo = Net::Telnet::new("Host" => hostname,
  20. "Timeout" => 10,
  21. "Prompt" => /<\/(\w+\/?)+>hpiLO-> \z/n )
  22. ilo.write("#{username}\r\n");
  23. sleep 1
  24. ilo.write("#{password}\r\n");
  25. while 1 do
  26. time = Time.new().to_i
  27. begin
  28. ilo.cmd("show system1") { |c|
  29. c.lines.select {|v| v =~ /oemhp_\w+Power/ }.each { |c|
  30. def getwatts(c)
  31. /=(\d+) Watts/.match(c)[1].to_i
  32. end
  33. case c
  34. when /Average/
  35. @average = getwatts(c)
  36. when /Max/
  37. @max = getwatts(c)
  38. when /Min/
  39. @min = getwatts(c)
  40. when /Present/
  41. @present = getwatts(c)
  42. end
  43. }
  44. }
  45. rescue
  46. end
  47. puts "Power Consumption:"
  48. puts "\tPresent: #{@present} Watts"
  49. puts "\tAverage: #{@average} Watts"
  50. puts "\tMin: #{@min} Watts"
  51. puts "\tMax: #{@max} Watts"
  52. csv.puts "#{time},#{@present},#{@average},#{@min},#{@max}"
  53. csv.flush
  54. sleep time_period * 60
  55. end
  56. ilo.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement