puma-status 1.3 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/core.rb +7 -5
  3. data/lib/stats.rb +6 -0
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ded7bd0b4bca01b8b07ca16c7380453cf96f49d0c00667d024a6317d7307cea0
4
- data.tar.gz: a391f836ca1c5d1a40acbab75178fd4c569d25005fac3c83bfd981051e1a7d66
3
+ metadata.gz: 2e70794f8cca6fe403afd55f48122c046b0670e7244b0dcad9a50d860c557c69
4
+ data.tar.gz: 5cbbbc03d2744a5ac27c2ca8472d3fdaf7940c21caf74327e5fb78b239427287
5
5
  SHA512:
6
- metadata.gz: c3968446849e0078c9cb557c721a1f5a2226a5ca1533016b319d15ec4c2e769a88062c8f354de28451fad533ba6502707a79660bf9a0469c677482f270ab1c65
7
- data.tar.gz: e186aefc643f0ce7bfaf9515d5a36fc71558c0a871d792914e55e5867d5d0d9e4e32d04a71f27429ab1ae19f43054d06ae00c47911f209bcf423c197e4c586b6
6
+ metadata.gz: 59c577ff899812624b466c06b539a25b4bc4d2cf476909525efe70e5e0ef57e0f12ebb9fe4b632600dba05e8149b6a05b6fc2680fe7d4801c19faca5d81ed5b9
7
+ data.tar.gz: 61268ccb302fd12a882a9d2308702e471814fed48308ff3de109501e8bcade6b0b3d7b1c7edfec1191093f477c389f710c8416cfa9886aa00eac803e1f1a2792
data/lib/core.rb CHANGED
@@ -3,6 +3,7 @@ require 'json'
3
3
  require 'net_x/http_unix'
4
4
  require 'openssl'
5
5
  require 'time'
6
+ require 'open3'
6
7
  require_relative 'stats'
7
8
 
8
9
  def get_stats(state_file_path)
@@ -33,8 +34,6 @@ def get_stats(state_file_path)
33
34
  end
34
35
 
35
36
  def get_memory_from_top(raw_memory)
36
- raw_memory.tr!(',', '.') # because of LC_NUMERIC separator can be ,
37
-
38
37
  case raw_memory[-1].downcase
39
38
  when 'g'
40
39
  (raw_memory[0...-1].to_f*1024).to_i
@@ -48,11 +47,12 @@ end
48
47
  PID_COLUMN = 0
49
48
  MEM_COLUMN = 5
50
49
  CPU_COLUMN = 8
50
+ OPEN3_STDOUT = 1
51
51
 
52
52
  def get_top_stats(pids)
53
53
  pids.each_slice(19).inject({}) do |res, pids19|
54
- top_result = `top -b -n 1 -p #{pids19.join(',')} | tail -n #{pids19.length}`
55
- top_result.split("\n").map { |row| r = row.split(' '); [r[PID_COLUMN].to_i, get_memory_from_top(r[MEM_COLUMN]), r[CPU_COLUMN].to_f] }
54
+ top_result = Open3.popen3({ 'LC_ALL' => 'C' }, "top -b -n 1 -p #{pids19.map(&:to_i).join(',')}")[OPEN3_STDOUT].read
55
+ top_result.split("\n").last(pids19.length).map { |row| r = row.split(' '); [r[PID_COLUMN].to_i, get_memory_from_top(r[MEM_COLUMN]), r[CPU_COLUMN].to_f] }
56
56
  .inject(res) { |hash, row| hash[row[0]] = { mem: row[1], pcpu: row[2] }; hash }
57
57
  res
58
58
  end
@@ -76,7 +76,9 @@ def hydrate_stats(stats, puma_state, state_file_path)
76
76
  end
77
77
 
78
78
  def format_stats(stats)
79
- master_line = "#{stats.pid} (#{stats.state_file_path}) Uptime: #{seconds_to_human(stats.uptime)}"
79
+ master_line = "#{stats.pid} (#{stats.state_file_path})"
80
+ master_line += " Version: #{stats.version} |" if stats.version
81
+ master_line += " Uptime: #{seconds_to_human(stats.uptime)}"
80
82
  master_line += " | Phase: #{stats.phase}" if stats.phase
81
83
 
82
84
  if stats.booting?
data/lib/stats.rb CHANGED
@@ -154,4 +154,10 @@ class Stats
154
154
  def load
155
155
  running_threads/total_threads.to_f*100
156
156
  end
157
+
158
+ def version
159
+ return nil unless @stats.key?('versions')
160
+
161
+ "#{@stats['versions']['puma']}/#{@stats['versions']['ruby']['engine']}#{@stats['versions']['ruby']['version']}p#{@stats['versions']['ruby']['patchlevel']}"
162
+ end
157
163
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puma-status
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.3'
4
+ version: '1.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoann Lecuyer
@@ -119,14 +119,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: 2.3.0
122
+ version: 2.5.0
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubygems_version: 3.3.0.dev
129
+ rubygems_version: 3.4.0.dev
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: Command-line tool for puma to display information about running request/process