sensu-plugins-disk-checks 1.0.2 → 1.0.3

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: 2128f9ac86a11db57c3c29eb2108ed2e3c4b8989
4
- data.tar.gz: 991a1ca89514c39e1e893f04606c2863031cfb93
3
+ metadata.gz: 6928e842b69da0370f869cc6bb4ad23002b04730
4
+ data.tar.gz: 11046434136bfc5fb222777795accc7ab1965987
5
5
  SHA512:
6
- metadata.gz: 382cdbf84b139b3569dd86b5b78fa82aa5595559156fdb391de1a106ac4bbc6e6a216006f752a5fa3f23c3eb2057838a3bb22b443fd3fbbe52c469022c84bd42
7
- data.tar.gz: 206c818747e1fb194efbc0e70b11103e89686f32d99c4714d7778676da34d7030dcc552134e8939dea7f10d27e73e80d285892febbb7c328a15fc3c0a8ab28bc
6
+ metadata.gz: f19fd7cf5136f02b029069cc28e0f7c35121a4de6eeff1839d09b01b509feb6893a7d851dc69b3730514d087e42da95cc05ed211bf0a383619e8f34330f1b69c
7
+ data.tar.gz: 7c8657194de211450f0fb26555e52f19427aecb7e4d229a6120eaf835894f5d08045cc53f16ab409dbc9b8908d62a0c2bb6f5a5e7dedd5ebeaa0d17dccd2d891
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -6,6 +6,33 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
6
6
  ## [Unreleased][unreleased]
7
7
  - nothing
8
8
 
9
+ ## [1.0.3] - 2015-10-25
10
+ ### Changed
11
+ - Adds Ignore option(s) to check-disk-usage.rb
12
+ - Adaptive thresholds
13
+
14
+ ### Adaptive Thresholds
15
+
16
+ This borrows from check_mk's "df" check, which has the ability to
17
+ adaptively adjust thresholds for filesystems based on their sizes.
18
+
19
+ For example, a hard threshold of "warn at 85%" is quite different
20
+ between small filesystems and very large filesystems - 85% utilization
21
+ of a 20GB filesystem is arguably more serious than 85% utilization of a
22
+ 10TB filesystem.
23
+
24
+ This uses check_mk's original alorithm to optionally adjust the
25
+ percentage thresholds based on size, using a "magic factor", a
26
+ "normalized size", and a "minium size to adjust".
27
+
28
+ The magic factor defaults to '1.0', which will not adjust thresholds.
29
+ The minimum size defaults to '100' (GB). Filesystems smaller than this
30
+ will not be adapted.
31
+
32
+ check_mk's documentation has a lot more information on this, including
33
+ examples of adjustments based on the magic factor:
34
+ https://mathias-kettner.de/checkmk_filesystems.html
35
+
9
36
  ## [1.0.2] - 2015-08-04
10
37
  ### Changed
11
38
  - general cleanup
data/README.md CHANGED
@@ -20,6 +20,22 @@ Check disk capacity and inodes based upon the output of df.
20
20
 
21
21
  Check disk capacity and inodes based upon the gem sys-filesystem.
22
22
 
23
+ Can adjust thresholds for larger filesystems by providing a 'magic factor'
24
+ (`-m`). The default, `1.0`, will not adapt threshold percentages for volumes.
25
+
26
+ The `-l` option can be used in combination with the 'magic factor' to specify
27
+ the minimum size volume to adjust the thresholds for.
28
+
29
+ Refer to [check_mk's](https://mathias-kettner.de/checkmk_filesystems.html)
30
+ documentation on adaptive thresholds.
31
+
32
+ You can also visualize the adjustment using
33
+ [WolframAlpha]([https://www.wolframalpha.com/input/) with the following:
34
+
35
+ y = 100 - (100-P)*(N^(1-m))/(x^(1-m)), y = P for x in 0 to 1024
36
+
37
+ Where P = base percentage, N = normalize factor, and m = magic factor
38
+
23
39
  **check-fs-writeable**
24
40
 
25
41
  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.
@@ -48,6 +48,11 @@ class CheckDisk < Sensu::Plugin::Check::CLI
48
48
  description: 'Ignore mount point(s)',
49
49
  proc: proc { |a| a.split(',') }
50
50
 
51
+ option :ignoreopt,
52
+ short: '-o TYPE[.TYPE]',
53
+ description: 'Ignore option(s)',
54
+ proc: proc { |a| a.split('.') }
55
+
51
56
  option :bwarn,
52
57
  short: '-w PERCENT',
53
58
  description: 'Warn if PERCENT or more of disk full',
@@ -72,6 +77,26 @@ class CheckDisk < Sensu::Plugin::Check::CLI
72
77
  proc: proc(&:to_i),
73
78
  default: 95
74
79
 
80
+ option :magic,
81
+ short: '-m MAGIC',
82
+ description: 'Magic factor to adjust warn/crit thresholds. Example: .9',
83
+ proc: proc(&:to_f),
84
+ default: 1.0
85
+
86
+ option :normal,
87
+ short: '-n NORMAL',
88
+ description: 'Levels are not adapted for filesystems of excatly this '\
89
+ 'size, where levels are reduced for smaller filesystems and raised '\
90
+ 'for larger filesystems.',
91
+ proc: proc(&:to_f),
92
+ default: 20
93
+
94
+ option :minimum,
95
+ short: '-l MINIMUM',
96
+ description: 'Minimum size to adjust (in GB)',
97
+ proc: proc(&:to_f),
98
+ default: 100
99
+
75
100
  # Setup variables
76
101
  #
77
102
  def initialize
@@ -88,6 +113,7 @@ class CheckDisk < Sensu::Plugin::Check::CLI
88
113
  next if config[:fstype] && !config[:fstype].include?(line.mount_type)
89
114
  next if config[:ignoretype] && config[:ignoretype].include?(line.mount_type)
90
115
  next if config[:ignoremnt] && config[:ignoremnt].include?(line.mount_point)
116
+ next if config[:ignoreopt] && config[:ignoreopt].include?(line.options)
91
117
  rescue
92
118
  unknown 'An error occured getting the mount info'
93
119
  end
@@ -95,6 +121,15 @@ class CheckDisk < Sensu::Plugin::Check::CLI
95
121
  end
96
122
  end
97
123
 
124
+ # Adjust the percentages based on volume size
125
+ #
126
+ def adj_percent(size, percent)
127
+ hsize = (size / (1024.0 * 1024.0)) / config[:normal].to_f
128
+ felt = hsize**config[:magic]
129
+ scale = felt / hsize
130
+ 100 - ((100 - percent) * scale)
131
+ end
132
+
98
133
  def check_mount(line)
99
134
  fs_info = Filesystem.stat(line.mount_point)
100
135
  if fs_info.respond_to?(:inodes) # needed for windows
@@ -106,11 +141,34 @@ class CheckDisk < Sensu::Plugin::Check::CLI
106
141
  end
107
142
  end
108
143
  percent_b = percent_bytes(fs_info)
109
- if percent_b >= config[:bcrit]
110
- @crit_fs << "#{line.mount_point} #{percent_b}% bytes usage"
111
- elsif percent_b >= config[:bwarn]
112
- @warn_fs << "#{line.mount_point} #{percent_b}% bytes usage"
144
+
145
+ if fs_info.bytes_total < (config[:minimum] * 1_000_000_000)
146
+ bcrit = config[:bcrit]
147
+ bwarn = config[:bwarn]
148
+ else
149
+ bcrit = adj_percent(fs_info.bytes_total, config[:bcrit])
150
+ bwarn = adj_percent(fs_info.bytes_total, config[:bwarn])
151
+ end
152
+
153
+ used = to_human(fs_info.bytes_used)
154
+ total = to_human(fs_info.bytes_total)
155
+
156
+ if percent_b >= bcrit
157
+ @crit_fs << "#{line.mount_point} #{percent_b}% bytes usage (#{used}/#{total})"
158
+ elsif percent_b >= bwarn
159
+ @warn_fs << "#{line.mount_point} #{percent_b}% bytes usage (#{used}/#{total})"
160
+ end
161
+ end
162
+
163
+ def to_human(s)
164
+ prefix = %w(TiB GiB MiB KiB B)
165
+ s.to_f
166
+ i = prefix.length - 1
167
+ while s > 512 && i > 0
168
+ s /= 1024
169
+ i -= 1
113
170
  end
171
+ ((s > 9 || s.modulo(1) < 0.1 ? '%d' : '%.1f') % s) + ' ' + prefix[i]
114
172
  end
115
173
 
116
174
  # Determine the percent inode usage
@@ -119,7 +119,7 @@ class SmartCheckStatus < Sensu::Plugin::Check::CLI
119
119
 
120
120
  # Main function
121
121
  #
122
- def run # rubocop:disable all
122
+ def run
123
123
  @smart_attributes = JSON.parse(IO.read(File.dirname(__FILE__) + '/smart.json'), symbolize_names: true)[:smart][:attributes]
124
124
  @smart_debug = config[:debug] == 'on'
125
125
 
@@ -183,7 +183,7 @@ class SmartCheckStatus < Sensu::Plugin::Check::CLI
183
183
  end
184
184
 
185
185
  # #YELLOW
186
- output[dev].split("\n").each do |line| # rubocop:disable Style/Next
186
+ output[dev].split("\n").each do |line|
187
187
  fields = line.split
188
188
  if fields.size == 10 && fields[0].to_i != 0 && att_check_list.include?(fields[0].to_i)
189
189
  smart_att = @smart_attributes.find { |att| att[:id] == fields[0].to_i }
@@ -96,7 +96,7 @@ class DiskUsageMetrics < Sensu::Plugin::Metric::CLI::Graphite
96
96
  delim = config[:flatten] == true ? '_' : '.'
97
97
  # Get disk usage from df with used and avail in megabytes
98
98
  # #YELLOW
99
- `df -PB#{config[:block_size]} #{config[:local] ? '-l' : ''}`.split("\n").drop(1).each do |line| # rubocop:disable Style/Next
99
+ `df -PB#{config[:block_size]} #{config[:local] ? '-l' : ''}`.split("\n").drop(1).each do |line|
100
100
  _, _, used, avail, used_p, mnt = line.split
101
101
 
102
102
  unless %r{/sys|/dev|/run}.match(mnt)
@@ -2,7 +2,7 @@ module SensuPluginsDiskChecks
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- PATCH = 2
5
+ PATCH = 3
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-disk-checks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
@@ -30,7 +30,7 @@ cert_chain:
30
30
  8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
31
  HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
32
  -----END CERTIFICATE-----
33
- date: 2015-08-05 00:00:00.000000000 Z
33
+ date: 2015-10-25 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: filesystem
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- ���0s�s�E�b����O��7���)��r!_`�oGkiM;�q�f�NsJ��>v��%4s��!7�7��2s&�~��G�)ͺ��R� vjA*d��v�M�.��@B_,F-��4v쭃#��ES�T7u��N9re��}z�.�ViE��]�/+�;NZj���(�Qg-^��:��h��>�Mӷ�bvń����_)���([��&��4#�����vl.P�����CKm$O�������Z�
2
- �~��7
1
+ WG��x:I��+�Rb���t}���+>�C���E>� ��\C /0����esT"U��&ά�^v��)��ku$_ABeAKk9Ҧ�w����pZf�<�V {C0��>��׷��N�(�Mߋ����iE�`���:D~�L&�� ��|���:]xrNؠ6k����=�*=?K.�a,5~#]c|��'Ś����X��4��Q�寢�ݛ�ս-���,l��B��r}')�1M� �����(EQ�� ������6µ