solaris_stats 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/solaris_stats.rb +80 -5
- data/lib/solaris_stats/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 121918f97ebf11117264378a9b1e92bd3cdb9d7f
|
4
|
+
data.tar.gz: 4212dfc1476c32fe981269ce36664816d25cb418
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e656f04deb60f9c339783cd717adfb8d2534663459e6fb323959b9464614b5bc4dec2a137989e0ed99e6ad0ed8d02084c50f61149746d60186427ab6fd3c736b
|
7
|
+
data.tar.gz: d7668c0b2168a9a157e9f46b7ccf2c3c12d67a854aaa1a8daf52db35214d786ce1e01b3152142ea9156a7a1a0730a7a9f20641437670ac257c49c94ad7aa621e
|
data/Gemfile
CHANGED
data/lib/solaris_stats.rb
CHANGED
@@ -1,9 +1,84 @@
|
|
1
1
|
require 'vmstat'
|
2
|
+
require 'sensu-plugin/metric/cli'
|
3
|
+
require 'socket'
|
2
4
|
require "solaris_stats/version"
|
3
5
|
|
4
|
-
module SolarisStats
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
module SolarisStats
|
7
|
+
def self.snapshot
|
8
|
+
Vmstat.snapshot
|
9
|
+
end
|
10
|
+
|
11
|
+
class DiskUsageMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
12
|
+
option :scheme,
|
13
|
+
description: 'Metric naming scheme, text to prepend to .$parent.$child',
|
14
|
+
long: '--scheme SCHEME',
|
15
|
+
default: "#{Socket.gethostname}.disk_usage"
|
16
|
+
|
17
|
+
option :ignore_mnt,
|
18
|
+
description: 'Ignore mounts matching pattern(s)',
|
19
|
+
short: '-i MNT[,MNT]',
|
20
|
+
long: '--ignore-mount',
|
21
|
+
proc: proc { |a| a.split(',') }
|
22
|
+
|
23
|
+
option :include_mnt,
|
24
|
+
description: 'Include only mounts matching pattern(s)',
|
25
|
+
short: '-I MNT[,MNT]',
|
26
|
+
long: '--include-mount',
|
27
|
+
proc: proc { |a| a.split(',') }
|
28
|
+
|
29
|
+
option :flatten,
|
30
|
+
description: 'Output mounts with underscore rather than dot',
|
31
|
+
short: '-f',
|
32
|
+
long: '--flatten',
|
33
|
+
boolean: true,
|
34
|
+
default: false
|
35
|
+
|
36
|
+
option :local,
|
37
|
+
description: 'Only check local filesystems (df -l option)',
|
38
|
+
short: '-l',
|
39
|
+
long: '--local',
|
40
|
+
boolean: true,
|
41
|
+
default: false
|
42
|
+
|
43
|
+
option :block_size,
|
44
|
+
description: 'Set block size for sizes printed',
|
45
|
+
short: '-B BLOCK_SIZE',
|
46
|
+
long: '--block-size BLOCK_SIZE',
|
47
|
+
default: 'M'
|
48
|
+
|
49
|
+
# Main function
|
50
|
+
#
|
51
|
+
def run
|
52
|
+
delim = config[:flatten] == true ? '_' : '.'
|
53
|
+
# Get disk usage from df with used and avail in megabytes
|
54
|
+
# #YELLOW
|
55
|
+
command = if Gem::Platform.local.os == 'solaris'
|
56
|
+
"df -k #{config[:local] ? '-l' : ''}"
|
57
|
+
else
|
58
|
+
"df -PB#{config[:block_size]} #{config[:local] ? '-l' : ''}"
|
59
|
+
end
|
60
|
+
|
61
|
+
`#{command}`.split("\n").drop(1).each do |line|
|
62
|
+
_, _, used, avail, used_p, mnt = line.split
|
63
|
+
|
64
|
+
unless %r{/sys[/|$]|/dev[/|$]|/run[/|$]} =~ mnt
|
65
|
+
next if config[:ignore_mnt] && config[:ignore_mnt].find { |x| mnt.match(x) }
|
66
|
+
next if config[:include_mnt] && !config[:include_mnt].find { |x| mnt.match(x) }
|
67
|
+
mnt = if config[:flatten]
|
68
|
+
mnt.eql?('/') ? 'root' : mnt.gsub(/^\//, '')
|
69
|
+
else
|
70
|
+
# If mnt is only / replace that with root if its /tmp/foo
|
71
|
+
# replace first occurance of / with root.
|
72
|
+
mnt.length == 1 ? 'root' : mnt.gsub(/^\//, 'root.')
|
73
|
+
end
|
74
|
+
# Fix subsequent slashes
|
75
|
+
mnt = mnt.gsub '/', delim
|
76
|
+
output [config[:scheme], mnt, 'used'].join('.'), used.gsub(config[:block_size], '')
|
77
|
+
output [config[:scheme], mnt, 'avail'].join('.'), avail.gsub(config[:block_size], '')
|
78
|
+
output [config[:scheme], mnt, 'used_percentage'].join('.'), used_p.delete('%')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
ok
|
82
|
+
end
|
83
|
+
end
|
9
84
|
end
|