DEV: Remove `StatsSocket`.

Removed in favor of https://github.com/discourse/discourse-prometheus.
This commit is contained in:
Guo Xiang Tan 2019-03-26 18:16:58 +08:00
parent e0cb2a434a
commit 4774633dac
3 changed files with 0 additions and 129 deletions

View File

@ -47,28 +47,6 @@ preload_app true
# fast LAN.
check_client_connection false
@stats_socket_dir = ENV["UNICORN_STATS_SOCKET_DIR"]
def clean_up_stats_socket(server, pid)
if @stats_socket_dir.present?
name = "#{@stats_socket_dir}/#{pid}.sock"
FileUtils.rm_f(name)
server.logger.info "Cleaned up stats socket at #{name}"
end
rescue => e
server.logger.warn "Failed to clean up stats socket #{e}"
end
def start_stats_socket(server)
if @stats_socket_dir.present?
name = "#{@stats_socket_dir}/#{Process.pid}.sock"
StatsSocket.new(name).start
server.logger.info "Started stats socket at #{name}"
end
rescue => e
server.logger.warn "Failed to start stats socket #{e}"
end
initialized = false
before_fork do |server, worker|
@ -84,18 +62,6 @@ before_fork do |server, worker|
# router warm up
Rails.application.routes.recognize_path('abc') rescue nil
if @stats_socket_dir.present?
server.logger.info "Initializing stats socket at #{@stats_socket_dir}"
begin
require 'stats_socket'
FileUtils.mkdir_p @stats_socket_dir
FileUtils.rm_f Dir.glob("#{@stats_socket_dir}/*.sock")
start_stats_socket(server)
rescue => e
server.logger.info "Failed to initialize stats socket dir #{e}"
end
end
# preload discourse version
Discourse.git_version
Discourse.git_branch
@ -125,7 +91,6 @@ before_fork do |server, worker|
require 'demon/sidekiq'
Demon::Sidekiq.after_fork do
start_stats_socket(server) if @stats_socket_dir
DiscourseEvent.trigger(:sidekiq_fork_started)
end
@ -220,13 +185,7 @@ before_fork do |server, worker|
sleep 1
end
after_worker_exit do |server, worker, status|
clean_up_stats_socket(server, status.pid)
end
after_fork do |server, worker|
start_stats_socket(server)
DiscourseEvent.trigger(:web_fork_started)
# warm up v8 after fork, that way we do not fork a v8 context

View File

@ -1,31 +0,0 @@
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

View File

@ -1,57 +0,0 @@
require 'rails_helper'
require_dependency 'stats_socket'
describe StatsSocket do
let :socket_path do
"#{Dir.tmpdir}/#{SecureRandom.hex}"
end
let :stats_socket do
StatsSocket.new(socket_path)
end
before do
stats_socket.start
end
after do
stats_socket.stop
end
it "can respond to various stats commands" do
line = nil
# ensure this works more than once :)
2.times do
socket = UNIXSocket.new(socket_path)
socket.send "gc_stat\n", 0
line = socket.readline
socket.close
end
socket = UNIXSocket.new(socket_path)
socket.send "gc_st", 0
socket.flush
sleep 0.001
socket.send "at\n", 0
line = socket.readline
socket.close
parsed = JSON.parse(line)
expect(parsed.keys.sort).to eq(GC.stat.keys.map(&:to_s).sort)
# make sure we have libv8 going
PrettyText.cook("x")
socket = UNIXSocket.new(socket_path)
socket.send "v8_stat\n", 0
line = socket.readline
socket.close
parsed = JSON.parse(line)
expect(parsed['total_physical_size']).to be > (0)
end
end