Skip to content

Commit a5fd24f

Browse files
committed
Better formatting of process title.
1 parent 743aad4 commit a5fd24f

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

lib/falcon/command/serve.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def endpoint_options
5757
@options.slice(:hostname, :port, :timeout)
5858
end
5959

60+
def name
61+
@options[:hostname] || @options[:bind]
62+
end
63+
6064
def environment
6165
Async::Service::Environment.new(Falcon::Environment::Server).with(
6266
Falcon::Environment::Rackup,
@@ -73,7 +77,7 @@ def environment
7377
preload: [@options[:preload]].compact,
7478
url: @options[:bind],
7579

76-
name: "server",
80+
name: self.name,
7781

7882
endpoint: ->{Endpoint.parse(url, **endpoint_options)}
7983
)

lib/falcon/server.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,41 @@ def self.middleware(rack_app, verbose: false, cache: true)
3535
run rack_app
3636
end
3737
end
38+
39+
def initialize(...)
40+
super
41+
42+
@accept_count = 0
43+
@connection_count = 0
44+
45+
@request_count = 0
46+
@active_count = 0
47+
end
48+
49+
attr :request_count
50+
attr :accept_count
51+
attr :connect_count
52+
53+
def accept(...)
54+
@accept_count += 1
55+
@connection_count += 1
56+
57+
super
58+
ensure
59+
@connection_count -= 1
60+
end
61+
62+
def call(...)
63+
@request_count += 1
64+
@active_count += 1
65+
66+
super
67+
ensure
68+
@active_count -= 1
69+
end
70+
71+
def to_s
72+
"connections: #{@connection_count}/#{@accept_count}, requests: #{@active_count}/#{@request_count}"
73+
end
3874
end
3975
end

lib/falcon/service/server.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def setup(container)
6767
if health_check_timeout
6868
Async(transient: true) do
6969
while true
70-
instance.name = "#{server} load=#{Fiber.scheduler.load}"
70+
# We only update this if the health check is enabled. Maybe we should always update it?
71+
instance.name = "#{self.name} (#{server.to_s}, load: #{Fiber.scheduler.load.round(3)})"
7172
sleep(health_check_timeout / 2)
7273
instance.ready!
7374
end

0 commit comments

Comments
 (0)