forked from FireHawkDigital/newrelic-inode-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
executable file
·33 lines (27 loc) · 935 Bytes
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env ruby
#
# This is an inode agent which monitors
# disk INode usage
#
require "rubygems"
require "bundler/setup"
require "newrelic_plugin"
start = `df -i`.gsub('map ', 'map.')
start = start.gsub('Mounted on', 'Mounted_On')
result = {}
disks = start.lines
headers = disks.shift()
headers = headers.split(/[ ]{1,}/)
disks.each { |line|
line = line.split(/[ ]{1,}/)
mountedAt = line[headers.length-1].strip()
mountedFrom = line[0].strip().gsub(/^\/|\/$/, '')
result[mountedFrom] = {}
i = 0
headers.each { |header|
header = header.gsub(/^%/, 'pct.').gsub(/%$/, '.pct').gsub(/%/, '.pct.').strip()
result[mountedFrom][header] = line[i].strip().gsub('%', '').strip().gsub(/^\/|\/$/, '')
i += 1
}
}
puts result.to_json