Class: ServerStatus::StatusCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/server-status/status_command.rb

Constant Summary collapse

SEPARATOR =
'###'

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ StatusCommand

Returns a new instance of StatusCommand.



6
7
8
9
# File 'lib/server-status/status_command.rb', line 6

def initialize(options)
  @options = options
  @parts   = []
end

Instance Method Details

#requested_optionsObject



11
12
13
# File 'lib/server-status/status_command.rb', line 11

def requested_options
  @requested_options ||= @options.__hash__.select { |k,v| k if v }.keys
end

#to_scriptObject



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
# File 'lib/server-status/status_command.rb', line 15

def to_script
  if @options.os
    @parts << "lsb_release -d | cut -f2"
  end

  if @options.uptime
    @parts << "cat /proc/uptime | cut -d\" \" -f1"
  end

  if @options.load
    @parts << "cat /proc/loadavg | cut -d\" \" -f -3"
  end

  if @options.disk_usage
    @parts << "df -h | awk '/\\/$/' | sed 's/ \\+/ /g' | cut -d\" \" -f5"
  end

  if @options.inode_usage
    @parts << "df -hi | awk '/\\/$/' | sed 's/ \\+/ /g' | cut -d\" \" -f5"
  end

  if @options.memory_usage
    @parts << "free -m | sed -n 3p | sed 's/ \\+/ /g' | cut -d\" \" -f 3-"
  end

  if @options.package_updates
    @parts << "cat /var/lib/update-notifier/updates-available 2>/dev/null"
  end

  if @options.reboot_required
    @parts << "if [ -f /var/run/reboot-required ]; then echo 1 ; fi"
  end

  @parts.join("\necho '#{SEPARATOR}'\n")
end