greenhat 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abf4296d91fa1a63e0858e1a1ee0bc461668a6839d7ffb7ab6fbaeadae035dc1
4
- data.tar.gz: c7134e262cabb6c1873dc92e56ca6318cef9c64abb4573646228ee52c36be60e
3
+ metadata.gz: 2bdaa3adc8b035c2b528472f1176e8104e75e369c0191926f2277a69170759b5
4
+ data.tar.gz: 9d5d1811e7efe201a93a2385ec08bb5f280adbf0e00b3e02dc70eab4d6fafe47
5
5
  SHA512:
6
- metadata.gz: 6ea40f3c0fc24c35722631e61ad489bd1b9eabd2d6453669e2b56476a5e1c4c883d181d062794023555598da608a69615d4f10f0bfd0c8a75bccf6e0faed8189
7
- data.tar.gz: 9b947cdfc641164da1ed4d76df4e9739a01ad29a8120bc3485a534b7a0274beb3965c07dc275004e0a3320341844a00031b480e984835e91610edf77b70bf3e4
6
+ metadata.gz: 4bd0b3e175659ff78f984dea7cae51fcd3b5cce01171db9a74e6e77c0c3fd2b5bad48a2e52a8a0941674ed39858893a8035fe7f2582279752d07f25c0db06821
7
+ data.tar.gz: 35a342acfbea1e1dbcd70285f458cbed15822668fc06ae77a05ef8658667768be25560a1676bd3536bb2a80945bb9ea87d5b179aefc81c049ba4d951617b6f4f
@@ -6,12 +6,13 @@ module GreenHat
6
6
  class Builder
7
7
  include GreenHat::Reports::Shared
8
8
 
9
- attr_accessor :store, :flags, :args
9
+ attr_accessor :store, :flags, :args, :raw_args
10
10
 
11
- def initialize(file:, flags:, args:)
11
+ def initialize(file:, flags:, args:, raw_args:)
12
12
  self.store = []
13
13
  self.flags = flags
14
14
  self.args = args
15
+ self.raw_args = raw_args
15
16
  instance_eval File.read(file)
16
17
  rescue StandardError => e
17
18
  print "#{e.message}\n"
@@ -88,6 +89,10 @@ module GreenHat
88
89
  add(:query_format, query, show_output, block)
89
90
  end
90
91
 
92
+ def query_if_exists(query, show_output = true, &block)
93
+ add(:query_if_exists, query, show_output, block)
94
+ end
95
+
91
96
  # FastStats Helper
92
97
  def faststats(query, subcmd = '')
93
98
  add(:faststats, query, subcmd)
@@ -52,6 +52,10 @@ def query(query, show_output = true, &block)
52
52
  add(:query, query, show_output, block)
53
53
  end
54
54
 
55
+ def query_if_exists(query, show_output = true, &block)
56
+ add(:query_if_exists, query, show_output, block)
57
+ end
58
+
55
59
  # Log Query / Assume Format
56
60
  def query_format(query, show_output = true, &block)
57
61
  add(:query_format, query, show_output, block)
@@ -37,6 +37,28 @@ module GreenHat
37
37
  instance_exec(&block)
38
38
  end
39
39
 
40
+ # Log Query Ignore if no Files
41
+ def query_if_exists(query, show_output, block)
42
+ files, query_flags, query_args = GreenHat::Args.parse(Shellwords.split(query))
43
+
44
+ query_flags[:archive] = [archive.name] # Limit query to archive
45
+ query_flags[:combine] = true
46
+
47
+ # Default to everything
48
+ files = archive.things if files.empty?
49
+
50
+ # Ignore if no files are found
51
+ return unless ShellHelper.any_things?(files, query_flags)
52
+
53
+ results = Query.start(files, query_flags, query_args)
54
+
55
+ # Print and Exit of No Block / Show
56
+ return show(results) if block.nil? && show_output
57
+
58
+ output = instance_exec(results, &block)
59
+ show output if show_output
60
+ end
61
+
40
62
  # Log Query
41
63
  def query(query, show_output, block)
42
64
  files, query_flags, query_args = GreenHat::Args.parse(Shellwords.split(query))
@@ -29,6 +29,7 @@ entries = [
29
29
 
30
30
  # Filter Logic
31
31
  filters = args_select(:filter)
32
+
32
33
  unless filters.empty?
33
34
  entries.select! do |entry|
34
35
  filters.any? do |filter|
@@ -37,6 +38,17 @@ unless filters.empty?
37
38
  end
38
39
  end
39
40
 
41
+ # Fuzzy Filter Match
42
+ unless raw_args.empty?
43
+ entries.select! do |entry|
44
+ # Create a pattern with the file and title
45
+ globby = [entry.header.downcase, entry.base.split(' ', 2).first].join(' ')
46
+
47
+ # Check any Matches
48
+ raw_args.any? { |x| globby.include? x }
49
+ end
50
+ end
51
+
40
52
  # Return output
41
53
  entries.each do |entry|
42
54
  query_string = flags[:verbose] ? entry.base : entry.base + " --stats=#{entry.stats}"
@@ -114,37 +114,43 @@ end
114
114
  br
115
115
  puts indent('Errors'.pastel(:cyan))
116
116
 
117
- query 'gitlab-rails/production_json.log --status=500' do |data|
117
+ query_if_exists 'gitlab-rails/production_json.log --status=500' do |data|
118
118
  color = data.count.zero? ? :green : :red
119
119
  indent("#{ljust('Production:', 14, :magenta)} #{data.count.to_s.pastel(color)}", 4)
120
120
  end
121
121
 
122
- query 'gitlab-rails/application_json.log --message!="Cannot obtain an exclusive lease" --severity=error' do |data|
122
+ app_query = 'gitlab-rails/application_json.log --message!="Cannot obtain an exclusive lease" --severity=error'
123
+ query_if_exists app_query do |data|
123
124
  color = data.count.zero? ? :green : :red
124
125
  indent("#{ljust('Application:', 14, :magenta)} #{data.count.to_s.pastel(color)}", 4)
125
126
  end
126
127
 
127
- query 'sidekiq/current --severity=error' do |data|
128
+ query_if_exists 'sidekiq/current --severity=error' do |data|
128
129
  color = data.count.zero? ? :green : :red
129
130
  indent("#{ljust('Sidekiq:', 14, :magenta)} #{data.count.to_s.pastel(color)}", 4)
130
131
  end
131
132
 
132
- query 'gitlab-rails/api_json.log --status=500' do |data|
133
+ query_if_exists 'gitlab-rails/api_json.log --status=500' do |data|
133
134
  color = data.count.zero? ? :green : :red
134
135
  indent("#{ljust('API:', 14, :magenta)} #{data.count.to_s.pastel(color)}", 4)
135
136
  end
136
137
 
137
- query 'gitaly/current --level=error' do |data|
138
+ query_if_exists 'gitaly/current --level=error' do |data|
138
139
  color = data.count.zero? ? :green : :red
139
140
  indent("#{ljust('Gitaly:', 14, :magenta)} #{data.count.to_s.pastel(color)}", 4)
140
141
  end
141
142
 
142
- query 'gitlab-workhorse/current --level=error' do |data|
143
+ query_if_exists 'gitlab-workhorse/current --level=error' do |data|
143
144
  color = data.count.zero? ? :green : :red
144
145
  indent("#{ljust('Workhorse:', 14, :magenta)} #{data.count.to_s.pastel(color)}", 4)
145
146
  end
146
147
 
147
- query 'gitlab-rails/exceptions_json.log' do |data|
148
+ query_if_exists 'gitlab-rails/exceptions_json.log' do |data|
148
149
  color = data.count.zero? ? :green : :red
149
150
  indent("#{ljust('Exceptions:', 14, :magenta)} #{data.count.to_s.pastel(color)}", 4)
150
151
  end
152
+
153
+ query_if_exists('praefect/current --level=error') do |data|
154
+ color = data.count.zero? ? :green : :red
155
+ indent("#{ljust('Praefect:', 14, :magenta)} #{data.count.to_s.pastel(color)}", 4)
156
+ end
@@ -9,18 +9,19 @@ module GreenHat
9
9
 
10
10
  include InternalMethods
11
11
  include Shared
12
- attr_accessor :store, :archive, :flags, :args, :output
12
+ attr_accessor :store, :archive, :flags, :args, :raw_args, :output
13
13
 
14
14
  # Make Pry Easier
15
15
  def inspect
16
16
  "#<Runner archive: '#{archive}'>"
17
17
  end
18
18
 
19
- def initialize(archive:, store:, flags:, args:)
19
+ def initialize(archive:, store:, flags:, args:, raw_args:)
20
20
  self.store = store
21
21
  self.archive = archive
22
22
  self.flags = flags
23
23
  self.args = args
24
+ self.raw_args = raw_args
24
25
  self.output = []
25
26
 
26
27
  # Don't render paper new lines
@@ -31,6 +31,7 @@ module GreenHat
31
31
  def args_select(field)
32
32
  args.select { |x| x.field == field.to_sym }
33
33
  end
34
+
34
35
  # -=-=-=-=-=-
35
36
  end
36
37
  end
@@ -3,14 +3,15 @@ module GreenHat
3
3
  # Log Helpers
4
4
  module Reports
5
5
  # Make Running more consistent
6
- def self.run(file:, args:, flags:)
7
- report = GreenHat::Reports::Builder.new(file: file, args: args, flags: flags)
6
+ def self.run(file:, args:, flags:, raw_args:)
7
+ report = GreenHat::Reports::Builder.new(file: file, args: args, flags: flags, raw_args: raw_args)
8
8
  output = Archive.all.map do |archive|
9
9
  runner = GreenHat::Reports::Runner.new(
10
10
  archive: archive,
11
11
  store: report.store.clone,
12
12
  flags: flags,
13
- args: args
13
+ args: args,
14
+ raw_args: raw_args
14
15
  )
15
16
 
16
17
  runner.run!
@@ -12,12 +12,19 @@ module GreenHat
12
12
  end
13
13
 
14
14
  def self.open(url = 'http://localhost:4567/chart/time')
15
- cmd = if platform.linux? || platform.unix?
16
- 'xdg-open'
17
- elsif platform.mac?
15
+ cmd = if platform.mac?
18
16
  'open'
17
+ elsif platform.linux? || platform.unix?
18
+ 'xdg-open'
19
19
  end
20
20
 
21
+ # See if anything was detected -- ignore system call if nothing was
22
+ if cmd.nil?
23
+ puts "Unknown OS! #{RbConfig::CONFIG['arch']}"
24
+ puts url
25
+ return
26
+ end
27
+
21
28
  # platform.windows? # => false
22
29
  # platform.unix? # => true
23
30
  # platform.linux? # => false
@@ -47,7 +47,8 @@ module GreenHat
47
47
  run_list.uniq!
48
48
 
49
49
  run_list.each do |file|
50
- GreenHat::ShellHelper::Reports.run(file: file, args: args, flags: flags)
50
+ raw_args = list.reject { |x| file.include? x }
51
+ GreenHat::ShellHelper::Reports.run(file: file, args: args, flags: flags, raw_args: raw_args)
51
52
  end
52
53
  end
53
54
  end
@@ -331,6 +331,11 @@ module GreenHat
331
331
  @thing_list
332
332
  end
333
333
 
334
+ # Shortcut to see if any things exist
335
+ def self.any_things?(file_list, flags = {}, base_list = nil)
336
+ !find_things(file_list, flags, base_list).empty?
337
+ end
338
+
334
339
  # Shortcut find things
335
340
  def self.find_things(file_list, flags = {}, base_list = nil)
336
341
  base_list ||= Thing.all
@@ -18,18 +18,6 @@ module GreenHat
18
18
  module FileTypes
19
19
  def types
20
20
  {
21
- 'ifconfig' => {
22
- format: :raw,
23
- pattern: [
24
- /ifconfig/
25
- ]
26
- },
27
- 'ip_address' => {
28
- format: :raw,
29
- pattern: [
30
- /ip_address/
31
- ]
32
- },
33
21
  'cpuinfo' => {
34
22
  format: :raw,
35
23
  pattern: [
@@ -115,12 +103,6 @@ module GreenHat
115
103
  /getenforce/
116
104
  ]
117
105
  },
118
- 'gitlab.rb' => {
119
- format: :raw,
120
- pattern: [
121
- %r{gitlab/gitlab.rb}
122
- ]
123
- },
124
106
  'geo-logcursor/current' => {
125
107
  format: :raw,
126
108
  pattern: [
@@ -387,6 +369,18 @@ module GreenHat
387
369
  /hostname/
388
370
  ]
389
371
  },
372
+ 'ifconfig' => {
373
+ format: :raw,
374
+ pattern: [
375
+ /ifconfig/
376
+ ]
377
+ },
378
+ 'ip_address' => {
379
+ format: :raw,
380
+ pattern: [
381
+ /ip_address/
382
+ ]
383
+ },
390
384
  'lscpu' => {
391
385
  format: :colon_split_strip,
392
386
  pattern: [
@@ -539,6 +533,27 @@ module GreenHat
539
533
  /^ps/
540
534
  ]
541
535
  },
536
+ 'pressure_cpu.txt' => {
537
+ format: :raw,
538
+ log: false,
539
+ pattern: [
540
+ /pressure_cpu.txt/
541
+ ]
542
+ },
543
+ 'pressure_io.txt' => {
544
+ format: :raw,
545
+ log: false,
546
+ pattern: [
547
+ /pressure_io.txt/
548
+ ]
549
+ },
550
+ 'pressure_mem.txt' => {
551
+ format: :raw,
552
+ log: false,
553
+ pattern: [
554
+ /pressure_mem.txt/
555
+ ]
556
+ },
542
557
  'puma/puma_stderr.log' => {
543
558
  format: :raw,
544
559
  log: false,
@@ -547,6 +562,7 @@ module GreenHat
547
562
  %r{webservice.log/puma.stderr.log}
548
563
  ]
549
564
  },
565
+
550
566
  'puma/puma_stdout.log' => {
551
567
  format: :json,
552
568
  log: true,
@@ -725,12 +741,6 @@ module GreenHat
725
741
  %r{gitlab-rails/gitlab-rails-db-migrate.*}
726
742
  ]
727
743
  },
728
- 'rpm_verify' => {
729
- format: :raw,
730
- pattern: [
731
- /rpm_verify/
732
- ]
733
- },
734
744
  'tainted' => {
735
745
  format: :raw,
736
746
  pattern: [
@@ -856,18 +866,48 @@ module GreenHat
856
866
  /vmstat/
857
867
  ]
858
868
  },
869
+ 'gitlab-kas/config' => {
870
+ format: :raw,
871
+ pattern: [
872
+ %r{gitlab-kas/config}
873
+ ]
874
+ },
875
+ 'mailroom/config' => {
876
+ format: :raw,
877
+ pattern: [
878
+ %r{mailroom/config}
879
+ ]
880
+ },
859
881
  'iotop' => {
860
882
  format: :raw,
861
883
  pattern: [
862
884
  /iotop/
863
885
  ]
864
886
  },
887
+ 'top_res' => {
888
+ format: :raw,
889
+ pattern: [
890
+ /top_res/
891
+ ]
892
+ },
893
+ 'top_cpu' => {
894
+ format: :raw,
895
+ pattern: [
896
+ /top_cpu/
897
+ ]
898
+ },
865
899
  'ntpq' => {
866
900
  format: :raw,
867
901
  pattern: [
868
902
  /ntpq/
869
903
  ]
870
904
  },
905
+ 'rpm_verify' => {
906
+ format: :raw,
907
+ pattern: [
908
+ /rpm_verify/
909
+ ]
910
+ },
871
911
  'gitlab-rails/application.log' => {
872
912
  format: :raw,
873
913
  pattern: [
@@ -1,3 +1,3 @@
1
1
  module GreenHat
2
- VERSION = '0.6.3'.freeze
2
+ VERSION = '0.6.4'.freeze
3
3
  end
data/lib/greenhat.rb CHANGED
@@ -22,7 +22,7 @@ require 'tty-reader'
22
22
  require 'tty-spinner'
23
23
  require 'tty-table'
24
24
  require 'tty-which'
25
- require 'warning'
25
+ # require 'warning' # Ruby 3
26
26
  require 'ruby_native_statistics'
27
27
  require 'gitlab_chronic_duration'
28
28
 
@@ -79,4 +79,4 @@ require 'greenhat/tty/reader'
79
79
  require 'greenhat/tty/custom_line'
80
80
  require 'greenhat/tty/columns'
81
81
 
82
- Warning.ignore(/The table size exceeds the currently set width/)
82
+ # Warning.ignore(/The table size exceeds the currently set width/) # Ruby 3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greenhat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davin Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-01 00:00:00.000000000 Z
11
+ date: 2022-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.12'
89
+ version: '1.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.12'
96
+ version: '1.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: actionview
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '1.5'
145
+ version: '1.6'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '1.5'
152
+ version: '1.6'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: dotenv
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -234,6 +234,20 @@ dependencies:
234
234
  - - "~>"
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0.14'
237
+ - !ruby/object:Gem::Dependency
238
+ name: puma
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: '5.6'
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: '5.6'
237
251
  - !ruby/object:Gem::Dependency
238
252
  name: require_all
239
253
  requirement: !ruby/object:Gem::Requirement
@@ -276,6 +290,20 @@ dependencies:
276
290
  - - "~>"
277
291
  - !ruby/object:Gem::Version
278
292
  version: '1.6'
293
+ - !ruby/object:Gem::Dependency
294
+ name: sinatra
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - "~>"
298
+ - !ruby/object:Gem::Version
299
+ version: '2.2'
300
+ type: :runtime
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - "~>"
305
+ - !ruby/object:Gem::Version
306
+ version: '2.2'
279
307
  - !ruby/object:Gem::Dependency
280
308
  name: slim
281
309
  requirement: !ruby/object:Gem::Requirement
@@ -430,20 +458,6 @@ dependencies:
430
458
  - - "~>"
431
459
  - !ruby/object:Gem::Version
432
460
  version: '0.5'
433
- - !ruby/object:Gem::Dependency
434
- name: warning
435
- requirement: !ruby/object:Gem::Requirement
436
- requirements:
437
- - - "~>"
438
- - !ruby/object:Gem::Version
439
- version: '1.2'
440
- type: :runtime
441
- prerelease: false
442
- version_requirements: !ruby/object:Gem::Requirement
443
- requirements:
444
- - - "~>"
445
- - !ruby/object:Gem::Version
446
- version: '1.2'
447
461
  description: Experimental SOS and Log Parser for GitLab
448
462
  email:
449
463
  - dwalker@gitlab.com
@@ -590,14 +604,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
590
604
  requirements:
591
605
  - - ">="
592
606
  - !ruby/object:Gem::Version
593
- version: 3.0.0
607
+ version: 2.7.5
594
608
  required_rubygems_version: !ruby/object:Gem::Requirement
595
609
  requirements:
596
610
  - - ">="
597
611
  - !ruby/object:Gem::Version
598
612
  version: '0'
599
613
  requirements: []
600
- rubygems_version: 3.2.32
614
+ rubygems_version: 3.1.6
601
615
  signing_key:
602
616
  specification_version: 4
603
617
  summary: GitLab SOS Tool