Class: OsCtl::Cli::Ps::Columns
- Inherits:
-
Object
- Object
- OsCtl::Cli::Ps::Columns
- Includes:
- Lib::Utils::Humanize
- Defined in:
- lib/osctl/cli/ps/columns.rb
Constant Summary collapse
- COLS =
%i( pool ctid pid ctpid ruid rgid euid egid ctruid ctrgid cteuid ctegid vmsize rss state start time command name )
- DEFAULT_ONE_CT =
%i( pid ctpid cteuid vmsize rss state start time command )
- DEFAULT_ONE_POOL =
%i(ctid) + DEFAULT_ONE_CT
- DEFAULT_MULTIPLE_POOLS =
%i(pool) + DEFAULT_ONE_POOL
- ALIGN_RIGHT =
%i( pid ruid rgid euid egid ctruid ctrgid cteuid ctegid vmsize rss time )
Instance Attribute Summary collapse
-
#os_proc ⇒ Object
readonly
protected
Returns the value of attribute os_proc.
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object
- #ctegid ⇒ Object
- #cteuid ⇒ Object
- #ctid ⇒ Object
- #ctpid ⇒ Object
- #ctrgid ⇒ Object
- #ctruid ⇒ Object
- #egid ⇒ Object
- #euid ⇒ Object
- #format_time(v) ⇒ Object protected
-
#initialize(os_proc, precise) ⇒ Columns
constructor
A new instance of Columns.
- #mapped_id_or_fallback(id) ⇒ Object protected
- #name ⇒ Object
- #pid ⇒ Object
- #pool ⇒ Object
- #precise? ⇒ Boolean protected
- #present_data(v) ⇒ Object protected
- #present_duration(v) ⇒ Object protected
- #present_time(v) ⇒ Object protected
- #rgid ⇒ Object
- #rss ⇒ Object
- #ruid ⇒ Object
- #start ⇒ Object
- #state ⇒ Object
- #time ⇒ Object
- #vmsize ⇒ Object
Constructor Details
#initialize(os_proc, precise) ⇒ Columns
Returns a new instance of Columns.
90 91 92 93 |
# File 'lib/osctl/cli/ps/columns.rb', line 90 def initialize(os_proc, precise) @os_proc = os_proc @precise = precise end |
Instance Attribute Details
#os_proc ⇒ Object (readonly, protected)
Returns the value of attribute os_proc.
180 181 182 |
# File 'lib/osctl/cli/ps/columns.rb', line 180 def os_proc @os_proc end |
Class Method Details
.generate(process_list, cols, precise) ⇒ Array<Hash>
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/osctl/cli/ps/columns.rb', line 62 def self.generate(process_list, cols, precise) spec = cols.map do |c| { name: c, label: c.to_s.upcase, align: ALIGN_RIGHT.include?(c) ? :right : :left, } end data = [] process_list.each do |os_proc| row = new(os_proc, precise) begin data << Hash[cols.map { |c| [c, row.send(c)] }] rescue OsCtl::Lib::Exceptions::OsProcessNotFound next end end [spec, data] end |
Instance Method Details
#command ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'lib/osctl/cli/ps/columns.rb', line 165 def command cmdline = os_proc.cmdline if cmdline.strip.empty? "[#{os_proc.name}]" else cmdline end end |
#ctegid ⇒ Object
141 142 143 |
# File 'lib/osctl/cli/ps/columns.rb', line 141 def ctegid mapped_id_or_fallback(:egid) end |
#cteuid ⇒ Object
137 138 139 |
# File 'lib/osctl/cli/ps/columns.rb', line 137 def cteuid mapped_id_or_fallback(:euid) end |
#ctid ⇒ Object
100 101 102 103 |
# File 'lib/osctl/cli/ps/columns.rb', line 100 def ctid pool, id = os_proc.ct_id pool.nil? ? '[host]' : id end |
#ctpid ⇒ Object
109 110 111 |
# File 'lib/osctl/cli/ps/columns.rb', line 109 def ctpid os_proc.ct_pid end |
#ctrgid ⇒ Object
133 134 135 |
# File 'lib/osctl/cli/ps/columns.rb', line 133 def ctrgid mapped_id_or_fallback(:rgid) end |
#ctruid ⇒ Object
129 130 131 |
# File 'lib/osctl/cli/ps/columns.rb', line 129 def ctruid mapped_id_or_fallback(:ruid) end |
#egid ⇒ Object
125 126 127 |
# File 'lib/osctl/cli/ps/columns.rb', line 125 def egid os_proc.egid end |
#euid ⇒ Object
121 122 123 |
# File 'lib/osctl/cli/ps/columns.rb', line 121 def euid os_proc.euid end |
#format_time(v) ⇒ Object (protected)
194 195 196 197 198 199 200 201 202 |
# File 'lib/osctl/cli/ps/columns.rb', line 194 def format_time(v) now = Time.now if now - v > 24*60*60 v.strftime('%b%d') else v.strftime('%H:%M') end end |
#mapped_id_or_fallback(id) ⇒ Object (protected)
204 205 206 207 208 |
# File 'lib/osctl/cli/ps/columns.rb', line 204 def mapped_id_or_fallback(id) os_proc.send(:"ct_#{id}") rescue OsCtl::Lib::Exceptions::IdMappingError os_proc.send(id) * -1 end |
#name ⇒ Object
175 176 177 |
# File 'lib/osctl/cli/ps/columns.rb', line 175 def name os_proc.name end |
#pid ⇒ Object
105 106 107 |
# File 'lib/osctl/cli/ps/columns.rb', line 105 def pid os_proc.pid end |
#pool ⇒ Object
95 96 97 98 |
# File 'lib/osctl/cli/ps/columns.rb', line 95 def pool pool, _ = os_proc.ct_id pool.nil? ? '-' : pool end |
#precise? ⇒ Boolean (protected)
210 211 212 |
# File 'lib/osctl/cli/ps/columns.rb', line 210 def precise? @precise end |
#present_data(v) ⇒ Object (protected)
182 183 184 |
# File 'lib/osctl/cli/ps/columns.rb', line 182 def present_data(v) OsCtl::Lib::Cli::Presentable.new(v, formatted: precise? ? nil : humanize_data(v)) end |
#present_duration(v) ⇒ Object (protected)
190 191 192 |
# File 'lib/osctl/cli/ps/columns.rb', line 190 def present_duration(v) OsCtl::Lib::Cli::Presentable.new(v, formatted: precise? ? nil : format_short_duration(v)) end |
#present_time(v) ⇒ Object (protected)
186 187 188 |
# File 'lib/osctl/cli/ps/columns.rb', line 186 def present_time(v) OsCtl::Lib::Cli::Presentable.new(v, formatted: precise? ? nil : format_time(v)) end |
#rgid ⇒ Object
117 118 119 |
# File 'lib/osctl/cli/ps/columns.rb', line 117 def rgid os_proc.rgid end |
#rss ⇒ Object
149 150 151 |
# File 'lib/osctl/cli/ps/columns.rb', line 149 def rss present_data(os_proc.rss) end |
#ruid ⇒ Object
113 114 115 |
# File 'lib/osctl/cli/ps/columns.rb', line 113 def ruid os_proc.ruid end |
#start ⇒ Object
157 158 159 |
# File 'lib/osctl/cli/ps/columns.rb', line 157 def start present_time(os_proc.start_time) end |
#state ⇒ Object
153 154 155 |
# File 'lib/osctl/cli/ps/columns.rb', line 153 def state os_proc.state end |
#time ⇒ Object
161 162 163 |
# File 'lib/osctl/cli/ps/columns.rb', line 161 def time present_duration(os_proc.user_time + os_proc.sys_time) end |
#vmsize ⇒ Object
145 146 147 |
# File 'lib/osctl/cli/ps/columns.rb', line 145 def vmsize present_data(os_proc.vmsize) end |