Created
June 20, 2014 16:08
-
-
Save macbury/fb5f32fa7478c5aa6879 to your computer and use it in GitHub Desktop.
Server code for stupid guage
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 'socket' | |
maximum_load = 8.0 | |
puts "Starting" | |
server = TCPServer.new(3000) | |
puts "Listening" | |
loop do | |
client = server.accept | |
puts "Accepted client" | |
while true | |
sleep 1 | |
begin | |
current_load = (`cat /proc/loadavg`.split(" ")[0].to_f * 100.0).round / 100.0 | |
total_load = (current_load / maximum_load).to_s | |
puts "[#{Time.now.to_s}] Sending: " + total_load | |
client.puts total_load + "\n" | |
rescue Errno::EPIPE, Errno::ECONNRESET | |
break | |
end | |
end | |
puts "Closing connection" | |
client.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment