discourse/lib/stats_socket.rb

32 lines
561 B
Ruby
Raw Normal View History

require 'socket_server'
class StatsSocket < SocketServer
def initialize(socket_path)
super(socket_path)
end
protected
def get_response(command)
result =
case command
when "gc_stat"
GC.stat.to_json
when "v8_stat"
2017-07-20 13:23:48 -04:00
stats = {}
ObjectSpace.each_object(MiniRacer::Context) do |context|
2017-07-27 21:20:09 -04:00
context.heap_stats.each do |k, v|
2017-07-20 13:23:48 -04:00
stats[k] = (stats[k] || 0) + v
end
end
stats.to_json
else
"[\"UNKNOWN COMMAND\"]"
end
result << "\n"
end
end