mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:49:14 +08:00
32 lines
561 B
Ruby
32 lines
561 B
Ruby
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"
|
|
stats = {}
|
|
ObjectSpace.each_object(MiniRacer::Context) do |context|
|
|
context.heap_stats.each do |k, v|
|
|
stats[k] = (stats[k] || 0) + v
|
|
end
|
|
end
|
|
stats.to_json
|
|
else
|
|
"[\"UNKNOWN COMMAND\"]"
|
|
end
|
|
|
|
result << "\n"
|
|
end
|
|
|
|
end
|