Module: WiotAgentHd

Defined in:
lib/wiot-agent-hd/cli.rb,
lib/wiot-agent-hd/metrics.rb,
lib/wiot-agent-hd/version.rb

Defined Under Namespace

Modules: CLI

Constant Summary collapse

VERSION =
'0.1.4'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.server_nameObject



35
36
37
38
# File 'lib/wiot-agent-hd/metrics.rb', line 35

def self.server_name
  ip = Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
  Socket.gethostname + '-' + ip
end

.unitObject



31
32
33
# File 'lib/wiot-agent-hd/metrics.rb', line 31

def self.unit
  'GB'
end

.valid_mount_type(mount) ⇒ Object



27
28
29
# File 'lib/wiot-agent-hd/metrics.rb', line 27

def self.valid_mount_type(mount)
  mount.mount_type == 'ext4'
end

Instance Method Details

#metricObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wiot-agent-hd/metrics.rb', line 7

def metric
  p 'Host name: ' + server_name
  Filesystem.mounts.each { |mount|
    next unless valid_mount_type mount

    stat = Filesystem.stat(mount.mount_point)

    metric = WiotSdk::Metric.new
    metric.add 'os', RbConfig::CONFIG['host_os']
    metric.add 'server_name', server_name
    metric.add 'partition', mount.name
    metric.add 'mount_point', mount.mount_point
    metric.add 'type', mount.mount_type
    metric.add 'total_space', stat.bytes_total.to_gb.to_s + unit
    metric.add 'free_space', stat.bytes_free.to_gb.to_s + unit
    metric.add 'unit', unit
    metric.add 'use_percet_space', stat.percent_used.round(2).to_s
  }
end