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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91107ea8bd32e262bb577f51a88eaac0a2121621
4
- data.tar.gz: 0733df74010c49d5f35e5b783c0c135f58f83414
3
+ metadata.gz: 121918f97ebf11117264378a9b1e92bd3cdb9d7f
4
+ data.tar.gz: 4212dfc1476c32fe981269ce36664816d25cb418
5
5
  SHA512:
6
- metadata.gz: 99b615ea983c15b19d1115dfc0925e463e082c8325eced7c001338ad65935ca7ae3979134eff6b5b3fb074d1068290c9b99c21c448c959b59a4855047ee78a15
7
- data.tar.gz: 577e6e14ee9a19760f6e9fcf7c262a596d3f8e3e6d00d5ca4cfe8916acff451da4e0a36600cef374bb29ee251be07f63c068fd4cddca51e85468be489d180d99
6
+ metadata.gz: e656f04deb60f9c339783cd717adfb8d2534663459e6fb323959b9464614b5bc4dec2a137989e0ed99e6ad0ed8d02084c50f61149746d60186427ab6fd3c736b
7
+ data.tar.gz: d7668c0b2168a9a157e9f46b7ccf2c3c12d67a854aaa1a8daf52db35214d786ce1e01b3152142ea9156a7a1a0730a7a9f20641437670ac257c49c94ad7aa621e
data/Gemfile CHANGED
@@ -3,3 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in solaris_stats.gemspec
4
4
  gemspec
5
5
  gem 'vmstat', '2.3.0'
6
+ gem 'sensu-plugin'
7
+
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
- def self.snapshot
6
- Vmstat.snapshot
7
- end
8
- # Your code goes here...
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
@@ -1,3 +1,3 @@
1
1
  module SolarisStats
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solaris_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - indermishra