Skip to content

Instantly share code, notes, and snippets.

@macbury
Created June 20, 2014 16:08
Show Gist options
  • Save macbury/fb5f32fa7478c5aa6879 to your computer and use it in GitHub Desktop.
Save macbury/fb5f32fa7478c5aa6879 to your computer and use it in GitHub Desktop.
Server code for stupid guage
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