sensu-plugins-memory 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +10 -0
- data/LICENSE +23 -0
- data/README.md +18 -0
- data/bin/check-memory.rb +105 -0
- data/lib/sensu-plugins-memory/version.rb +9 -0
- data/lib/sensu-plugins-memory.rb +1 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae0d4935df847ee0c797b513414248ff9f615217
|
4
|
+
data.tar.gz: 773f00007fc44ec0adb8c1f59065bb5ce835a970
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 01f20ceb8f6fd78a41d558d410de68e876cf0d21d4e407901af7ca4683eb42440d584ec27455741ff0fb3bc364876dc56ea73065a66a6ba7143326b01e067876
|
7
|
+
data.tar.gz: e546aac46166f4580b8ee655838c5ed5c228b8cfcaee5d89565c2322abd7807b146e8755f340e6c04653f45061c6b8b78226140efaeb92b291c3c6d6bb427f0b
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2015 Matteo Cerutti
|
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.
|
23
|
+
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Sensu plugin for monitoring real memory and swap usage
|
2
|
+
|
3
|
+
A sensu plugin to monitor real memory and swap usage.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
The plugin accepts the following command line options:
|
8
|
+
|
9
|
+
```
|
10
|
+
--available Check thresholds against memory available
|
11
|
+
-c, --crit <PERCENTAGE> Critical if PERCENTAGE exceeds current memory available/used
|
12
|
+
--swap Check SWAP rather than real memory (default: false)
|
13
|
+
--used Check thresholds against memory used
|
14
|
+
-w, --warn <PERCENTAGE> Warn if PERCENTAGE exceeds current memory available/used
|
15
|
+
```
|
16
|
+
|
17
|
+
## Author
|
18
|
+
Matteo Cerutti - <matteo.cerutti@hotmail.co.uk>
|
data/bin/check-memory.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-memory.rb
|
4
|
+
#
|
5
|
+
# Author: Matteo Cerutti <matteo.cerutti@hotmail.co.uk>
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'sensu-plugin/check/cli'
|
9
|
+
|
10
|
+
class CheckMemory < Sensu::Plugin::Check::CLI
|
11
|
+
option :swap,
|
12
|
+
:description => "Check SWAP rather than real memory (default: false)",
|
13
|
+
:long => "--swap",
|
14
|
+
:boolean => true,
|
15
|
+
:default => false
|
16
|
+
|
17
|
+
option :available,
|
18
|
+
:description => "Check thresholds against memory available",
|
19
|
+
:long => "--available",
|
20
|
+
:boolean => true,
|
21
|
+
:default => true
|
22
|
+
|
23
|
+
option :used,
|
24
|
+
:description => "Check thresholds against memory used",
|
25
|
+
:long => "--used",
|
26
|
+
:boolean => true,
|
27
|
+
:default => false
|
28
|
+
|
29
|
+
option :warn,
|
30
|
+
:description => "Warn if PERCENTAGE exceeds current memory available/used",
|
31
|
+
:short => "-w <PERCENTAGE>",
|
32
|
+
:long => "--warn <PERCENTAGE>",
|
33
|
+
:proc => proc(&:to_i),
|
34
|
+
:default => 20
|
35
|
+
|
36
|
+
option :crit,
|
37
|
+
:description => "Critical if PERCENTAGE exceeds current memory available/used",
|
38
|
+
:short => "-c <PERCENTAGE>",
|
39
|
+
:long => "--crit <PERCENTAGE>",
|
40
|
+
:proc => proc(&:to_i),
|
41
|
+
:default => 15
|
42
|
+
|
43
|
+
def initialize()
|
44
|
+
super
|
45
|
+
|
46
|
+
# sanity checks
|
47
|
+
if config[:used]
|
48
|
+
raise "Warning threshold must be lower than the critical threshold" if config[:warn] >= config[:crit]
|
49
|
+
else
|
50
|
+
raise "Warning threshold must be greater than the critical threshold" if config[:warn] <= config[:crit]
|
51
|
+
end
|
52
|
+
|
53
|
+
@vmstat = get_vmstat()
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_vmstat()
|
57
|
+
vmstat = {}
|
58
|
+
|
59
|
+
meminfo = %x[cat /proc/meminfo]
|
60
|
+
vmstat['total'] = meminfo[/^MemTotal:\s*(\d+)/, 1].to_i
|
61
|
+
vmstat['free'] = meminfo[/^MemFree:\s*(\d+)/, 1].to_i
|
62
|
+
vmstat['available'] = meminfo[/^MemAvailable:\s*(\d+)/, 1].to_i
|
63
|
+
vmstat['buffers'] = meminfo[/^Buffers:\s*(\d+)/, 1].to_i
|
64
|
+
vmstat['cached'] = meminfo[/^Cached:\s*(\d+)/, 1].to_i
|
65
|
+
vmstat['swapcached'] = meminfo[/^SwapCached:\s*(\d+)/, 1].to_i
|
66
|
+
vmstat['swaptotal'] = meminfo[/^SwapTotal:\s*(\d+)/, 1].to_i
|
67
|
+
vmstat['swapfree'] = meminfo[/^SwapFree:\s*(\d+)/, 1].to_i
|
68
|
+
|
69
|
+
vmstat
|
70
|
+
end
|
71
|
+
|
72
|
+
def run
|
73
|
+
if config[:swap]
|
74
|
+
avail = @vmstat['swapcached'] + @vmstat['swapfree']
|
75
|
+
used = @vmstat['swaptotal'] - avail
|
76
|
+
|
77
|
+
if @vmstat['swaptotal'] > 0
|
78
|
+
pavail = avail * 100 / @vmstat['swaptotal']
|
79
|
+
pused = used * 100 / @vmstat['swaptotal']
|
80
|
+
else
|
81
|
+
ok("Swap is disabled")
|
82
|
+
end
|
83
|
+
|
84
|
+
prefix = "Swap"
|
85
|
+
else
|
86
|
+
avail = @vmstat['cached'] + @vmstat['buffers'] + @vmstat['free']
|
87
|
+
used = @vmstat['total'] - avail
|
88
|
+
pavail = avail * 100 / @vmstat['total']
|
89
|
+
pused = used * 100 / @vmstat['total']
|
90
|
+
prefix = "Real"
|
91
|
+
end
|
92
|
+
|
93
|
+
if config[:used]
|
94
|
+
msg = "#{prefix} memory used #{used / 1024}MB of #{@vmstat['total'] / 1024}MB"
|
95
|
+
warning("#{msg} (>= #{config[:crit]}%)") if pused >= config[:crit]
|
96
|
+
critical("#{msg} (>= #{config[:warn]}%)") if pused >= config[:warn]
|
97
|
+
ok("#{msg} (< #{config[:warn]}%)")
|
98
|
+
else
|
99
|
+
msg = "#{prefix} memory available #{avail / 1024}MB of #{@vmstat['total'] / 1024}MB"
|
100
|
+
warning("#{msg} (<= #{config[:crit]}%)") if pavail <= config[:crit]
|
101
|
+
critical("#{msg} (<= #{config[:warn]}%)") if pavail <= config[:warn]
|
102
|
+
ok("#{msg} (>= #{config[:warn]}%)")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sensu-plugins-memory/version'
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-memory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matteo Cerutti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-05 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.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.0
|
27
|
+
description: This plugin provides facilities for monitoring real memory and swap usage
|
28
|
+
email: "<matteo.cerutti@hotmail.co.uk>"
|
29
|
+
executables:
|
30
|
+
- check-memory.rb
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- bin/check-memory.rb
|
38
|
+
- lib/sensu-plugins-memory.rb
|
39
|
+
- lib/sensu-plugins-memory/version.rb
|
40
|
+
homepage: https://github.com/m4ce/sensu-plugins-memory
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata:
|
44
|
+
maintainer: "@m4ce"
|
45
|
+
development_status: active
|
46
|
+
production_status: stable
|
47
|
+
release_draft: 'false'
|
48
|
+
release_prerelease: 'false'
|
49
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
50
|
+
in /etc/default/sensu
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.9.3
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.4.5.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Sensu plugins for monitoring real memory and swap usage
|
70
|
+
test_files: []
|