check-disk-io 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/check-disk-io_gem.rb +150 -0
  3. metadata +63 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 511a2d6021d61c83dff4ea328072133b28189630
4
+ data.tar.gz: 7bbbb4f7969e7067c798bddb7cc864922ca5b05c
5
+ SHA512:
6
+ metadata.gz: df704c6954867e6a764944ac0ab6126c4caf590a2eab8e0a5a2d088f9e060f6a89983213c3222f49812839bf623e105a83514840e6d1989e849d59d8b5f4bf6d
7
+ data.tar.gz: 3d02a9c7285b8a5c0f016fe03d65f0eedfc0602bac08cbf39cc071186f33c92cf3fff1ad0ceb18e23cff236962e80e6b11571b789029e825f0ed6848771fc0cc
@@ -0,0 +1,150 @@
1
+ #!/opt/sensu/embedded/bin/ruby
2
+ #
3
+ # encoding: UTF-8
4
+ # check-disk-io.rb
5
+ #
6
+ # DESCRIPTION:
7
+ # Check disks io and alert if over threshold
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ #
20
+ # ./check-disk-io.rb -w 1000 -c 2000
21
+ #
22
+ #
23
+ # LICENSE:
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
25
+ # for details.
26
+ require 'sensu-plugin/check/cli'
27
+ require 'ostruct'
28
+
29
+ class Diskstats
30
+ include Enumerable
31
+
32
+ COLUMNS = [
33
+ :major,
34
+ :minor,
35
+ :device_name,
36
+ :reads_success,
37
+ :reads_merged,
38
+ :sectors_read,
39
+ :read_time_ms,
40
+ :writes_success,
41
+ :writes_merged,
42
+ :sectors_written,
43
+ :write_time_ms,
44
+ :current_ios,
45
+ :io_time_ms,
46
+ :weightd_io_time_ms
47
+ ]
48
+
49
+ attr_reader :raw_stats, :now, :later
50
+
51
+ def initialize(stats)
52
+ @raw_stats = stats
53
+ end
54
+
55
+ def rows
56
+ @rows ||= raw_stats.lines.map do |line|
57
+ OpenStruct.new(Hash[COLUMNS.zip(line.strip.split)])
58
+ end
59
+ end
60
+
61
+ def each(&block)
62
+ rows.each(&block)
63
+ end
64
+
65
+ def self.from_proc
66
+ new(File.read('/proc/diskstats'))
67
+ end
68
+ end
69
+
70
+ class CheckDiskIO < Sensu::Plugin::Check::CLI
71
+
72
+ check_name 'check_disk_io'
73
+
74
+ option :warning,
75
+ short: '-w WARNING',
76
+ long: '--warning WARNING',
77
+ description: 'Warning threshold',
78
+ default: 3000
79
+
80
+ option :critical,
81
+ short: '-c CRITICAL',
82
+ long: '--critical CRITICAL',
83
+ description: 'Critical threshold',
84
+ default: 4000
85
+
86
+ def run
87
+ disks = Diskstats.from_proc.reject { |s| s.device_name =~ /^sr0|fd0|ram|loop|dm-/ }.map(&:device_name)
88
+ counters = Hash[disks.each_with_object({}).to_a]
89
+ for i in 0..1 do
90
+ disks.each do |disk|
91
+ new_hash = {
92
+ disk => {
93
+ i => {
94
+ timestamp: Time.new.to_i,
95
+ writes_success: Diskstats.from_proc.select { |s| s.device_name == disk }.map(&:writes_success)
96
+ }
97
+ }
98
+ }
99
+ counters[disk] = counters[disk].merge(new_hash[disk])
100
+ sleep 3
101
+ end
102
+ end
103
+
104
+ alerts = []
105
+
106
+ counters.each do |counter|
107
+
108
+ counter[1].keys.sort.each_with_index do |key, index|
109
+ if index == counter[1].length - 1
110
+ last_writes_success = counter[1][key][:writes_success]
111
+ first_writes_success = counter[1][0][:writes_success]
112
+ result = last_writes_success.join.to_i - first_writes_success.join.to_i
113
+
114
+ device = counter[0]
115
+
116
+ if result >= config[:critical].to_i && result > config[:warning].to_i
117
+ alerts << [device, 'critical', result]
118
+ end
119
+ if result >= config[:warning].to_i && result < config[:critical].to_i
120
+ alerts << [device, 'warning', result]
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ if alerts.empty?
127
+ message 'Everything is ok'
128
+ ok
129
+ else
130
+ status = ''
131
+ messages = ''
132
+
133
+ alerts.each do |alert|
134
+ messages << "\r\n/dev/#{alert[0]} has reached #{alert[2]} IOPS"
135
+ if alert[1] == 'critical' && status.empty?
136
+ status = 'critical'
137
+ end
138
+ end
139
+
140
+ message messages
141
+
142
+ critical if status == 'critical'
143
+ warning if status != 'critical'
144
+ end
145
+
146
+ rescue => err
147
+ puts "Exception: #{err}"
148
+ err
149
+ end
150
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check-disk-io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Maxime Devalland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-plugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ - - '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.1.0
33
+ description:
34
+ email:
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - lib/check-disk-io_gem.rb
40
+ homepage:
41
+ licenses: []
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.6.11
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: check disk io
63
+ test_files: []