greenhat 0.1.5 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/greenhat/accessors/disk.rb +58 -2
- data/lib/greenhat/accessors/gitlab.rb +75 -0
- data/lib/greenhat/accessors/memory.rb +10 -10
- data/lib/greenhat/accessors/process.rb +10 -1
- data/lib/greenhat/cli.rb +148 -63
- data/lib/greenhat/color.rb +27 -0
- data/lib/greenhat/logbot.rb +9 -9
- data/lib/greenhat/settings.rb +51 -3
- data/lib/greenhat/shell/args.rb +146 -0
- data/lib/greenhat/shell/cat.rb +25 -73
- data/lib/greenhat/shell/color_string.rb +43 -0
- data/lib/greenhat/shell/disk.rb +30 -42
- data/lib/greenhat/shell/faststats.rb +104 -58
- data/lib/greenhat/shell/field_helper.rb +75 -0
- data/lib/greenhat/shell/filter_help.rb +162 -0
- data/lib/greenhat/shell/gitlab.rb +61 -2
- data/lib/greenhat/shell/help.rb +98 -15
- data/lib/greenhat/shell/list.rb +46 -0
- data/lib/greenhat/shell/log.rb +115 -209
- data/lib/greenhat/shell/page.rb +39 -0
- data/lib/greenhat/shell/process.rb +57 -2
- data/lib/greenhat/shell/report.rb +70 -60
- data/lib/greenhat/shell/shell_helper.rb +654 -0
- data/lib/greenhat/shell.rb +27 -13
- data/lib/greenhat/thing/file_types.rb +54 -7
- data/lib/greenhat/thing/formatters/json_shellwords.rb +0 -3
- data/lib/greenhat/thing/formatters/nginx.rb +44 -0
- data/lib/greenhat/thing/formatters/syslog.rb +39 -0
- data/lib/greenhat/thing/helpers.rb +4 -4
- data/lib/greenhat/thing/kind.rb +9 -2
- data/lib/greenhat/thing/spinner.rb +3 -3
- data/lib/greenhat/thing.rb +25 -3
- data/lib/greenhat/tty/columns.rb +44 -0
- data/lib/greenhat/version.rb +1 -1
- data/lib/greenhat.rb +16 -14
- metadata +42 -17
- data/lib/greenhat/shell/helper.rb +0 -541
@@ -4,8 +4,63 @@ module GreenHat
|
|
4
4
|
# Logs
|
5
5
|
module Process
|
6
6
|
# Easy Show All
|
7
|
-
|
8
|
-
|
7
|
+
# Filter --archive
|
8
|
+
|
9
|
+
def self.ls
|
10
|
+
help
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.help
|
14
|
+
puts "\u2500".pastel(:cyan) * 22
|
15
|
+
puts "#{'Process'.pastel(:yellow)} - ps helper"
|
16
|
+
puts "\u2500".pastel(:cyan) * 22
|
17
|
+
|
18
|
+
ShellHelper.common_opts
|
19
|
+
|
20
|
+
puts 'Command Summary'.pastel(:blue)
|
21
|
+
puts ' ps'.pastel(:green)
|
22
|
+
puts ' Raw `ps`'
|
23
|
+
puts
|
24
|
+
puts ' filter'.pastel(:green)
|
25
|
+
puts " Key/Field Filtering. See #{'filter_help'.pastel(:blue)}"
|
26
|
+
puts ' Examples'
|
27
|
+
puts ' filter --sort=mem --reverse'.pastel(:green)
|
28
|
+
puts ' filter --user=gitlab'.pastel(:green)
|
29
|
+
|
30
|
+
puts
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.filter_help
|
34
|
+
ShellHelper::Filter.help
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.ps(raw = {})
|
38
|
+
# Extract Args
|
39
|
+
files_list, flags, _args = Args.parse(raw)
|
40
|
+
|
41
|
+
# Collect Files
|
42
|
+
files = ShellHelper.files(files_list, GreenHat::Ps.things, flags)
|
43
|
+
|
44
|
+
# Output
|
45
|
+
ShellHelper.file_output(files, flags)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.filter(raw = {})
|
49
|
+
# Argument Parsing
|
50
|
+
files, flags, args = Args.parse(raw)
|
51
|
+
|
52
|
+
# Prepare Log List
|
53
|
+
file_list = ShellHelper.prepare_list(files, GreenHat::Ps.things)
|
54
|
+
|
55
|
+
results = ShellHelper.filter_start(file_list, flags, args)
|
56
|
+
|
57
|
+
# Check Search Results
|
58
|
+
if results.instance_of?(Hash) && results.values.flatten.empty?
|
59
|
+
puts 'No results'.pastel(:red)
|
60
|
+
else
|
61
|
+
# This causes the key 'colorized' output to also be included
|
62
|
+
ShellHelper.show(results.to_a.compact.flatten, flags)
|
63
|
+
end
|
9
64
|
end
|
10
65
|
end
|
11
66
|
end
|
@@ -2,11 +2,17 @@ module GreenHat
|
|
2
2
|
# Root Level Shell / Report Helper
|
3
3
|
module Shell
|
4
4
|
def self.report(raw)
|
5
|
-
|
6
|
-
raw: raw.include?('--raw')
|
7
|
-
}
|
5
|
+
_files, flags, _args = Args.parse(raw)
|
8
6
|
|
9
|
-
|
7
|
+
archives = if flags.archive
|
8
|
+
Archive.all.select do |archive|
|
9
|
+
flags.archive.any? { |x| archive.name.include? x.to_s }
|
10
|
+
end
|
11
|
+
else
|
12
|
+
Archive.all
|
13
|
+
end
|
14
|
+
|
15
|
+
ShellHelper.show(archives.map(&:report).map(&:show).flatten, flags)
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
@@ -19,7 +25,7 @@ module GreenHat
|
|
19
25
|
|
20
26
|
attr_accessor :archive, :host, :os_release, :selinux_status, :cpu, :uname,
|
21
27
|
:timedatectl, :uptime, :meminfo, :gitlab_manifest, :gitlab_status,
|
22
|
-
:production_log, :api_log, :application_log, :sidekiq_log, :free_m
|
28
|
+
:production_log, :api_log, :application_log, :sidekiq_log, :free_m, :disk_free
|
23
29
|
|
24
30
|
# Find Needed Files for Report
|
25
31
|
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
|
@@ -40,15 +46,16 @@ module GreenHat
|
|
40
46
|
self.api_log = archive.things.find { |x| x.name == 'gitlab-rails/api_json.log' }
|
41
47
|
self.application_log = archive.things.find { |x| x.name == 'gitlab-rails/application_json.log' }
|
42
48
|
self.sidekiq_log = archive.things.find { |x| x.name == 'sidekiq/current' }
|
49
|
+
self.disk_free = archive.things.find { |x| x.name == 'df_h' }
|
43
50
|
end
|
44
51
|
|
45
52
|
def show
|
46
53
|
output = [
|
47
|
-
archive.friendly_name.
|
54
|
+
archive.friendly_name.pastel(:blue)
|
48
55
|
]
|
49
56
|
|
50
57
|
# OS
|
51
|
-
output << 'OS'.
|
58
|
+
output << 'OS'.pastel(:bright_yellow)
|
52
59
|
output << hostname if host
|
53
60
|
output << distro if os_release
|
54
61
|
output << selinux if selinux_status
|
@@ -61,14 +68,20 @@ module GreenHat
|
|
61
68
|
|
62
69
|
# Memory
|
63
70
|
if meminfo || free_m
|
64
|
-
output << 'Memory'.
|
65
|
-
output <<
|
71
|
+
output << 'Memory'.pastel(:bright_yellow)
|
72
|
+
output << memory_perc if meminfo
|
66
73
|
output << memory_free if free_m
|
67
74
|
output << ''
|
68
75
|
end
|
69
76
|
|
77
|
+
# Disk
|
78
|
+
if disk_free
|
79
|
+
output << disks
|
80
|
+
output << ''
|
81
|
+
end
|
82
|
+
|
70
83
|
# Gitlab
|
71
|
-
output << 'GitLab'.
|
84
|
+
output << 'GitLab'.pastel(:bright_yellow) if gitlab_manifest
|
72
85
|
output << gitlab_version if gitlab_manifest
|
73
86
|
output << gitlab_services if gitlab_status
|
74
87
|
output << title('Errors') if production_log || api_log || application_log || sidekiq_log
|
@@ -88,8 +101,8 @@ module GreenHat
|
|
88
101
|
color = count.zero? ? :green : :red
|
89
102
|
|
90
103
|
[
|
91
|
-
title(' Production', :
|
92
|
-
count.to_s.
|
104
|
+
title(' Production', :bright_red, 18),
|
105
|
+
count.to_s.pastel(color)
|
93
106
|
].join
|
94
107
|
end
|
95
108
|
|
@@ -98,8 +111,8 @@ module GreenHat
|
|
98
111
|
color = count.zero? ? :green : :red
|
99
112
|
|
100
113
|
[
|
101
|
-
title(' API', :
|
102
|
-
count.to_s.
|
114
|
+
title(' API', :bright_red, 18),
|
115
|
+
count.to_s.pastel(color)
|
103
116
|
].join
|
104
117
|
end
|
105
118
|
|
@@ -108,8 +121,8 @@ module GreenHat
|
|
108
121
|
color = count.zero? ? :green : :red
|
109
122
|
|
110
123
|
[
|
111
|
-
title(' Application', :
|
112
|
-
count.to_s.
|
124
|
+
title(' Application', :bright_red, 18),
|
125
|
+
count.to_s.pastel(color)
|
113
126
|
].join
|
114
127
|
end
|
115
128
|
|
@@ -118,32 +131,16 @@ module GreenHat
|
|
118
131
|
color = count.zero? ? :green : :red
|
119
132
|
|
120
133
|
[
|
121
|
-
title(' Sidekiq', :
|
122
|
-
count.to_s.
|
134
|
+
title(' Sidekiq', :bright_red, 18),
|
135
|
+
count.to_s.pastel(color)
|
123
136
|
].join
|
124
137
|
end
|
125
138
|
|
126
139
|
def gitlab_services
|
127
|
-
list = gitlab_status.data.keys.sort.map do |service|
|
128
|
-
color = gitlab_status.data.dig(service, 0, :status) == 'run' ? :green : :red
|
129
|
-
service.colorize(color)
|
130
|
-
end
|
131
|
-
|
132
|
-
# Keep Alphabetical Sort
|
133
|
-
groups = list.each_slice((list.size / 3.to_f).round).to_a
|
134
|
-
|
135
|
-
table = TTY::Table.new do |t|
|
136
|
-
loop do
|
137
|
-
break if groups.all?(&:empty?)
|
138
|
-
|
139
|
-
t << groups.map(&:shift)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
140
|
[
|
144
141
|
title('Services'),
|
145
142
|
"\n ",
|
146
|
-
|
143
|
+
GitLab.services(archive, 3)
|
147
144
|
].join
|
148
145
|
rescue StandardError => e
|
149
146
|
LogBot.fatal('GitLab Services', message: e.message, backtrace: e.backtrace.first)
|
@@ -166,7 +163,7 @@ module GreenHat
|
|
166
163
|
def distro
|
167
164
|
[
|
168
165
|
title('Distro'),
|
169
|
-
"[#{os_release.data.ID}] ".
|
166
|
+
"[#{os_release.data.ID}] ".pastel(:bright_black),
|
170
167
|
os_release.data.PRETTY_NAME
|
171
168
|
].join
|
172
169
|
end
|
@@ -177,7 +174,7 @@ module GreenHat
|
|
177
174
|
|
178
175
|
[
|
179
176
|
title('SeLinux'),
|
180
|
-
status.
|
177
|
+
status.pastel(status_color),
|
181
178
|
' (',
|
182
179
|
selinux_status.data['Current mode'],
|
183
180
|
')'
|
@@ -197,7 +194,7 @@ module GreenHat
|
|
197
194
|
[
|
198
195
|
title('Kernel'),
|
199
196
|
value,
|
200
|
-
" (#{build})".
|
197
|
+
" (#{build})".pastel(:bright_black)
|
201
198
|
].join
|
202
199
|
end
|
203
200
|
|
@@ -209,6 +206,9 @@ module GreenHat
|
|
209
206
|
end
|
210
207
|
|
211
208
|
def sys_time
|
209
|
+
# Ignore if Empty
|
210
|
+
return false if timedatectl.data.nil?
|
211
|
+
|
212
212
|
ntp_statuses = timedatectl.data.slice(*ntp_keys).values.compact
|
213
213
|
|
214
214
|
enabled = %w[active yes] & ntp_statuses
|
@@ -221,9 +221,9 @@ module GreenHat
|
|
221
221
|
[
|
222
222
|
title('Sys Time'),
|
223
223
|
timedatectl.data['Local time'],
|
224
|
-
' (ntp: '.
|
225
|
-
ntp_status.
|
226
|
-
')'.
|
224
|
+
' (ntp: '.pastel(:bright_black),
|
225
|
+
ntp_status.pastel(ntp_color),
|
226
|
+
')'.pastel(:bright_black)
|
227
227
|
].join
|
228
228
|
end
|
229
229
|
|
@@ -248,38 +248,30 @@ module GreenHat
|
|
248
248
|
[
|
249
249
|
interval,
|
250
250
|
' (',
|
251
|
-
"#{value}%".
|
251
|
+
"#{value}%".pastel(color),
|
252
252
|
')'
|
253
253
|
].join
|
254
254
|
end
|
255
255
|
|
256
256
|
[
|
257
257
|
title('LoadAvg'),
|
258
|
-
"[CPU #{cpu_count}] ".
|
258
|
+
"[CPU #{cpu_count}] ".pastel(:bright_white),
|
259
259
|
intervals_text.join(', ')
|
260
260
|
].join
|
261
261
|
end
|
262
262
|
|
263
|
-
def
|
263
|
+
def memory_perc
|
264
264
|
total = ShellHelper.human_size_to_number(meminfo.data['MemTotal'])
|
265
265
|
free = ShellHelper.human_size_to_number(meminfo.data['MemFree'])
|
266
266
|
used = percent((total - free), total)
|
267
|
+
|
267
268
|
[
|
268
|
-
title('
|
269
|
-
'['.
|
270
|
-
'='.
|
269
|
+
title('Usage'),
|
270
|
+
' ['.pastel(:bright_black),
|
271
|
+
'='.pastel(:green) * (used / 2),
|
271
272
|
' ' * (50 - used / 2),
|
272
|
-
']'.
|
273
|
-
" #{100 - percent(free, total)}%".
|
274
|
-
"\n",
|
275
|
-
title('Total'),
|
276
|
-
number_to_human_size(total).colorize(:light_white),
|
277
|
-
"\n",
|
278
|
-
title('Used'),
|
279
|
-
number_to_human_size(total - free),
|
280
|
-
"\n",
|
281
|
-
title('Free'),
|
282
|
-
number_to_human_size(free)
|
273
|
+
']'.pastel(:bright_black),
|
274
|
+
" #{100 - percent(free, total)}%".pastel(:green) # Inverse
|
283
275
|
].join
|
284
276
|
end
|
285
277
|
|
@@ -288,6 +280,8 @@ module GreenHat
|
|
288
280
|
|
289
281
|
return unless free
|
290
282
|
|
283
|
+
formatted_mem = free_m.data.map { |x| GreenHat::Memory.memory_row x }
|
284
|
+
|
291
285
|
[
|
292
286
|
title('Total', :cyan, 14),
|
293
287
|
number_to_human_size(free.total.to_i * 1024**2),
|
@@ -299,7 +293,23 @@ module GreenHat
|
|
299
293
|
number_to_human_size(free.free.to_i * 1024**2),
|
300
294
|
"\n",
|
301
295
|
title('Available', :green, 14),
|
302
|
-
number_to_human_size(free.available.to_i * 1024**2)
|
296
|
+
number_to_human_size(free.available.to_i * 1024**2),
|
297
|
+
"\n\n",
|
298
|
+
formatted_mem.map { |x| x.prepend ' ' * 2 }.join("\n")
|
299
|
+
].join
|
300
|
+
end
|
301
|
+
|
302
|
+
def disks
|
303
|
+
# GreenHat::Disk.df({archive: []})
|
304
|
+
file = GreenHat::Disk.df({ archive: [archive.name] })
|
305
|
+
|
306
|
+
disk_list = GreenHat::Disk.format_output(file.first, false, 3)
|
307
|
+
|
308
|
+
# Preapre / Indent List
|
309
|
+
[
|
310
|
+
'Disks'.pastel(:bright_yellow) + ' (Top % Usage)'.pastel(:bright_black),
|
311
|
+
"\n",
|
312
|
+
disk_list.each { |x| x.prepend(' ' * 4) }.join("\n")
|
303
313
|
].join
|
304
314
|
end
|
305
315
|
|
@@ -312,7 +322,7 @@ module GreenHat
|
|
312
322
|
|
313
323
|
# Helper to Make Cyan Titles
|
314
324
|
def title(name, color = :cyan, ljust = 12)
|
315
|
-
" #{name}:".ljust(ljust).
|
325
|
+
" #{name}:".ljust(ljust).pastel(color)
|
316
326
|
end
|
317
327
|
end
|
318
328
|
# rubocop:enable Metrics/ClassLength
|