Module: Adminix::Helpers::Command
- Defined in:
- lib/adminix/helpers/command.rb
Class Method Summary collapse
- .darwin_cpu_load ⇒ Object
- .darwin_disk_usage ⇒ Object
- .darwin_memory_load ⇒ Object
- .debian_cpu_load ⇒ Object
- .debian_disk_usage ⇒ Object
- .debian_memory_load ⇒ Object
- .debian_temperature ⇒ Object
- .git_clone(repo, branch = 'master') ⇒ Object
- .home ⇒ Object
- .run_system_command(command) ⇒ Object
- .systemctl_enabled? ⇒ Boolean
- .which(arg1) ⇒ Object
- .whoami ⇒ Object
Instance Method Summary collapse
Class Method Details
.darwin_cpu_load ⇒ Object
50 51 52 |
# File 'lib/adminix/helpers/command.rb', line 50 def self.darwin_cpu_load `ps -A -o %cpu | awk '{s+=$1} END {print s}'`.to_f end |
.darwin_disk_usage ⇒ Object
66 67 68 69 70 |
# File 'lib/adminix/helpers/command.rb', line 66 def self.darwin_disk_usage output = `df -h | awk '$NF=="/"{printf "%d/%d", $3,$2,$5}'` used, disk_size = output.split('/') [used.to_f * 1024, disk_size.to_f * 1024] end |
.darwin_memory_load ⇒ Object
41 42 43 44 |
# File 'lib/adminix/helpers/command.rb', line 41 def self.darwin_memory_load output = `free -m | awk 'NR==2{printf "%s/%s", $3,$2,$3*100/$2 }'` output.split('/') end |
.debian_cpu_load ⇒ Object
46 47 48 |
# File 'lib/adminix/helpers/command.rb', line 46 def self.debian_cpu_load `top -bn1 | grep load | awk '{printf "%.2f\\\n", $(NF-2)}'`.to_f end |
.debian_disk_usage ⇒ Object
54 55 56 57 |
# File 'lib/adminix/helpers/command.rb', line 54 def self.debian_disk_usage output = `df -h | awk '$NF=="/"{printf "%d/%d\\\n", $3,$2,$5}'` output.split('/') end |
.debian_memory_load ⇒ Object
32 33 34 35 |
# File 'lib/adminix/helpers/command.rb', line 32 def self.debian_memory_load output = `free -m | awk 'NR==2{printf "%s/%s", $3,$2,$3*100/$2 }'` output.split('/') end |
.debian_temperature ⇒ Object
59 60 61 62 63 64 |
# File 'lib/adminix/helpers/command.rb', line 59 def self.debian_temperature output = `cat /sys/class/thermal/thermal_zone*/temp` temperatures = output.split("\n").map(&:to_i) return nil if temperatures.empty? temperatures.reduce(:+) / temperatures.size end |
.git_clone(repo, branch = 'master') ⇒ Object
19 20 21 22 |
# File 'lib/adminix/helpers/command.rb', line 19 def self.git_clone(repo, branch = 'master') bin = 'git' `#{bin} clone #{repo} -b #{branch}` end |
.home ⇒ Object
15 16 17 |
# File 'lib/adminix/helpers/command.rb', line 15 def self.home ENV['HOME'] end |
.run_system_command(command) ⇒ Object
28 29 30 |
# File 'lib/adminix/helpers/command.rb', line 28 def self.run_system_command(command) `#{command}` end |
.systemctl_enabled? ⇒ Boolean
37 38 39 |
# File 'lib/adminix/helpers/command.rb', line 37 def self.systemctl_enabled? !`which systemctl`.length.zero? end |
.which(arg1) ⇒ Object
4 5 6 7 8 |
# File 'lib/adminix/helpers/command.rb', line 4 def self.which(arg1) output = `which #{arg1}` output = output.split("\n")[0] output.empty? ? nil : output end |
.whoami ⇒ Object
10 11 12 13 |
# File 'lib/adminix/helpers/command.rb', line 10 def self.whoami output = `whoami` output.split("\n")[0] end |
Instance Method Details
#mkdir_p(dirname) ⇒ Object
24 25 26 |
# File 'lib/adminix/helpers/command.rb', line 24 def mkdir_p(dirname) `mkdir -p #{dirname}` end |