sensu-plugins-disk-checks 0.0.1.alpha.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa3b81d298dd7521cb60c728ee9a27f4b100471e
4
+ data.tar.gz: 45087c070f23db20b7405de83871fa523319dc87
5
+ SHA512:
6
+ metadata.gz: 666ea2928769d72dbe5b0744a426f761f9e8d87a024c97b0953ef5772f965d71ebee51875c9ad77f5ebff6eff5b764c15093a074b00638da2b23baa72108d791
7
+ data.tar.gz: 886067b90da285a1ca28e1f4b76cdc0593fade73a7ba7ca38e5f2125104dc72fbee33c8808b591716346a3b9f15d3add270af5d03c1cb93bb76477c6a6e77c7a
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ )"}��D`�kiz{���z�uc���J�1�Kܒ��_ʛ�c"N�
2
+ ,���A�_�S�c�}��:d�^a����M�
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ #### 0.1.0-alpha.1
2
+
3
+ * baseline release identical to **sensu-community-plugins** repo
4
+ * basic yard coverage
5
+ * pinned dependencies
6
+ * built against 1.9.3, 2.0, 2.1
7
+ * cryptographically signed
8
+
9
+ #### 0.0.1-alpha.2
10
+
11
+ * bump Vagrant box to Cent 6.6
12
+ * update LICENSE and gemspec authors
13
+ * update README
14
+ * add required Ruby version *>= 1.9.3*
15
+ * add test/spec_help.rb
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 devops@yieldbot.com
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ ## Sensu-Plugins-disk-checks
2
+
3
+ [![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-disk-checks.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-disk-checks)
4
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-disk-checks.svg)](http://badge.fury.io/rb/sensu-plugins-disk-checks)
5
+ [![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-disk-checks/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-disk-checks)
6
+ [![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-disk-checks/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-disk-checks)
7
+
8
+ ## Functionality
9
+
10
+ **check-disk-fail**
11
+
12
+ Check the output of dmesg for a given set of strings that may correspond to a failure
13
+
14
+ **check-disk**
15
+
16
+ Check disk capacity and inodes based upon the output of df.
17
+
18
+ **check-fs-writeable**
19
+
20
+ Check to make sure a filesytem is writable. This will check both proc and do a smoke test of each given mountpoint. It can also auto-discover mount points in the self namespace.
21
+
22
+ **check-fstab-mounts**
23
+
24
+ Check the mount points in */etc/fstab* to ensure they are all accounted for.
25
+
26
+ **disk-capacity-metrics**
27
+
28
+ Acquire disk capacity metrics from `df` and convert them to a form usable by graphite
29
+
30
+ **disk-metrics**
31
+
32
+ Read */proc/iostats* for disk metrics and put them in a form usable by Graphite. See [iostats.txt](http://www.kernel.org/doc/Documentation/iostats.txt) for more details.
33
+
34
+ **disk-usage-metrics**
35
+
36
+ Based on disk-capacity-metrics.rb by bhenerey and nstielau. The difference here being how the key is defined in graphite and the size we emit to graphite(now using megabytes), inode info has also been dropped.
37
+
38
+
39
+ ## Files
40
+ * bin/check-disk-fail.rb
41
+ * bin/check-process-restart.rb
42
+ * bin/check-process.rb
43
+
44
+ ## Installation
45
+
46
+
47
+ Add the public key (if you haven’t already) as a trusted certificate
48
+
49
+ ```
50
+ gem cert --add <(curl -Ls https://raw.githubusercontent.com/sensu-plugins/sensu-plugins.github.io/master/certs/sensu-plugins.pem)
51
+ gem install <gem> -P MediumSecurity
52
+ ```
53
+
54
+ You can also download the key from /certs/ within each repository.
55
+
56
+ `gem install sensu-plugins-disk-checks`
57
+
58
+ Add *sensu-plugins-disk-checks* to your Gemfile, manifest, cookbook, etc
59
+
60
+ ## Notes
@@ -0,0 +1,49 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-disk-fail
4
+ #
5
+ # DESCRIPTION:
6
+ # Check for failing disks
7
+ # Greps through dmesg output looking for indications that a drive is failing.
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ #
20
+ # NOTES:
21
+ #
22
+ # LICENSE:
23
+ # Coppyright 07/14/2014 Shane Feek and Alan Smith.
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
25
+ # for details.
26
+ #
27
+
28
+ require 'sensu-plugin/check/cli'
29
+
30
+ #
31
+ # Check Disk Fail
32
+ #
33
+ class CheckDiskFail < Sensu::Plugin::Check::CLI
34
+ # Main function
35
+ #
36
+ # Check the contents of dmesg for a set of given strings
37
+ def run
38
+ dmesg = `dmesg`.lines
39
+
40
+ %w(Read Write Smart).each do |v|
41
+ found = dmesg.grep(/failed command\: #{v.upcase}/)
42
+ # #YELLOW
43
+ unless found.empty? # rubocop:disable IfUnlessModifier
44
+ critical "Disk #{v} Failure"
45
+ end
46
+ end
47
+ ok
48
+ end
49
+ end
data/bin/check-disk.rb ADDED
@@ -0,0 +1,157 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-disk
4
+ #
5
+ # DESCRIPTION:
6
+ # Uses GNU's -T option for listing filesystem type; unfortunately, this
7
+ # is not portable to BSD. Warning/critical levels are percentages only.
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ #
20
+ # NOTES:
21
+ #
22
+ # LICENSE:
23
+ # Copyright 2011 Sonian, Inc <chefs@sonian.net>
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
25
+ # for details.
26
+ #
27
+
28
+ require 'sensu-plugin/check/cli'
29
+
30
+ #
31
+ # Check Disk
32
+ #
33
+ class CheckDisk < Sensu::Plugin::Check::CLI
34
+ option :fstype,
35
+ short: '-t TYPE[,TYPE]',
36
+ description: 'Only check fs type(s)',
37
+ proc: proc { |a| a.split(',') }
38
+
39
+ option :ignoretype,
40
+ short: '-x TYPE[,TYPE]',
41
+ description: 'Ignore fs type(s)',
42
+ proc: proc { |a| a.split(',') }
43
+
44
+ option :ignoremnt,
45
+ short: '-i MNT[,MNT]',
46
+ description: 'Ignore mount point(s)',
47
+ proc: proc { |a| a.split(',') }
48
+
49
+ option :ignoreline,
50
+ short: '-l PATTERN[,PATTERN]',
51
+ description: 'Ignore df line(s) matching pattern(s)',
52
+ proc: proc { |a| a.split(',') }
53
+
54
+ option :includeline,
55
+ short: '-L PATTERN[,PATTERN]',
56
+ description: 'Only include df line(s) matching pattern(s)',
57
+ proc: proc { |a| a.split(',') }
58
+
59
+ option :warn,
60
+ short: '-w PERCENT',
61
+ description: 'Warn if PERCENT or more of disk full',
62
+ proc: proc(&:to_i),
63
+ default: 85
64
+
65
+ option :crit,
66
+ short: '-c PERCENT',
67
+ description: 'Critical if PERCENT or more of disk full',
68
+ proc: proc(&:to_i),
69
+ default: 95
70
+
71
+ option :iwarn,
72
+ short: '-W PERCENT',
73
+ description: 'Warn if PERCENT or more of inodes used',
74
+ proc: proc(&:to_i),
75
+ default: 85
76
+
77
+ option :icrit,
78
+ short: '-K PERCENT',
79
+ description: 'Critical if PERCENT or more of inodes used',
80
+ proc: proc(&:to_i),
81
+ default: 95
82
+
83
+ option :debug,
84
+ short: '-d',
85
+ long: '--debug',
86
+ description: 'Output list of included filesystems'
87
+
88
+ # Setup variables
89
+ #
90
+ def initialize
91
+ super
92
+ @crit_fs = []
93
+ @warn_fs = []
94
+ @line_count = 0
95
+ end
96
+
97
+ # Read the output of `df` spliting the lines based upon their fields
98
+ # This will check both blocks and inodes
99
+ def read_df
100
+ `df -lPT`.split("\n").drop(1).each do |line|
101
+ begin
102
+ _fs, type, _blocks, _used, _avail, capacity, mnt = line.split
103
+ next if config[:includeline] && !config[:includeline].find { |x| line.match(x) }
104
+ next if config[:fstype] && !config[:fstype].include?(type)
105
+ next if config[:ignoretype] && config[:ignoretype].include?(type)
106
+ next if config[:ignoremnt] && config[:ignoremnt].include?(mnt)
107
+ next if config[:ignoreline] && config[:ignoreline].find { |x| line.match(x) }
108
+ puts line if config[:debug]
109
+ rescue
110
+ unknown "malformed line from df: #{line}"
111
+ end
112
+ @line_count += 1
113
+ if capacity.to_i >= config[:crit]
114
+ @crit_fs << "#{mnt} #{capacity}"
115
+ elsif capacity.to_i >= config[:warn]
116
+ @warn_fs << "#{mnt} #{capacity}"
117
+ end
118
+ end
119
+
120
+ `df -lPTi`.split("\n").drop(1).each do |line|
121
+ begin
122
+ _fs, type, _inodes, _used, _avail, capacity, mnt = line.split
123
+ next if config[:includeline] && !config[:includeline].find { |x| line.match(x) }
124
+ next if config[:fstype] && !config[:fstype].include?(type)
125
+ next if config[:ignoretype] && config[:ignoretype].include?(type)
126
+ next if config[:ignoremnt] && config[:ignoremnt].include?(mnt)
127
+ next if config[:ignoreline] && config[:ignoreline].find { |x| line.match(x) }
128
+ puts line if config[:debug]
129
+ rescue
130
+ unknown "malformed line from df: #{line}"
131
+ end
132
+ @line_count += 1
133
+ if capacity.to_i > config[:icrit]
134
+ @crit_fs << "#{mnt} inodes #{capacity}"
135
+ elsif capacity.to_i >= config[:iwarn]
136
+ @warn_fs << "#{mnt} inodes #{capacity}"
137
+ end
138
+ end
139
+ end
140
+
141
+ # Generate output
142
+ #
143
+ def usage_summary
144
+ (@crit_fs + @warn_fs).join(', ')
145
+ end
146
+
147
+ # Main function
148
+ #
149
+ def run
150
+ unknown 'Do not use -l and -L options concurrently' if config[:includeline] && config[:ignoreline]
151
+ read_df
152
+ unknown 'No filesystems found' unless @line_count > 0
153
+ critical usage_summary unless @crit_fs.empty?
154
+ warning usage_summary unless @warn_fs.empty?
155
+ ok "All disk usage under #{config[:warn]}% and inode usage under #{config[:iwarn]}%"
156
+ end
157
+ end
@@ -0,0 +1,143 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-fs-writable
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks that a filesystem is writable. Useful for checking for stale NFS mounts.
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # all
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: rubysl-tempfile
17
+ #
18
+ # USAGE:
19
+ # ./check-fs-writable.rb --auto (check all volgroups in fstab)
20
+ # ./check-fs-writable.rb --dir /,/var,/usr,/home (check a defined list of directories)
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright 2014 Yieldbot, Inc <devops@yieldbot.com>
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugin/check/cli'
31
+ require 'tempfile'
32
+
33
+ #
34
+ # Check Filesystem Writable
35
+ #
36
+ class CheckFSWritable < Sensu::Plugin::Check::CLI
37
+ option :dir,
38
+ description: 'Directory to check for writability',
39
+ short: '-d DIRECTORY',
40
+ long: '--directory DIRECTORY',
41
+ proc: proc { |a| a.split(',') }
42
+
43
+ option :auto,
44
+ description: 'Auto discover mount points via fstab',
45
+ short: '-a',
46
+ long: '--auto-discover'
47
+
48
+ option :debug,
49
+ description: 'Print debug statements',
50
+ long: '--debug'
51
+
52
+ # Setup variables
53
+ #
54
+ def initialize
55
+ super
56
+ @crit_pt_proc = []
57
+ @crit_pt_test = []
58
+ end
59
+
60
+ # Generate output
61
+ #
62
+ def usage_summary
63
+ if @crit_pt_test.empty? && @crit_pt_proc.empty?
64
+ ok 'All filesystems are writable'
65
+ elsif @crit_pt_test || @crit_pt_proc
66
+ critical "The following file systems are not writeable: #{ @crit_pt_test }, #{@crit_pt_proc}"
67
+ end
68
+ end
69
+
70
+ # Get the mount points from the self namespace
71
+ #
72
+ def acquire_mnt_pts
73
+ `grep VolGroup /proc/self/mounts | awk '{print $2, $4}' | awk -F, '{print $1}' | awk '{print $1, $2}'`
74
+ end
75
+
76
+ # Does proc list the mount point as rw
77
+ #
78
+ def rw_in_proc?(mount_info)
79
+ mount_info.each do |pt|
80
+ @crit_pt_proc << "#{ pt.split[0] }" if pt.split[1] != 'rw'
81
+ end
82
+ end
83
+
84
+ # Create a tempfile at each mount point and attempt to write a line to it
85
+ # If it can't write the line, or the mount point does not exist it will
86
+ # generate a critical error
87
+ #
88
+ def rw_test?(mount_info)
89
+ mount_info.each do |pt|
90
+ (Dir.exist? pt.split[0]) || (@crit_pt_test << "#{ pt.split[0] }")
91
+ file = Tempfile.new('.sensu', pt.split[0])
92
+ puts "The temp file we are writing to is: #{ file.path }" if config[:debug]
93
+ # #YELLOW
94
+ # need to add a check here to validate permissions, if none it pukes
95
+ file.write('mops') || @crit_pt_test << "#{ pt.split[0] }"
96
+ file.read || @crit_pt_test << "#{ pt.split[0] }"
97
+ file.close
98
+ file.unlink
99
+ end
100
+ end
101
+
102
+ # Auto-generate a list of mount points to check based upon the self
103
+ # namespace in proc
104
+ #
105
+ def auto_discover
106
+ # #YELLOW
107
+ # this will only work for a single namespace as of now
108
+ mount_info = acquire_mnt_pts.split("\n")
109
+ warning 'No mount points found' if mount_info.length == 0
110
+ # #YELLOW
111
+ # I want to map this at some point to make it pretty and eaiser to read for large filesystems
112
+ puts 'This is a list of mount_pts and their current status: ', mount_info if config[:debug]
113
+ rw_in_proc?(mount_info)
114
+ rw_test?(mount_info)
115
+ puts "The critical mount points according to proc are: #{ @crit_pt_proc }" if config[:debug]
116
+ puts "The critical mount points according to actual testing are: #{ @crit_pt_test }" if config[:debug]
117
+ end
118
+
119
+ # Create a tempfile as each mount point and attempt to write a line to it
120
+ # If it can't write the line, or the mount point does not exist it will
121
+ # generate a critical error
122
+ #
123
+ def manual_test
124
+ config[:dir].each do |d|
125
+ (Dir.exist? d) || (@crit_pt_test << "#{ d }")
126
+ file = Tempfile.new('.sensu', d)
127
+ puts "The temp file we are writing to is: #{ file.path }" if config[:debug]
128
+ # #YELLOW
129
+ # need to add a check here to validate permissions, if none it pukes
130
+ file.write('mops') || @crit_pt_test << "#{ d }"
131
+ file.read || @crit_pt_test << "#{ d }"
132
+ file.close
133
+ file.unlink
134
+ end
135
+ end
136
+
137
+ # Main function
138
+ #
139
+ def run
140
+ (auto_discover if config[:auto]) || (manual_test if config[:dir]) || (warning 'No directorties to check')
141
+ usage_summary
142
+ end
143
+ end
@@ -0,0 +1,81 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-fstab-mounts
4
+ #
5
+ # DESCRIPTION:
6
+ # Check /etc/mtab to ensure all filesystems of the requested type(s) from
7
+ # fstab are currently mounted. If no fstypes are specified, will check all
8
+ # entries in fstab.
9
+ #
10
+ # OUTPUT:
11
+ # plain text
12
+ #
13
+ # PLATFORMS:
14
+ # Linux
15
+ #
16
+ # DEPENDENCIES:
17
+ # gem: sensu-plugin
18
+ # gem: pathname
19
+ #
20
+ # USAGE:
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Peter Fern <ruby@0xc0dedbad.com>
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugin/check/cli'
31
+ require 'pathname'
32
+
33
+ #
34
+ # Check Fstab Mounts
35
+ #
36
+ class CheckFstabMounts < Sensu::Plugin::Check::CLI
37
+ option :fstypes,
38
+ description: 'Filesystem types to check, comma-separated',
39
+ short: '-t TYPES',
40
+ long: '--types TYPES',
41
+ proc: proc { |a| a.split(',') },
42
+ required: false
43
+
44
+ # Setup variables
45
+ #
46
+ def initialize
47
+ super
48
+ @fstab = IO.readlines '/etc/fstab'
49
+ @mtab = IO.readlines '/etc/mtab'
50
+ @swap_mounts = IO.readlines '/proc/swaps'
51
+ @missing_mounts = []
52
+ end
53
+
54
+ # Check by mount destination (col 2 in fstab and proc/mounts)
55
+ #
56
+ def check_mounts
57
+ @fstab.each do |line|
58
+ next if line =~ /^\s*#/
59
+ next if line =~ /^\s*$/
60
+ fields = line.split(/\s+/)
61
+ next if fields[1] == 'none' || (fields[3].include? 'noauto')
62
+ next if config[:fstypes] && !config[:fstypes].include?(fields[2])
63
+ if fields[2] != 'swap'
64
+ @missing_mounts << fields[1] if @mtab.select { |m| m.split(/\s+/)[1] == fields[1] }.empty?
65
+ else
66
+ @missing_mounts << fields[1] if @swap_mounts.select { |m| m.split(/\s+/)[0] == Pathname.new(fields[0]).realpath.to_s }.empty?
67
+ end
68
+ end
69
+ end
70
+
71
+ # Main function
72
+ #
73
+ def run
74
+ check_mounts
75
+ if @missing_mounts.any?
76
+ critical "Mountpoint(s) #{@missing_mounts.join(',')} not mounted!"
77
+ else
78
+ ok 'All mountpoints accounted for'
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,114 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # disk-capacity-metrics
5
+ #
6
+ # DESCRIPTION:
7
+ # This plugin uses df to collect disk capacity metrics
8
+ # disk-metrics.rb looks at /proc/stat which doesnt hold capacity metricss.
9
+ # could have intetrated this into disk-metrics.rb, but thought I'd leave it up to
10
+ # whomever implements the checks.
11
+ #
12
+ # OUTPUT:
13
+ # metric data
14
+ #
15
+ # PLATFORMS:
16
+ # Linux
17
+ #
18
+ # DEPENDENCIES:
19
+ # gem: sensu-plugin
20
+ # gem: socket
21
+ #
22
+ # USAGE:
23
+ #
24
+ # NOTES:
25
+ #
26
+ # LICENSE:
27
+ # Copyright 2012 Sonian, Inc <chefs@sonian.net>
28
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
29
+ # for details.
30
+ #
31
+
32
+ require 'sensu-plugin/metric/cli'
33
+ require 'socket'
34
+
35
+ #
36
+ # Disk Capacity
37
+ #
38
+ class DiskCapacity < Sensu::Plugin::Metric::CLI::Graphite
39
+ option :scheme,
40
+ description: 'Metric naming scheme, text to prepend to .$parent.$child',
41
+ long: '--scheme SCHEME',
42
+ default: "#{Socket.gethostname}.disk"
43
+
44
+ # Unused ?
45
+ #
46
+ def convert_integers(values)
47
+ values.each_with_index do |value, index|
48
+ begin
49
+ converted = Integer(value)
50
+ values[index] = converted
51
+ # #YELLOW
52
+ rescue ArgumentError # rubocop:disable HandleExceptions
53
+ end
54
+ end
55
+ values
56
+ end
57
+
58
+ # Main function
59
+ #
60
+ def run
61
+ # Get capacity metrics from DF as they don't appear in /proc
62
+ `df -PT`.split("\n").drop(1).each do |line|
63
+ begin
64
+ fs, _type, _blocks, used, avail, capacity, _mnt = line.split
65
+
66
+ timestamp = Time.now.to_i
67
+ if fs.match('/dev')
68
+ fs = fs.gsub('/dev/', '')
69
+ metrics = {
70
+ disk: {
71
+ "#{fs}.used" => used,
72
+ "#{fs}.avail" => avail,
73
+ "#{fs}.capacity" => capacity.gsub('%', '')
74
+ }
75
+ }
76
+ metrics.each do |parent, children|
77
+ children.each do |child, value|
78
+ output [config[:scheme], parent, child].join('.'), value, timestamp
79
+ end
80
+ end
81
+ end
82
+ rescue
83
+ unknown "malformed line from df: #{line}"
84
+ end
85
+ end
86
+
87
+ # Get inode capacity metrics
88
+ `df -Pi`.split("\n").drop(1).each do |line|
89
+ begin
90
+ fs, _inodes, used, avail, capacity, _mnt = line.split
91
+
92
+ timestamp = Time.now.to_i
93
+ if fs.match('/dev')
94
+ fs = fs.gsub('/dev/', '')
95
+ metrics = {
96
+ disk: {
97
+ "#{fs}.iused" => used,
98
+ "#{fs}.iavail" => avail,
99
+ "#{fs}.icapacity" => capacity.gsub('%', '')
100
+ }
101
+ }
102
+ metrics.each do |parent, children|
103
+ children.each do |child, value|
104
+ output [config[:scheme], parent, child].join('.'), value, timestamp
105
+ end
106
+ end
107
+ end
108
+ rescue
109
+ unknown "malformed line from df: #{line}"
110
+ end
111
+ end
112
+ ok
113
+ end
114
+ end
@@ -0,0 +1,70 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # disk-metrics
5
+ #
6
+ # DESCRIPTION:
7
+ #
8
+ # OUTPUT:
9
+ # metric data
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: socket
17
+ #
18
+ # USAGE:
19
+ #
20
+ # NOTES:
21
+ #
22
+ # LICENSE:
23
+ # Copyright 2012 Sonian, Inc <chefs@sonian.net>
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
25
+ # for details.
26
+ #
27
+
28
+ require 'sensu-plugin/metric/cli'
29
+ require 'socket'
30
+
31
+ #
32
+ # Disk Graphite
33
+ #
34
+ class DiskGraphite < Sensu::Plugin::Metric::CLI::Graphite
35
+ option :scheme,
36
+ description: 'Metric naming scheme, text to prepend to metric',
37
+ short: '-s SCHEME',
38
+ long: '--scheme SCHEME',
39
+ default: "#{Socket.gethostname}.disk"
40
+
41
+ # this option uses lsblk to convert the dm-<whatever> name to the LVM name.
42
+ # sample metric scheme without this:
43
+ # <hostname>.disk.dm-0
44
+ # sample metric scheme with this:
45
+ # <hostname>.disk.vg-root
46
+ option :convert,
47
+ description: 'Convert devicemapper to logical volume name',
48
+ short: '-c',
49
+ long: '--convert',
50
+ default: false
51
+
52
+ # Main function
53
+ def run
54
+ # http://www.kernel.org/doc/Documentation/iostats.txt
55
+ metrics = %w(reads readsMerged sectorsRead readTime writes writesMerged sectorsWritten writeTime ioInProgress ioTime ioTimeWeighted)
56
+
57
+ File.open('/proc/diskstats', 'r').each_line do |line|
58
+ stats = line.strip.split(/\s+/)
59
+ _major, _minor, dev = stats.shift(3)
60
+ if config[:convert]
61
+ dev = `lsblk -P -o NAME /dev/"#{dev}"| cut -d\\" -f2`.lines.first.chomp! if dev =~ /^dm-.*$/
62
+ end
63
+ next if stats == ['0'].cycle.take(stats.size)
64
+
65
+ metrics.size.times { |i| output "#{config[:scheme]}.#{dev}.#{metrics[i]}", stats[i] }
66
+ end
67
+
68
+ ok
69
+ end
70
+ end
@@ -0,0 +1,121 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # disk-usage-metrics
5
+ #
6
+ # DESCRIPTION:
7
+ # This plugin uses df to collect disk capacity metrics
8
+ # disk-usage-metrics.rb looks at /proc/stat which doesnt hold capacity metricss.
9
+ #
10
+ # OUTPUT:
11
+ # metric data
12
+ #
13
+ # PLATFORMS:
14
+ # Linux
15
+ #
16
+ # DEPENDENCIES:
17
+ # gem: sensu-plugin
18
+ # gem: socket
19
+ #
20
+ # USAGE:
21
+ #
22
+ # NOTES:
23
+ # Based on disk-capacity-metrics.rb by bhenerey and nstielau
24
+ # The difference here being how the key is defined in graphite and the
25
+ # size we emit to graphite(now using megabytes). Also i dropped inode info.
26
+ # Using this as an example
27
+ # Filesystem Size Used Avail Use% Mounted on
28
+ # /dev/mapper/precise64-root 79G 3.5G 72G 5% /
29
+ # /dev/sda1 228M 25M 192M 12% /boot
30
+ # /dev/sdb1 99G 2G 97G 2% /media/sda1
31
+ # The keys with this plugin will be
32
+ # disk_usage.root, disk_usage.root.boot, and disk_usage.root.media.sda1
33
+ # instead of disk.dev.mapper.precise64-root, disk.sda1, and disk.sda2
34
+ #
35
+ # Use --flatten option to reduce graphite "tree" by using underscores rather
36
+ # then dots for subdirs. Also eliminates 'root' on mounts other than '/'.
37
+ # Keys with --flatten option would be
38
+ # disk_usage.root, disk_usage.boot, and disk_usage.media_sda1
39
+ #
40
+ # Mountpoints can be specifically included or ignored using -i or -I options:
41
+ # e.g. disk-usage-metric.rb -i ^/boot,^/media
42
+ #
43
+ # LICENSE:
44
+ # Copyright 2012 Sonian, Inc <chefs@sonian.net>
45
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
46
+ # for details.
47
+ #
48
+
49
+ require 'sensu-plugin/metric/cli'
50
+ require 'socket'
51
+
52
+ #
53
+ # Disk Usage Metrics
54
+ #
55
+ class DiskUsageMetrics < Sensu::Plugin::Metric::CLI::Graphite
56
+ option :scheme,
57
+ description: 'Metric naming scheme, text to prepend to .$parent.$child',
58
+ long: '--scheme SCHEME',
59
+ default: "#{Socket.gethostname}.disk_usage"
60
+
61
+ option :ignore_mnt,
62
+ description: 'Ignore mounts matching pattern(s)',
63
+ short: '-i MNT[,MNT]',
64
+ long: '--ignore-mount',
65
+ proc: proc { |a| a.split(',') }
66
+
67
+ option :include_mnt,
68
+ description: 'Include only mounts matching pattern(s)',
69
+ short: '-I MNT[,MNT]',
70
+ long: '--include-mount',
71
+ proc: proc { |a| a.split(',') }
72
+
73
+ option :flatten,
74
+ description: 'Output mounts with underscore rather than dot',
75
+ short: '-f',
76
+ long: '--flatten',
77
+ boolean: true,
78
+ default: false
79
+
80
+ option :local,
81
+ description: 'Only check local filesystems (df -l option)',
82
+ short: '-l',
83
+ long: '--local',
84
+ boolean: true,
85
+ default: false
86
+
87
+ option :block_size,
88
+ description: 'Set block size for sizes printed',
89
+ short: '-B BLOCK_SIZE',
90
+ long: '--block-size BLOCK_SIZE',
91
+ default: 'M'
92
+
93
+ # Main function
94
+ #
95
+ def run
96
+ delim = config[:flatten] == true ? '_' : '.'
97
+ # Get disk usage from df with used and avail in megabytes
98
+ # #YELLOW
99
+ `df -PB#{config[:block_size]} #{config[:local] ? '-l' : ''}`.split("\n").drop(1).each do |line| # rubocop:disable Style/Next
100
+ _, _, used, avail, used_p, mnt = line.split
101
+
102
+ unless %r{/sys|/dev|/run}.match(mnt)
103
+ next if config[:ignore_mnt] && config[:ignore_mnt].find { |x| mnt.match(x) }
104
+ next if config[:include_mnt] && !config[:include_mnt].find { |x| mnt.match(x) }
105
+ if config[:flatten]
106
+ mnt = mnt.eql?('/') ? 'root' : mnt.gsub(/^\//, '')
107
+ else
108
+ # If mnt is only / replace that with root if its /tmp/foo
109
+ # replace first occurance of / with root.
110
+ mnt = mnt.length == 1 ? 'root' : mnt.gsub(/^\//, 'root.')
111
+ end
112
+ # Fix subsequent slashes
113
+ mnt = mnt.gsub '/', delim
114
+ output [config[:scheme], mnt, 'used'].join('.'), used.gsub(config[:block_size], '')
115
+ output [config[:scheme], mnt, 'avail'].join('.'), avail.gsub(config[:block_size], '')
116
+ output [config[:scheme], mnt, 'used_percentage'].join('.'), used_p.gsub('%', '')
117
+ end
118
+ end
119
+ ok
120
+ end
121
+ end
@@ -0,0 +1,7 @@
1
+ #
2
+ # Set gem version
3
+ #
4
+ module SensuPluginsDiskChecks
5
+ # Gem version
6
+ VERSION = '0.0.1.alpha.2'
7
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-disk-checks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha.2
5
+ platform: ruby
6
+ authors:
7
+ - Yieldbot, Inc. and contributors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDgDCCAmigAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRIwEAYDVQQDDAltYXR0
14
+ am9uZXMxGDAWBgoJkiaJk/IsZAEZFgh5aWVsZGJvdDETMBEGCgmSJomT8ixkARkW
15
+ A2NvbTAeFw0xNTAxMjgyMTAyNTFaFw0xNjAxMjgyMTAyNTFaMEMxEjAQBgNVBAMM
16
+ CW1hdHRqb25lczEYMBYGCgmSJomT8ixkARkWCHlpZWxkYm90MRMwEQYKCZImiZPy
17
+ LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyTSzVYnO
18
+ CLgyrIyT1mBQakArQyW8xhi6MlDqyzXHJGeERT790U6EgoBVeS4XoK0ptFZNR8Tf
19
+ zko0w+Nv47TarSCgkPOaxY+mxWnAVR10dOmfeLr7huiMyps+YD56/EF2FqQ3jf/+
20
+ qohENfKD91qy1ieEy+Fn7Pf74ltbNKUdkb9a9eFXQ0DQ4ip5vik7DzjQkUTj4lca
21
+ k6ArwnmHX4YDhZoYtrQJ8jVktN0/+NtA40M5qkCYHNe5tUW25b/tKVYuioxG6b2Z
22
+ oIzaZxRLxf6HVAWpCVRT/F5+/yjigkX4u++eYacfLGleXQzoK7BL65vHGMJygWEE
23
+ 0TKGqFOrl/L0AQIDAQABo38wfTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
24
+ HQ4EFgQUEf6a8Td7MrSZc8ImbLFZAENPbz0wIQYDVR0RBBowGIEWbWF0dGpvbmVz
25
+ QHlpZWxkYm90LmNvbTAhBgNVHRIEGjAYgRZtYXR0am9uZXNAeWllbGRib3QuY29t
26
+ MA0GCSqGSIb3DQEBBQUAA4IBAQBbzXAYA3BVGw8DZ0YYoY1VHPNEcH5qPIApmHO8
27
+ rvSmuUT0yMEi7u00H/5uHRFf4LleGT/+sTdyXKsNPGT9kdRuQEgwi+vf7Zfvd8aX
28
+ UF/+4VkEYf/8rV8Ere6u2QaWPgApdMV6JjKr1fAwCTd8AuGXNaWItiPPMseSQzLJ
29
+ JKP4hVvbc1d+oS925B1lcBiqn2aYvElbyNAVmQPywNNqkWmvtlqj9ZVJfV5HQLdu
30
+ 8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
+ HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
+ -----END CERTIFICATE-----
33
+ date: 2015-02-01 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: sensu-plugin
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.1.0
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 1.1.0
49
+ - !ruby/object:Gem::Dependency
50
+ name: codeclimate-test-reporter
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rubocop
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.17.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 0.17.0
77
+ - !ruby/object:Gem::Dependency
78
+ name: rspec
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '3.1'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '3.1'
91
+ - !ruby/object:Gem::Dependency
92
+ name: bundler
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '1.7'
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: '1.7'
105
+ - !ruby/object:Gem::Dependency
106
+ name: rake
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '10.0'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: '10.0'
119
+ - !ruby/object:Gem::Dependency
120
+ name: github-markup
121
+ requirement: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ type: :development
127
+ prerelease: false
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ - !ruby/object:Gem::Dependency
134
+ name: redcarpet
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ - !ruby/object:Gem::Dependency
148
+ name: yard
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ description: Sensu disk checks
162
+ email: <sensu-users@googlegroups.com>
163
+ executables:
164
+ - check-disk-fail.rb
165
+ - check-disk.rb
166
+ - check-fs-writable.rb
167
+ - check-fstab-mounts.rb
168
+ - disk-capacity-metrics.rb
169
+ - disk-metrics.rb
170
+ - disk-usage-metrics.rb
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - bin/check-disk-fail.rb
175
+ - bin/check-disk.rb
176
+ - bin/check-fs-writable.rb
177
+ - bin/check-fstab-mounts.rb
178
+ - bin/disk-capacity-metrics.rb
179
+ - bin/disk-metrics.rb
180
+ - bin/disk-usage-metrics.rb
181
+ - lib/sensu-plugins-disk-checks.rb
182
+ - LICENSE
183
+ - README.md
184
+ - CHANGELOG.md
185
+ homepage: https://github.com/sensu-plugins/sensu-plugins-disk-checks
186
+ licenses:
187
+ - MIT
188
+ metadata: {}
189
+ post_install_message:
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - '>='
196
+ - !ruby/object:Gem::Version
197
+ version: 1.9.3
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - '>'
201
+ - !ruby/object:Gem::Version
202
+ version: 1.3.1
203
+ requirements: []
204
+ rubyforge_project:
205
+ rubygems_version: 2.0.14
206
+ signing_key:
207
+ specification_version: 4
208
+ summary: Sensu disk checks
209
+ test_files: []
210
+ has_rdoc:
metadata.gz.sig ADDED
Binary file