puma-status 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/core.rb +38 -8
- data/lib/helpers.rb +2 -1
- data/lib/stats.rb +17 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 379b1ab081684ba19977385c0bad2d6b1635d9fd56225a35b89698574281c832
|
4
|
+
data.tar.gz: 1e8db9d9acbe9a74e850c5ff214bd8258a5c6d748e1e662367003297c40d185a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f2f695e9b510c2dd0f3eb6f808e927dae5a596a69d1e7d8347617c6590e09d0c299c2f66f63574fe95da971fe85c780cea407da2ade8a5eb443230ebbdc22ff
|
7
|
+
data.tar.gz: d618f0c0bc28f4fdf6720b3e595269670967185bacbb5c754fde0e6bf863d37dbe5bb12692099bb25f15a46a634894b494a5bb5dba6c649a5771653862d8567d
|
data/lib/core.rb
CHANGED
@@ -1,13 +1,28 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'json'
|
3
3
|
require 'net_x/http_unix'
|
4
|
+
require 'openssl'
|
4
5
|
require 'time'
|
5
6
|
require_relative 'stats'
|
6
7
|
|
7
8
|
def get_stats(state_file_path)
|
8
9
|
puma_state = YAML.load_file(state_file_path)
|
9
10
|
|
10
|
-
|
11
|
+
uri = URI.parse(puma_state["control_url"])
|
12
|
+
|
13
|
+
address = if uri.scheme =~ /unix/i
|
14
|
+
[uri.scheme, '://', uri.host, uri.path].join
|
15
|
+
else
|
16
|
+
[uri.host, uri.path].join
|
17
|
+
end
|
18
|
+
|
19
|
+
client = NetX::HTTPUnix.new(address, uri.port)
|
20
|
+
|
21
|
+
if uri.scheme =~ /ssl/i
|
22
|
+
client.use_ssl = true
|
23
|
+
client.verify_mode = OpenSSL::SSL::VERIFY_NONE if ENV['SSL_NO_VERIFY'] == '1'
|
24
|
+
end
|
25
|
+
|
11
26
|
req = Net::HTTP::Get.new("/stats?token=#{puma_state["control_auth_token"]}")
|
12
27
|
resp = client.request(req)
|
13
28
|
raw_stats = JSON.parse(resp.body)
|
@@ -36,8 +51,9 @@ def hydrate_stats(stats, puma_state, state_file_path)
|
|
36
51
|
|
37
52
|
stats.tap do |s|
|
38
53
|
stats.workers.map do |wstats|
|
39
|
-
wstats.mem = top_stats
|
40
|
-
wstats.pcpu = top_stats
|
54
|
+
wstats.mem = top_stats.dig(wstats.pid, :mem) || 0
|
55
|
+
wstats.pcpu = top_stats.dig(wstats.pid, :pcpu) || 0
|
56
|
+
wstats.killed = !top_stats.key?(wstats.pid) || (wstats.mem <=0 && wstats.pcpu <= 0)
|
41
57
|
end
|
42
58
|
end
|
43
59
|
end
|
@@ -45,13 +61,27 @@ end
|
|
45
61
|
def format_stats(stats)
|
46
62
|
master_line = "#{stats.pid} (#{stats.state_file_path}) Uptime: #{seconds_to_human(stats.uptime)} "
|
47
63
|
master_line += "| Phase: #{stats.phase} " if stats.phase
|
48
|
-
|
64
|
+
|
65
|
+
if stats.booting?
|
66
|
+
master_line += warn("booting")
|
67
|
+
else
|
68
|
+
master_line += "| Load: #{color(75, 50, stats.load, asciiThreadLoad(stats.running_threads, stats.max_threads))}"
|
69
|
+
end
|
49
70
|
|
50
71
|
output = [master_line] + stats.workers.map do |wstats|
|
51
|
-
worker_line = " └ #{wstats.pid.to_s.rjust(5, ' ')} CPU: #{color(75, 50, wstats.pcpu, wstats.pcpu.to_s.rjust(5, ' '))}% Mem: #{color(1000, 750, wstats.mem, wstats.mem.to_s.rjust(4, ' '))} MB Uptime: #{seconds_to_human(wstats.uptime)}
|
52
|
-
|
53
|
-
|
54
|
-
|
72
|
+
worker_line = " └ #{wstats.pid.to_s.rjust(5, ' ')} CPU: #{color(75, 50, wstats.pcpu, wstats.pcpu.to_s.rjust(5, ' '))}% Mem: #{color(1000, 750, wstats.mem, wstats.mem.to_s.rjust(4, ' '))} MB Uptime: #{seconds_to_human(wstats.uptime)}"
|
73
|
+
|
74
|
+
if wstats.booting?
|
75
|
+
worker_line += " #{warn("booting")}"
|
76
|
+
elsif wstats.killed?
|
77
|
+
worker_line += " #{error("killed")}"
|
78
|
+
else
|
79
|
+
worker_line += " | Load: #{color(75, 50, wstats.load, asciiThreadLoad(wstats.running_threads, wstats.max_threads))}"
|
80
|
+
worker_line += " Phase: #{error(wstats.phase)}" if wstats.phase != stats.phase
|
81
|
+
worker_line += " Queue: #{error(wstats.backlog.to_s)}" if wstats.backlog > 0
|
82
|
+
worker_line += " Last checkin: #{error(wstats.last_checkin)}" if wstats.last_checkin >= 10
|
83
|
+
end
|
84
|
+
|
55
85
|
worker_line
|
56
86
|
end
|
57
87
|
|
data/lib/helpers.rb
CHANGED
@@ -17,7 +17,8 @@ def colorize(str, color_name)
|
|
17
17
|
str.to_s.colorize(color_name)
|
18
18
|
end
|
19
19
|
|
20
|
-
def color(critical, warn, value, str)
|
20
|
+
def color(critical, warn, value, str = nil)
|
21
|
+
str = value unless str
|
21
22
|
color_level = if value >= critical
|
22
23
|
:red
|
23
24
|
elsif value < critical && value >= warn
|
data/lib/stats.rb
CHANGED
@@ -9,6 +9,14 @@ class Stats
|
|
9
9
|
@wstats['pid']
|
10
10
|
end
|
11
11
|
|
12
|
+
def killed=(killed)
|
13
|
+
@wstats['killed'] = killed
|
14
|
+
end
|
15
|
+
|
16
|
+
def killed?
|
17
|
+
!!@wstats['killed']
|
18
|
+
end
|
19
|
+
|
12
20
|
def mem=(mem)
|
13
21
|
@wstats['mem'] = mem
|
14
22
|
end
|
@@ -25,6 +33,10 @@ class Stats
|
|
25
33
|
@wstats['pcpu']
|
26
34
|
end
|
27
35
|
|
36
|
+
def booting?
|
37
|
+
@wstats.key?('last_status') && @wstats['last_status'].empty?
|
38
|
+
end
|
39
|
+
|
28
40
|
def running
|
29
41
|
@wstats.dig('last_status', 'running') || @wstats['running'] || 0
|
30
42
|
end
|
@@ -71,7 +83,7 @@ class Stats
|
|
71
83
|
end
|
72
84
|
|
73
85
|
def workers
|
74
|
-
(@stats['worker_status'] || [@stats]).map { |wstats| Worker.new(wstats) }
|
86
|
+
@workers ||= (@stats['worker_status'] || [@stats]).map { |wstats| Worker.new(wstats) }
|
75
87
|
end
|
76
88
|
|
77
89
|
def pid=(pid)
|
@@ -95,6 +107,10 @@ class Stats
|
|
95
107
|
(Time.now - Time.parse(@stats['started_at'])).to_i
|
96
108
|
end
|
97
109
|
|
110
|
+
def booting?
|
111
|
+
workers.all?(&:booting?)
|
112
|
+
end
|
113
|
+
|
98
114
|
def total_threads
|
99
115
|
workers.reduce(0) { |total, wstats| total + wstats.max_threads }
|
100
116
|
end
|