module GreenHat::Shell
Root Level Shell
CLI Helper
CLI Helper
CLI Helper
CLI Helper
Root Level Shell
/ Splitting Help into its own file
CLI Helper
CLI Helper
CLI Helper
CLI Helper
Public Class Methods
about()
click to toggle source
# File lib/greenhat/shell/help.rb, line 52 def self.about puts "\u2500".pastel(:cyan) * 20 puts "About GreenHat #{GreenHat::VERSION}".pastel(:yellow) puts "\u2500".pastel(:cyan) * 20 puts 'TLDR; Put in SOS reports, run commands, and find stuffs'.pastel(:green) puts puts <<~BLOCK General overview (OS, Memory, Disk, GitLab) #{'report'.pastel(:bright_cyan)} Log Searching #{'log filter sidekiq/current --job_status=done --sort=duration_s,db_duration_s --slice=duration_s,db_duration_s --reverse'.pastel(:bright_cyan)} Read File(s) across SOS archives #{'cat uptime'.pastel(:bright_cyan)} or #{'cat mount etc/fstab'.pastel(:bright_cyan)} BLOCK puts 'What it does / How it works'.pastel(:blue) puts puts <<~BLOCK GreenHat is a support utility to enhance troubleshooting with GitLabSOS Reports and log files. Make it easy to find stuff Supplied input files are staged, unpacked, identified, and normalized. This enables other utilities to automatically find and present data. (Faststats, report, and etc) BLOCK puts 'Commands and Submodules'.pastel(:blue) puts puts <<~BLOCK Greenhat is broken down into different "modules". Each module has its own commands. For example: log, cat, and faststats. You can "cd" into or execute commands directly against with their names. - Direct: #{'log filter sidekiq/current'.pastel(:cyan)} - Or within: First #{'log'.pastel(:cyan)}, then #{'filter sidekiq/current'.pastel(:cyan)} You can find the list of commands and submodules of each with #{'help'.pastel(:yellow)} BLOCK end
cli_shortcuts()
click to toggle source
rubocop:enable Layout/LineLength
# File lib/greenhat/shell/help.rb, line 35 def self.cli_shortcuts puts "\u2500".pastel(:cyan) * 25 puts 'Nav / Keyboard Shortcuts'.pastel(:blue) puts "\u2500".pastel(:cyan) * 25 puts <<~BLOCK | Hotkey | Description | | ------------------- | ----------------------- | | Ctrl + U | Clear Input | | Ctrl + A | Go to beginning | | Ctrl + E | Go to End | | Ctrl + Left/Right | Move left/right by word | | Ctrl + D, Ctrl + Z | Exit | | Ctrl + C, Shift Tab | Up one module | BLOCK puts end
debug()
click to toggle source
# File lib/greenhat/shell.rb, line 45 def self.debug ENV['DEBUG'] = if ENV['DEBUG'] puts "GreenHat Debug Logging #{'Off'.pastel(:red)}" nil else puts "GreenHat Debug Logging #{'On'.pastel(:green)}" 'true' end end
df()
click to toggle source
# File lib/greenhat/shell.rb, line 10 def self.df Disk.df end
free()
click to toggle source
# File lib/greenhat/shell.rb, line 22 def self.free Memory.free end
help()
click to toggle source
rubocop:disable Layout/LineLength
# File lib/greenhat/shell/help.rb, line 5 def self.help puts 'Quickstart'.pastel(:blue) puts " Commands are organized by submodule: #{'log'.pastel(:blue)}, #{'cat'.pastel(:blue)}, #{'faststats'.pastel(:blue)}" puts " Use #{'help'.pastel(:bright_blue)} for available commands in each module" puts puts ' Example Commands' puts ' log filter sidekiq/current'.pastel(:yellow) puts ' disk free'.pastel(:yellow) puts puts 'Top Level Commands'.pastel(:blue) puts ' report'.pastel(:green) puts ' Show summary report of SOS Report. OS, CPU, Memory, Disk, and etc' puts puts ' ps,df,netstat,free,uptime,uname'.pastel(:green) puts ' Show common files from archives / Emulate terminal commands' puts puts ' Noisy Output'.pastel(:green) puts " Use #{'quiet'.pastel(:blue)} or to #{'debug'.pastel(:blue)} to toggle greenhat logging" puts cli_shortcuts puts "See #{'about'.pastel(:bright_blue)} for more details about GreenHat" end
history()
click to toggle source
# File lib/greenhat/shell.rb, line 83 def self.history Settings.cmd_history_clean.each_with_index do |line, i| puts "#{i.to_s.ljust(3).pastel(:magenta)} #{line}" end end
history_clear()
click to toggle source
# File lib/greenhat/shell.rb, line 79 def self.history_clear Settings.cmd_history_clear end
hostname()
click to toggle source
# File lib/greenhat/shell.rb, line 71 def self.hostname Shell::Cat.default ['hostname'] end
ll()
click to toggle source
# File lib/greenhat/shell.rb, line 93 def self.ll GreenHat::Cli.help(false) end
load_local()
click to toggle source
# File lib/greenhat/shell.rb, line 26 def self.load_local return false unless TTY::Prompt.new.yes?('Load local Omnibus GitLab Instance files?') archive_path = "#{$TMP}/#{Time.now.to_i}_local" Dir.mkdir(archive_path) # archive = Archive.new(name: 'local') archive = Archive.new(name: archive_path, path: archive_path) file_list = Dir['/var/log/gitlab/*/current'] + Dir['/var/log/gitlab/*/*.log'] file_list.each do |file| next if File.size(file).zero? puts "- Loading #{file.pastel(:green)}" archive.things_create(file: file).setup end end
ls()
click to toggle source
# File lib/greenhat/shell.rb, line 89 def self.ls GreenHat::Cli.help(false) end
netstat()
click to toggle source
# File lib/greenhat/shell.rb, line 18 def self.netstat Network.netstat end
pry()
click to toggle source
# File lib/greenhat/shell.rb, line 4 def self.pry # rubocop:disable Lint/Debugger binding.pry # rubocop:enable Lint/Debugger end
ps(raw = {})
click to toggle source
# File lib/greenhat/shell.rb, line 14 def self.ps(raw = {}) Process.ps raw end
quiet()
click to toggle source
# File lib/greenhat/shell.rb, line 55 def self.quiet Cli.quiet! if Cli.quiet puts "GreenHat Quiet Logging #{'Off'.pastel(:red)}" nil else puts "GreenHat Quiet Logging #{'On'.pastel(:green)}" 'true' end end
report(raw)
click to toggle source
# File lib/greenhat/shell/report.rb, line 4 def self.report(raw) args = { raw: raw.include?('--raw') } ShellHelper.show(Archive.all.map(&:report).map(&:show).flatten, args) end
uname()
click to toggle source
# File lib/greenhat/shell.rb, line 75 def self.uname Shell::Cat.default ['uname'] end
uptime()
click to toggle source
# File lib/greenhat/shell.rb, line 67 def self.uptime Shell::Cat.default ['uptime'] end
version()
click to toggle source
# File lib/greenhat/shell.rb, line 97 def self.version puts "#{'GreenHat'.pastel(:green)}: #{GreenHat::VERSION.pastel(:blue)}" puts ' - https://gitlab.com/gitlab-com/support/toolbox/greenhat'.pastel(:cyan) end