Module: GreenHat::Shell::Faststats
- Defined in:
- lib/greenhat/shell/faststats.rb
Overview
Logs
Class Method Summary collapse
-
.default(raw, _other = nil) ⇒ Object
Vanilla Fast Stats.
-
.errors(raw = [], internal = false) ⇒ Object
===== [ Fast Stats - Errors ] ==================== ========================================================================.
-
.faststats_installation ⇒ Object
rubocop:enable Metrics/MethodLength.
-
.help ⇒ Object
rubocop:disable Metrics/MethodLength.
-
.list(args = []) ⇒ Object
List Files Helpers.
- .ls(args = []) ⇒ Object
-
.top(raw = [], internal = false) ⇒ Object
===== [ Fast Stats - Top ] ==================== ————————————————- Options: –display, value,perc,both Show percentage of totals, actual durations, or both.
Class Method Details
.default(raw, _other = nil) ⇒ Object
Vanilla Fast Stats
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 |
# File 'lib/greenhat/shell/faststats.rb', line 117 def self.default(raw, _other = nil) unless TTY::Which.exist? 'fast-stats' faststats_installation return false end files, flags, cmd = ShellHelper::Faststats.parse(raw) LogBot.debug('FastStats CMD', cmd) if ENV['DEBUG'] # binding.pry # Ignore Unknown Errors results = ShellHelper.file_process(files) do |file| output = `fast-stats #{cmd} #{file.file} 2>&1` result = $CHILD_STATUS.success? next unless result [ file.friendly_name, output.split("\n"), "\n" ] end ShellHelper.show(results.compact.flatten, flags) end |
.errors(raw = [], internal = false) ⇒ Object
[ Fast Stats - Errors ] ====================
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 |
# File 'lib/greenhat/shell/faststats.rb', line 183 def self.errors(raw = [], internal = false) unless TTY::Which.exist? 'fast-stats' faststats_installation return false end # Add Color Output raw.push '--color-output' if Settings.settings.color? files, flags, cmd = ShellHelper::Faststats.parse(raw) LogBot.debug('FastStats CMD', cmd) if ENV['DEBUG'] results = ShellHelper.file_process(files) do |file| [ file.friendly_name, `fast-stats errors #{cmd} #{file.file}`.split("\n"), "\n" ] end # Quick exit for internal processing return results.flatten if internal ShellHelper.show(results.flatten, flags) end |
.faststats_installation ⇒ Object
rubocop:enable Metrics/MethodLength
70 71 72 73 74 75 |
# File 'lib/greenhat/shell/faststats.rb', line 70 def self.faststats_installation puts "#{'Unable to find'.pastel(:red)} #{'fast-stats'.pastel(:blue)}" puts ' Release Downloads here' puts ' - https://gitlab.com/gitlab-com/support/toolbox/fast-stats/-/releases'.pastel(:yellow) puts '' end |
.help ⇒ Object
rubocop:disable Metrics/MethodLength
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 |
# File 'lib/greenhat/shell/faststats.rb', line 7 def self.help puts "\u2500".pastel(:cyan) * 25 puts "Gimme #{'Performance Stats'.pastel(:yellow)}" puts "\u2500".pastel(:cyan) * 25 puts 'General'.pastel(:blue) puts " Any double dash arguments (e.g. #{'--color-output'.pastel(:green)}) are passed directly to fast-stats" puts " See #{'`fast-stats --help`'.pastel(:bright_black)} for all available options" puts puts 'Common Options'.pastel(:blue) puts ' --raw'.pastel(:green) puts ' Do not use less/paging' puts ' --search'.pastel(:green) puts ' Case-insensitive search of controller/method/worker field' puts ' --sort'.pastel(:green) puts ' count,fail,max,median,min,p95,p99,rps,score' puts ' --limit'.pastel(:green) puts ' The number of rows to print' puts ' --verbose'.pastel(:green) puts ' Prints the component details of the maximum, P99, P95, and median events by total duration for each' puts puts 'Commands'.pastel(:blue) puts 'ls'.pastel(:green) puts ' List available files' puts ' Options' puts ' -a, --all, show all files including source' puts puts '<file names+>'.pastel(:green) puts ' Print any file names' puts ' Ex: `gitaly/current`' puts ' Ex: `gitlab-rails/api_json.log gitlab-rails/production_json.log --raw`' puts puts 'top'.pastel(:green) puts ' Print a summary of top items in a category' puts puts 'errors'.pastel(:green) puts ' Show summary of errors captured in log' puts puts 'Examples'.pastel(:blue) puts ' Default'.pastel(:bright_white) puts ' gitaly/current' puts ' --raw gitlab-rails/production_json.log' puts ' gitlab-rails/api_json.log --sort=count' puts ' --search=pipeline sidekiq/current' puts puts ' Top'.pastel(:bright_white) puts ' top gitaly/current' puts ' top --limit=5 sidekiq/current' puts puts ' Errors'.pastel(:bright_white) puts ' errors gitaly/current' puts ' errors gitaly/current --no-border' end |
.list(args = []) ⇒ Object
List Files Helpers
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 |
# File 'lib/greenhat/shell/faststats.rb', line 78 def self.list(args = []) unless TTY::Which.exist? 'fast-stats' faststats_installation return false end all = false all = true if args.include?('-a') || args.include?('--all') files = ShellHelper::Faststats.things # Sort files.sort_by!(&:name) # Short & Uniq files.uniq!(&:name) unless all # Print files.each do |log| if all puts "- #{log.friendly_name}" else puts "- #{log.name.pastel(:yellow)}" end end return unless all puts "\n#{'Other / Unknown'.pastel(:red)}" (Thing.all - files).each do |file| puts "- #{file.name.pastel(:yellow)}" end end |
.ls(args = []) ⇒ Object
112 113 114 |
# File 'lib/greenhat/shell/faststats.rb', line 112 def self.ls(args = []) list(args) end |
.top(raw = [], internal = false) ⇒ Object
[ Fast Stats - Top ] ====================
Options: –display, value,perc,both
Show percentage of totals, actual durations, or both. Defaults to both.
–limit=X –sort=count,fail,max,median,min,p95,p99,rps,score
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/greenhat/shell/faststats.rb', line 155 def self.top(raw = [], internal = false) unless TTY::Which.exist? 'fast-stats' faststats_installation return false end files, flags, cmd = ShellHelper::Faststats.parse(raw) LogBot.debug('FastStats CMD', cmd) if ENV['DEBUG'] results = ShellHelper.file_process(files) do |file| [ file.friendly_name, `fast-stats top #{cmd} #{file.file}`.split("\n"), "\n" ] end # Quick exit for internal processing return results.flatten if internal ShellHelper.show(results.flatten, flags) end |