greenhat 0.4.0 → 0.6.1
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/bin/greenhat +1 -2
- data/lib/greenhat/accessors/disk.rb +1 -1
- data/lib/greenhat/accessors/gitlab.rb +4 -2
- data/lib/greenhat/archive.rb +7 -1
- data/lib/greenhat/cli.rb +24 -11
- data/lib/greenhat/entrypoint.rb +37 -34
- data/lib/greenhat/host.rb +1 -1
- data/lib/greenhat/logbot.rb +1 -1
- data/lib/greenhat/paper/flag_helper.rb +18 -0
- data/lib/greenhat/paper/paper_helper.rb +118 -0
- data/lib/greenhat/paper.rb +34 -0
- data/lib/greenhat/reports/builder.rb +98 -0
- data/lib/greenhat/reports/helpers.rb +101 -0
- data/lib/greenhat/reports/internal_methods.rb +156 -0
- data/lib/greenhat/reports/reports/errors.rb +49 -0
- data/lib/greenhat/reports/reports/faststats.rb +42 -0
- data/lib/greenhat/reports/reports/full.rb +143 -0
- data/lib/greenhat/reports/runner.rb +58 -0
- data/lib/greenhat/reports/shared.rb +37 -0
- data/lib/greenhat/reports/shell_helper.rb +34 -0
- data/lib/greenhat/reports.rb +79 -0
- data/lib/greenhat/settings.rb +35 -8
- data/lib/greenhat/shell/args.rb +9 -9
- data/lib/greenhat/shell/color_string.rb +1 -1
- data/lib/greenhat/shell/faststats.rb +24 -5
- data/lib/greenhat/shell/field_helper.rb +1 -1
- data/lib/greenhat/shell/filter_help.rb +65 -185
- data/lib/greenhat/shell/gitlab.rb +1 -0
- data/lib/greenhat/shell/log.rb +24 -30
- data/lib/greenhat/shell/markdown.rb +355 -352
- data/lib/greenhat/shell/process.rb +11 -5
- data/lib/greenhat/shell/query.rb +534 -0
- data/lib/greenhat/shell/report.rb +415 -410
- data/lib/greenhat/shell/reports.rb +41 -0
- data/lib/greenhat/shell/shell_helper.rb +95 -387
- data/lib/greenhat/shell.rb +22 -3
- data/lib/greenhat/thing/file_types.rb +30 -1
- data/lib/greenhat/thing/formatters/api_json.rb +4 -2
- data/lib/greenhat/thing/formatters/bracket_log.rb +1 -1
- data/lib/greenhat/thing/formatters/clean_raw.rb +1 -1
- data/lib/greenhat/thing/formatters/colon_split_strip.rb +2 -2
- data/lib/greenhat/thing/formatters/dotenv.rb +1 -1
- data/lib/greenhat/thing/formatters/format.rb +0 -11
- data/lib/greenhat/thing/formatters/free_m.rb +2 -2
- data/lib/greenhat/thing/formatters/json.rb +41 -17
- data/lib/greenhat/thing/formatters/json_shellwords.rb +3 -2
- data/lib/greenhat/thing/formatters/kube_json.rb +3 -2
- data/lib/greenhat/thing/formatters/multiline_json.rb +1 -1
- data/lib/greenhat/thing/formatters/nginx.rb +5 -1
- data/lib/greenhat/thing/formatters/runner_log.rb +70 -0
- data/lib/greenhat/thing/formatters/table.rb +17 -3
- data/lib/greenhat/thing/formatters/time_json.rb +12 -1
- data/lib/greenhat/thing/helpers.rb +0 -11
- data/lib/greenhat/thing/info_format.rb +4 -4
- data/lib/greenhat/thing/kind.rb +1 -1
- data/lib/greenhat/thing.rb +21 -25
- data/lib/greenhat/version.rb +1 -1
- data/lib/greenhat.rb +6 -8
- metadata +32 -4
- data/lib/greenhat/pry_helpers.rb +0 -51
- data/lib/greenhat/thing/super_log.rb +0 -102
@@ -1,410 +1,415 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
1
|
+
# Deprecated in favor of reports module
|
2
|
+
# TODO: Remove
|
3
|
+
# module GreenHat
|
4
|
+
# # Root Level Shell / Report Helper
|
5
|
+
# module Shell
|
6
|
+
# def self.report(raw)
|
7
|
+
|
8
|
+
# _files, flags, _args = Args.parse(raw)
|
9
|
+
|
10
|
+
# archives = if flags.archive
|
11
|
+
# Archive.all.select do |archive|
|
12
|
+
# flags.archive.any? { |x| archive.name.include? x.to_s }
|
13
|
+
# end
|
14
|
+
# else
|
15
|
+
# Archive.all
|
16
|
+
# end
|
17
|
+
|
18
|
+
# output = archives.map { |x| x.report(flags) }.map(&:show).flatten
|
19
|
+
|
20
|
+
# flags[:page] = true if flags.full && !flags.raw
|
21
|
+
|
22
|
+
# ShellHelper.show(output, flags)
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
|
27
|
+
# module GreenHat
|
28
|
+
# # Report Generator Helper
|
29
|
+
#
|
30
|
+
# class Report
|
31
|
+
# include ActionView::Helpers::NumberHelper
|
32
|
+
|
33
|
+
# attr_accessor :archive, :flags, :host, :os_release, :selinux_status, :cpu, :uname,
|
34
|
+
# :timedatectl, :uptime, :meminfo, :gitlab_manifest, :gitlab_status,
|
35
|
+
# :production_log, :api_log, :sidekiq_log,
|
36
|
+
# :exceptions_log, :gitaly_log, :free_m, :disk_free
|
37
|
+
|
38
|
+
# # Find Needed Files for Report
|
39
|
+
#
|
40
|
+
# def initialize(archive, flags)
|
41
|
+
# self.archive = archive
|
42
|
+
# self.flags = flags
|
43
|
+
# self.host = archive.things.find { |x| x.name == 'hostname' }
|
44
|
+
# self.os_release = archive.things.find { |x| x.name == 'etc/os-release' }
|
45
|
+
# self.selinux_status = archive.things.find { |x| x.name == 'sestatus' }
|
46
|
+
# self.cpu = archive.things.find { |x| x.name == 'lscpu' }
|
47
|
+
# self.uname = archive.things.find { |x| x.name == 'uname' }
|
48
|
+
# self.timedatectl = archive.things.find { |x| x.name == 'timedatectl' }
|
49
|
+
# self.uptime = archive.things.find { |x| x.name == 'uptime' }
|
50
|
+
# self.meminfo = archive.things.find { |x| x.name == 'meminfo' }
|
51
|
+
# self.free_m = archive.things.find { |x| x.name == 'free_m' }
|
52
|
+
# self.gitlab_manifest = archive.things.find { |x| x.name == 'gitlab/version-manifest.json' }
|
53
|
+
# self.gitlab_status = archive.things.find { |x| x.name == 'gitlab_status' }
|
54
|
+
# self.production_log = archive.things.find { |x| x.name == 'gitlab-rails/production_json.log' }
|
55
|
+
# self.api_log = archive.things.find { |x| x.name == 'gitlab-rails/api_json.log' }
|
56
|
+
# self.exceptions_log = archive.things.find { |x| x.name == 'gitlab-rails/exceptions_json.log' }
|
57
|
+
# self.gitaly_log = archive.things.find { |x| x.name == 'gitaly/current' }
|
58
|
+
# self.sidekiq_log = archive.things.find { |x| x.name == 'sidekiq/current' }
|
59
|
+
# self.disk_free = archive.things.find { |x| x.name == 'df_hT' }
|
60
|
+
# end
|
61
|
+
|
62
|
+
# def show
|
63
|
+
# output = [
|
64
|
+
# archive.friendly_name.pastel(:blue)
|
65
|
+
# ]
|
66
|
+
|
67
|
+
# # OS
|
68
|
+
# output << 'OS'.pastel(:bright_yellow)
|
69
|
+
# output << hostname if host
|
70
|
+
# output << distro if os_release
|
71
|
+
# output << selinux if selinux_status
|
72
|
+
# # output << arch if cpu
|
73
|
+
# output << kernel if uname
|
74
|
+
# output << sys_time if timedatectl
|
75
|
+
# output << sys_uptime if uptime
|
76
|
+
# output << load_average if uptime && cpu
|
77
|
+
# output << ''
|
78
|
+
|
79
|
+
# # Memory
|
80
|
+
# if meminfo || free_m
|
81
|
+
# output << 'Memory'.pastel(:bright_yellow)
|
82
|
+
# output << memory_perc if meminfo
|
83
|
+
# output << memory_free if free_m
|
84
|
+
# output << ''
|
85
|
+
# end
|
86
|
+
|
87
|
+
# # Disk
|
88
|
+
# if disk_free
|
89
|
+
# output << disks
|
90
|
+
# output << ''
|
91
|
+
# end
|
92
|
+
|
93
|
+
# # Gitlab
|
94
|
+
# output << 'GitLab'.pastel(:bright_yellow) if gitlab_manifest
|
95
|
+
# output << gitlab_version if gitlab_manifest
|
96
|
+
# output << gitlab_services if gitlab_status
|
97
|
+
# output << title('Errors') if production_log || api_log || sidekiq_log
|
98
|
+
# output << production_errors if production_log
|
99
|
+
# output << application_errors if archive.thing?('gitlab-rails/application_json.log')
|
100
|
+
# output << sidekiq_errors if sidekiq_log
|
101
|
+
# output << api_errors if api_log
|
102
|
+
# output << exception_errors if exceptions_log
|
103
|
+
# output << gitaly_errors if gitaly_log
|
104
|
+
# output << workhorse_errors if archive.thing?('gitlab-workhorse/current')
|
105
|
+
|
106
|
+
# full(output) if flags.full
|
107
|
+
|
108
|
+
# # Final Space / Return
|
109
|
+
# output << ''
|
110
|
+
# output
|
111
|
+
# end
|
112
|
+
# # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
|
113
|
+
|
114
|
+
# def full(output)
|
115
|
+
# output << ''
|
116
|
+
# output << 'FastStats Top'
|
117
|
+
# Shell::Faststats.top(['--raw'], true).each { |x| output << x } # Page Row Helper
|
118
|
+
# output << ''
|
119
|
+
|
120
|
+
# output << 'FastStats Errors'
|
121
|
+
# Shell::Faststats.errors(['--raw'], true).each { |x| output << x } # Page Row Helper
|
122
|
+
# output << ''
|
123
|
+
# end
|
124
|
+
|
125
|
+
# def exception_errors
|
126
|
+
# count = exceptions_log.data.count
|
127
|
+
# color = count.zero? ? :green : :red
|
128
|
+
|
129
|
+
# [
|
130
|
+
# title(' Exception', :bright_red, 18),
|
131
|
+
# count.to_s.pastel(color)
|
132
|
+
# ].join
|
133
|
+
# end
|
134
|
+
|
135
|
+
# def workhorse_errors
|
136
|
+
# results = ShellHelper.filter_internal([
|
137
|
+
# 'gitlab-workhorse/current',
|
138
|
+
# '--level=error',
|
139
|
+
# "--archive=#{archive.name}"
|
140
|
+
# ].join(' '))
|
141
|
+
|
142
|
+
# color = results.count.zero? ? :green : :red
|
143
|
+
|
144
|
+
# [
|
145
|
+
# title(' Workhorse', :bright_red, 18),
|
146
|
+
# results.count.to_s.pastel(color)
|
147
|
+
# ].join
|
148
|
+
# end
|
149
|
+
|
150
|
+
# def gitaly_errors
|
151
|
+
# count = gitaly_log.data.count { |x| x.level == 'error' }
|
152
|
+
# color = count.zero? ? :green : :red
|
153
|
+
|
154
|
+
# [
|
155
|
+
# title(' Gitaly', :bright_red, 18),
|
156
|
+
# count.to_s.pastel(color)
|
157
|
+
# ].join
|
158
|
+
# end
|
159
|
+
|
160
|
+
# def production_errors
|
161
|
+
# count = production_log.data.count { |x| x.status == 500 }
|
162
|
+
# color = count.zero? ? :green : :red
|
163
|
+
|
164
|
+
# [
|
165
|
+
# title(' Production', :bright_red, 18),
|
166
|
+
# count.to_s.pastel(color)
|
167
|
+
# ].join
|
168
|
+
# end
|
169
|
+
|
170
|
+
# def api_errors
|
171
|
+
# count = api_log.data.count { |x| x.status == 500 }
|
172
|
+
# color = count.zero? ? :green : :red
|
173
|
+
|
174
|
+
# [
|
175
|
+
# title(' API', :bright_red, 18),
|
176
|
+
# count.to_s.pastel(color)
|
177
|
+
# ].join
|
178
|
+
# end
|
179
|
+
|
180
|
+
# def application_errors
|
181
|
+
# results = ShellHelper.filter_internal([
|
182
|
+
# 'gitlab-rails/application_json.log',
|
183
|
+
# '--message!="Cannot obtain an exclusive lease"',
|
184
|
+
# '--severity=error',
|
185
|
+
# "--archive=#{archive.name}"
|
186
|
+
# ].join(' '))
|
187
|
+
|
188
|
+
# count = results.count { |x| x&.severity == 'ERROR' }
|
189
|
+
# color = count.zero? ? :green : :red
|
190
|
+
|
191
|
+
# [
|
192
|
+
# title(' Application', :bright_red, 18),
|
193
|
+
# count.to_s.pastel(color)
|
194
|
+
# ].join
|
195
|
+
# end
|
196
|
+
|
197
|
+
# def sidekiq_errors
|
198
|
+
# count = sidekiq_log.data.count { |x| x&.severity == 'ERROR' }
|
199
|
+
# color = count.zero? ? :green : :red
|
200
|
+
|
201
|
+
# [
|
202
|
+
# title(' Sidekiq', :bright_red, 18),
|
203
|
+
# count.to_s.pastel(color)
|
204
|
+
# ].join
|
205
|
+
# end
|
206
|
+
|
207
|
+
# def gitlab_services
|
208
|
+
# [
|
209
|
+
# title('Services'),
|
210
|
+
# "\n ",
|
211
|
+
# GitLab.services(archive, 3)
|
212
|
+
# ].join
|
213
|
+
# rescue StandardError => e
|
214
|
+
# LogBot.fatal('GitLab Services', message: e.message, backtrace: e.backtrace.first)
|
215
|
+
# end
|
216
|
+
|
217
|
+
# def gitlab_version
|
218
|
+
# [
|
219
|
+
# title('Version'),
|
220
|
+
# gitlab_manifest.data.build_version
|
221
|
+
# ].join
|
222
|
+
# end
|
223
|
+
|
224
|
+
# def hostname
|
225
|
+
# [
|
226
|
+
# title('Hostname'),
|
227
|
+
# host.data.first
|
228
|
+
# ].join
|
229
|
+
# end
|
230
|
+
|
231
|
+
# def distro
|
232
|
+
# [
|
233
|
+
# title('Distro'),
|
234
|
+
# "[#{os_release.data.ID}] ".pastel(:bright_black),
|
235
|
+
# os_release.data.PRETTY_NAME
|
236
|
+
# ].join
|
237
|
+
# end
|
238
|
+
|
239
|
+
# def selinux
|
240
|
+
# return nil if selinux_status.data.nil?
|
241
|
+
|
242
|
+
# status = selinux_status.data['SELinux status']
|
243
|
+
# status_color = status == 'enabled' ? :green : :red
|
244
|
+
|
245
|
+
# [
|
246
|
+
# title('SeLinux'),
|
247
|
+
# status.pastel(status_color),
|
248
|
+
# ' (',
|
249
|
+
# selinux_status.data['Current mode'],
|
250
|
+
# ')'
|
251
|
+
# ].join
|
252
|
+
# end
|
253
|
+
|
254
|
+
# def arch
|
255
|
+
# [
|
256
|
+
# title('Arch'),
|
257
|
+
# cpu.data.Architecture
|
258
|
+
# ].join
|
259
|
+
# end
|
260
|
+
|
261
|
+
# def kernel
|
262
|
+
# # TODO: Better way to consistently get uname info?
|
263
|
+
# value, build = uname.data.first.split[2].split('-')
|
264
|
+
# [
|
265
|
+
# title('Kernel'),
|
266
|
+
# value,
|
267
|
+
# " (#{build})".pastel(:bright_black)
|
268
|
+
# ].join
|
269
|
+
# end
|
270
|
+
|
271
|
+
# # Helper for finding if NTP is enabled
|
272
|
+
# def ntp_keys
|
273
|
+
# [
|
274
|
+
# 'Network time on', 'NTP enabled', 'NTP service', 'System clock synchronized'
|
275
|
+
# ]
|
276
|
+
# end
|
277
|
+
|
278
|
+
# def sys_time
|
279
|
+
# # Ignore if Empty
|
280
|
+
# return false if timedatectl.data.nil?
|
281
|
+
|
282
|
+
# ntp_statuses = timedatectl.data.slice(*ntp_keys).values.compact
|
283
|
+
|
284
|
+
# enabled = %w[active yes] & ntp_statuses
|
285
|
+
# ntp_status = ntp_statuses.first
|
286
|
+
# ntp_color = enabled.empty? ? :red : :green
|
287
|
+
|
288
|
+
# # Fall Back
|
289
|
+
# ntp_status ||= 'unknown'
|
290
|
+
|
291
|
+
# [
|
292
|
+
# title('Sys Time'),
|
293
|
+
# timedatectl.data['Local time'],
|
294
|
+
# ' (ntp: '.pastel(:bright_black),
|
295
|
+
# ntp_status.pastel(ntp_color),
|
296
|
+
# ')'.pastel(:bright_black)
|
297
|
+
# ].join
|
298
|
+
# end
|
299
|
+
|
300
|
+
# # Strip/Simplify Uptime
|
301
|
+
# def sys_uptime
|
302
|
+
# init = uptime.data.first.split(', load average').first.strip
|
303
|
+
|
304
|
+
# [
|
305
|
+
# title('Uptime'),
|
306
|
+
# init.split('up ', 2).last
|
307
|
+
# ].join
|
308
|
+
# end
|
309
|
+
|
310
|
+
# def load_average
|
311
|
+
# cpu_count = cpu.data['CPU(s)'].to_i
|
312
|
+
# intervals = uptime.data.first.split('load average: ', 2).last.split(', ').map(&:to_f)
|
313
|
+
|
314
|
+
# # Generate Colorized Text for Output
|
315
|
+
# intervals_text = intervals.map do |interval|
|
316
|
+
# value = percent(interval, cpu_count)
|
317
|
+
# color = value > 100 ? :red : :green
|
318
|
+
# [
|
319
|
+
# interval,
|
320
|
+
# ' (',
|
321
|
+
# "#{value}%".pastel(color),
|
322
|
+
# ')'
|
323
|
+
# ].join
|
324
|
+
# end
|
325
|
+
|
326
|
+
# [
|
327
|
+
# title('LoadAvg'),
|
328
|
+
# "[CPU #{cpu_count}] ".pastel(:bright_white),
|
329
|
+
# intervals_text.join(', ')
|
330
|
+
# ].join
|
331
|
+
# end
|
332
|
+
|
333
|
+
# def memory_perc
|
334
|
+
# total = ShellHelper.human_size_to_number(meminfo.data['MemTotal'])
|
335
|
+
# free = ShellHelper.human_size_to_number(meminfo.data['MemFree'])
|
336
|
+
# used = percent((total - free), total)
|
337
|
+
|
338
|
+
# [
|
339
|
+
# title('Usage'),
|
340
|
+
# ' ['.pastel(:bright_black),
|
341
|
+
# '='.pastel(:green) * (used / 2),
|
342
|
+
# ' ' * (50 - (used / 2)),
|
343
|
+
# ']'.pastel(:bright_black),
|
344
|
+
# " #{100 - percent(free, total)}%".pastel(:green) # Inverse
|
345
|
+
# ].join
|
346
|
+
# end
|
347
|
+
|
348
|
+
# def memory_free
|
349
|
+
# free = free_m.data.find { |x| x.kind == 'Mem' }
|
350
|
+
|
351
|
+
# return unless free
|
352
|
+
|
353
|
+
# formatted_mem = free_m.data.map { |x| GreenHat::Memory.memory_row x }
|
354
|
+
|
355
|
+
# output = []
|
356
|
+
# unless free.total.blank?
|
357
|
+
# output << title('Total', :cyan, 14)
|
358
|
+
# output << number_to_human_size(free.total.to_i * (1024**2))
|
359
|
+
# output << "\n"
|
360
|
+
# end
|
361
|
+
|
362
|
+
# unless free.total.blank?
|
363
|
+
# output << title('Used', :yellow, 14)
|
364
|
+
# output << number_to_human_size(free.used.to_i * (1024**2))
|
365
|
+
# output << "\n"
|
366
|
+
# end
|
367
|
+
|
368
|
+
# unless free.total.blank?
|
369
|
+
# output << title('Free', :blue, 14)
|
370
|
+
# output << number_to_human_size(free.free.to_i * (1024**2))
|
371
|
+
# output << "\n"
|
372
|
+
# end
|
373
|
+
|
374
|
+
# unless free.total.blank?
|
375
|
+
# output << title('Available', :green, 14)
|
376
|
+
# output << number_to_human_size(free.available.to_i * (1024**2))
|
377
|
+
# output << "\n"
|
378
|
+
# end
|
379
|
+
|
380
|
+
# output << "\n"
|
381
|
+
# output << formatted_mem.map { |x| x.prepend ' ' * 2 }.join("\n")
|
382
|
+
|
383
|
+
# output.join
|
384
|
+
# rescue StandardError => e
|
385
|
+
# LogBot.fatal('Memory', message: e.message, backtrace: e.backtrace.first)
|
386
|
+
# end
|
387
|
+
|
388
|
+
# def disks
|
389
|
+
# # GreenHat::Disk.df({archive: []})
|
390
|
+
# file = GreenHat::Disk.df({ archive: [archive.name] })
|
391
|
+
|
392
|
+
# disk_list = GreenHat::Disk.format_output(file.first, false, 3)
|
393
|
+
|
394
|
+
# # Preapre / Indent List
|
395
|
+
# [
|
396
|
+
# 'Disks'.pastel(:bright_yellow) + ' (Top % Usage)'.pastel(:bright_black),
|
397
|
+
# "\n",
|
398
|
+
# disk_list.each { |x| x.prepend(' ' * 4) }.join("\n")
|
399
|
+
# ].join
|
400
|
+
# end
|
401
|
+
|
402
|
+
# # ----------------------------
|
403
|
+
# # Helpers
|
404
|
+
# # ----------------------------
|
405
|
+
# def percent(value, total)
|
406
|
+
# ((value / total.to_f) * 100).round
|
407
|
+
# end
|
408
|
+
|
409
|
+
# # Helper to Make Cyan Titles
|
410
|
+
# def title(name, color = :cyan, ljust = 12)
|
411
|
+
# " #{name}:".ljust(ljust).pastel(color)
|
412
|
+
# end
|
413
|
+
# end
|
414
|
+
# # rubocop:enable Metrics/ClassLength
|
415
|
+
# end
|