Skip to content

Commit dc16a24

Browse files
committed
Improvements
1 parent ab55f22 commit dc16a24

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

script/passenger_worker_cleaner.rb

+11-17
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,12 @@ def parse(output)
152152
next
153153
end
154154

155-
# Extract CPU and Memory using regex to handle variable whitespace
156-
if line =~ /^CPU\s*:\s*([\d.]+)%\s+Memory\s*:\s*([\d.]+\s*[KMGTP]?)/i
155+
# Extract CPU, Memory, and Last used using regex to handle variable whitespace
156+
if line =~ /^CPU\s*:\s*([\d.]+)%\s+Memory\s*:\s*([\d.]+\s*[KMGTP]?)\s+Last\s+used\s*:\s*([\dm\s]+s)/i
157157
current_worker_data[:cpu] = Regexp.last_match(1).to_f
158158
current_worker_data[:memory_str] = Regexp.last_match(2).strip
159-
debug_log("Parsed CPU and Memory: CPU=#{current_worker_data[:cpu]}%, Memory='#{current_worker_data[:memory_str]}'")
160-
next
161-
end
162-
163-
# Extract Last used using regex to handle variable whitespace
164-
if line =~ /^Last\s+used\s*:\s*([\dm\s]+s)\s*(?:ago|ag)?/i
165-
current_worker_data[:last_used_str] = Regexp.last_match(1).strip
166-
debug_log("Parsed Last Used: '#{current_worker_data[:last_used_str]}'")
159+
current_worker_data[:last_used_str] = Regexp.last_match(3).strip
160+
debug_log("Parsed CPU, Memory, Last Used: CPU=#{current_worker_data[:cpu]}%, Memory='#{current_worker_data[:memory_str]}', Last Used='#{current_worker_data[:last_used_str]}'")
167161
next
168162
end
169163
end
@@ -245,13 +239,13 @@ def print_summary(total_processes, workers)
245239
end
246240

247241
# Define column widths
248-
pid_width = 8
249-
sessions_width = 10
250-
processed_width = 12
251-
uptime_width = 12
252-
cpu_width = 8
253-
memory_width = 14
254-
last_used_width = 14
242+
pid_width = 10
243+
sessions_width = 12
244+
processed_width = 14
245+
uptime_width = 14
246+
cpu_width = 10
247+
memory_width = 16
248+
last_used_width = 16
255249

256250
# Print table header
257251
header = [

0 commit comments

Comments
 (0)