-
-
Save AhmedKamal20/9ef8fd49814a840752898c0fe036123e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Prerequisite : | |
# - On local | |
# Ruby | |
# - On local | |
# Docker (Optional) | |
# iostat (Optional) | |
# Usage : | |
# ruby server.com username /path/to/.ssh/key | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'io-console', require: 'io/console' | |
gem 'net-ssh', require: 'net/ssh' | |
gem 'colorize', require: %w[colorize colorized_string] | |
end | |
DEFAULT_LINE_WIDTH = 100 | |
def screen_size() IO.console.winsize end | |
def screen_height() screen_size[0] end | |
def screen_width() [DEFAULT_LINE_WIDTH, screen_size[1]].min end | |
def line(size) '⎯' * size end | |
def header(s) puts "\n", (s.upcase + line(screen_width - s.length)).light_red end | |
def escape(s) s.gsub('$', '$$') end | |
def label(s, sep: ' ') print "#{s}:#{sep}".light_green end | |
def cmd(ssh, c) ssh.exec!(escape(c)) end | |
def run(ssh, c) puts cmd(ssh, c) end | |
def item(ssh, l, c, sep: ' ') label(l, sep: sep); run(ssh, c); end | |
ssh = Net::SSH.start(ARGV[0], ARGV[1], keys: ARGV[2]) | |
header 'Machine' | |
item ssh, 'Hostname', 'hostname' | |
item ssh, 'Date', 'date' | |
item ssh, 'Uptime', 'uptime -p' | |
header 'CPU' | |
item ssh, 'Processor', 'uname --processor' | |
item ssh, 'Utilization', 'iostat -h -c | sed -n "3,$p"', sep: "\n" | |
run ssh, 'lscpu' | |
header 'System' | |
item ssh, 'Kernel', 'uname --kernel-name' | |
item ssh, 'Node name', 'uname --nodename' | |
item ssh, 'Kernel release', 'uname --kernel-release' | |
item ssh, 'Kernel version', 'uname --kernel-version' | |
item ssh, 'Machine', 'uname --machine' | |
item ssh, 'Operating system', 'uname --operating-system' | |
header 'Memory' | |
item ssh, 'Disk space', 'df -hl --no-sync /', sep: "\n" | |
item ssh, 'RAM/SWAP', 'free -h --total', sep: "\n" | |
item ssh, 'Disk utilization', 'iostat -h -d | sed -n "3,$p"', sep: "\n" | |
header 'Docker' | |
run ssh, 'docker ps --format "table {{.Image}}\t{{.Status}}\t{{.Ports}}"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment