sensu-plugins-memory-checks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +12 -0
- data/LICENSE +22 -0
- data/README.md +27 -0
- data/bin/check-mem.sh +70 -0
- data/bin/check-memory-pcnt.sh +78 -0
- data/bin/check-ram.rb +73 -0
- data/bin/check-swap-percentage.sh +47 -0
- data/bin/check-swap.sh +68 -0
- data/bin/metrics-memory-percent.rb +97 -0
- data/bin/metrics-memory.rb +74 -0
- data/lib/sensu-plugins-memory-checks.rb +15 -0
- data/lib/sensu-plugins-memory-checks/version.rb +28 -0
- metadata +251 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dd378e636239b2a88381ca07c75bb7be16a90854
|
4
|
+
data.tar.gz: 0af9349b3773b9a4571a175b070ba3a84251005c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75fc60eef163cac65843e7c8bbd98c177f0c02f9cc97ad336cc9773dc395f76a71e04555dee2b1c8386a0ed631cf03e094bb6a791c874f7261367451b7e2b066
|
7
|
+
data.tar.gz: 947127ccf73feefd5ef39f2efd72495329304484f4560c016b1bd60a5e734d503f3d145967f881c5d97a1b330a766aa4a60c3d19870555ba83351600072e444a
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v71��>�5�;^�:��^����xƑC�E.;:-"�tV0ebB>x?��h�E��5�Y��2���w�c5�H�n�K�������B!��5�w���:��k]y�U��N)D��ރi�)?�G'uTҥ���Yr�]�Je��%*ꉤ"$\q�f�L��`P� E^%i�����3l�yW/�҅��w���1
|
data.tar.gz.sig
ADDED
Binary file
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#Change Log
|
2
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
|
+
|
4
|
+
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
|
+
|
6
|
+
## Unreleased][unreleased]
|
7
|
+
|
8
|
+
## 0.0.1 - 2015-05-21
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- initial release
|
12
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sensu-Plugins
|
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,27 @@
|
|
1
|
+
## Sensu-Plugins-memory-checks
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-memory-checks.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-memory-checks)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-memory-checks.svg)](http://badge.fury.io/rb/sensu-plugins-memory-checks)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-memory-checks/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-memory-checks)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-memory-checks/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-memory-checks)
|
7
|
+
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-memory-checks.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-memory-checks)
|
8
|
+
[ ![Codeship Status for sensu-plugins/sensu-plugins-memory-checks](https://codeship.com/projects/a76e31a0-dc03-0132-9d16-1e3fe125131b/status?branch=master)](https://codeship.com/projects/79854)
|
9
|
+
|
10
|
+
## Functionality
|
11
|
+
|
12
|
+
## Files
|
13
|
+
* bin/check-mem.sh
|
14
|
+
* bin/check-memory-pcnt.sh
|
15
|
+
* bin/check-ram.rb
|
16
|
+
* bin/check-swap-percentage.sh
|
17
|
+
* bin/check-swap.rb
|
18
|
+
* bin/metrics-memory-percent
|
19
|
+
* bin/metrics-memory.rb
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
[Installation and Setup](https://github.com/sensu-plugins/documentation/blob/master/user_docs/installation_instructions.md)
|
26
|
+
|
27
|
+
## Notes
|
data/bin/check-mem.sh
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# Evaluate free system memory from Linux based systems.
|
4
|
+
#
|
5
|
+
# Date: 2007-11-12
|
6
|
+
# Author: Thomas Borger - ESG
|
7
|
+
# Date: 2012-04-02
|
8
|
+
# Modified: Norman Harman - norman.harman@mutualmobile.com
|
9
|
+
#
|
10
|
+
# The memory check is done with following command line:
|
11
|
+
# free -m | grep buffers/cache | awk '{ print $4 }'
|
12
|
+
|
13
|
+
# get arguments
|
14
|
+
|
15
|
+
# #RED
|
16
|
+
while getopts 'w:c:hp' OPT; do
|
17
|
+
case $OPT in
|
18
|
+
w) WARN=$OPTARG;;
|
19
|
+
c) CRIT=$OPTARG;;
|
20
|
+
h) hlp="yes";;
|
21
|
+
p) perform="yes";;
|
22
|
+
*) unknown="yes";;
|
23
|
+
esac
|
24
|
+
done
|
25
|
+
|
26
|
+
# usage
|
27
|
+
HELP="
|
28
|
+
usage: $0 [ -w value -c value -p -h ]
|
29
|
+
|
30
|
+
-w --> Warning MB < value
|
31
|
+
-c --> Critical MB < value
|
32
|
+
-p --> print out performance data
|
33
|
+
-h --> print this help screen
|
34
|
+
"
|
35
|
+
|
36
|
+
if [ "$hlp" = "yes" ]; then
|
37
|
+
echo "$HELP"
|
38
|
+
exit 0
|
39
|
+
fi
|
40
|
+
|
41
|
+
WARN=${WARN:=0}
|
42
|
+
CRIT=${CRIT:=0}
|
43
|
+
|
44
|
+
if [ -f /etc/redhat-release ] && [ `awk '{print $3}' /etc/redhat-release` = "21" ]; then
|
45
|
+
FREE_MEMORY=`free -m | grep Mem | awk '{ print $7 }'`
|
46
|
+
else
|
47
|
+
FREE_MEMORY=`free -m | grep buffers/cache | awk '{ print $4 }'`
|
48
|
+
fi
|
49
|
+
|
50
|
+
if [ "$FREE_MEMORY" = "" ]; then
|
51
|
+
echo "MEM UNKNOWN -"
|
52
|
+
exit 3
|
53
|
+
fi
|
54
|
+
|
55
|
+
if [ "$perform" = "yes" ]; then
|
56
|
+
output="free system memory: $FREE_MEMORY MB | free memory="$FREE_MEMORY"MB;$WARN;$CRIT;0"
|
57
|
+
else
|
58
|
+
output="free system memory: $FREE_MEMORY MB"
|
59
|
+
fi
|
60
|
+
|
61
|
+
if (( $FREE_MEMORY <= $CRIT )); then
|
62
|
+
echo "MEM CRITICAL - $output"
|
63
|
+
exit 2
|
64
|
+
elif (( $FREE_MEMORY <= $WARN )); then
|
65
|
+
echo "MEM WARNING - $output"
|
66
|
+
exit 1
|
67
|
+
else
|
68
|
+
echo "MEM OK - $output"
|
69
|
+
exit 0
|
70
|
+
fi
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
#
|
3
|
+
# Evaluate free system memory from Linux based systems based on percentage
|
4
|
+
# This was forked from Sensu Community Plugins
|
5
|
+
#
|
6
|
+
# Requires: bc
|
7
|
+
#
|
8
|
+
# Date: 2007-11-12
|
9
|
+
# Author: Thomas Borger - ESG
|
10
|
+
# Date: 2012-04-02
|
11
|
+
# Modified: Norman Harman - norman.harman@mutualmobile.com
|
12
|
+
# Date: 2013-9-30
|
13
|
+
# Modified: Mario Harvey - Zumetrics
|
14
|
+
# Date: 2015-01-10
|
15
|
+
# Modified Ollie Armstrong <ollie@armstrong.io>
|
16
|
+
|
17
|
+
# get arguments
|
18
|
+
|
19
|
+
# #RED
|
20
|
+
while getopts 'w:c:hp' OPT; do
|
21
|
+
case $OPT in
|
22
|
+
w) WARN=$OPTARG;;
|
23
|
+
c) CRIT=$OPTARG;;
|
24
|
+
h) hlp="yes";;
|
25
|
+
p) perform="yes";;
|
26
|
+
*) unknown="yes";;
|
27
|
+
esac
|
28
|
+
done
|
29
|
+
|
30
|
+
# usage
|
31
|
+
HELP="
|
32
|
+
usage: $0 [ -w value -c value -p -h ]
|
33
|
+
|
34
|
+
-w --> Warning Percentage < value
|
35
|
+
-c --> Critical Percentage < value
|
36
|
+
-p --> print out performance data
|
37
|
+
-h --> print this help screen
|
38
|
+
"
|
39
|
+
|
40
|
+
if [ "$hlp" = "yes" ]; then
|
41
|
+
echo "$HELP"
|
42
|
+
exit 0
|
43
|
+
fi
|
44
|
+
|
45
|
+
WARN=${WARN:=0}
|
46
|
+
CRIT=${CRIT:=0}
|
47
|
+
|
48
|
+
#Get total memory available on machine
|
49
|
+
TotalMem=$(free -m | grep Mem | awk '{ print $2 }')
|
50
|
+
#Determine amount of free memory on the machine
|
51
|
+
FreeMem=$(free -m | grep buffers/cache | awk '{ print $4 }')
|
52
|
+
#Get percentage of free memory
|
53
|
+
FreePer=$(echo "scale=3; $FreeMem / $TotalMem * 100" | bc -l| cut -d "." -f1)
|
54
|
+
#Get actual memory usage percentage by subtracting free memory percentage from 100
|
55
|
+
UsedPer=$((100-$FreePer))
|
56
|
+
|
57
|
+
|
58
|
+
if [ "$UsedPer" = "" ]; then
|
59
|
+
echo "MEM UNKNOWN -"
|
60
|
+
exit 3
|
61
|
+
fi
|
62
|
+
|
63
|
+
if [ "$perform" = "yes" ]; then
|
64
|
+
output="system memory usage: $UsedPer% | free memory="$UsedPer"MB;$WARN;$CRIT;0"
|
65
|
+
else
|
66
|
+
output="system memory usage: $UsedPer%"
|
67
|
+
fi
|
68
|
+
|
69
|
+
if (( $UsedPer >= $CRIT )); then
|
70
|
+
echo "MEM CRITICAL - $output"
|
71
|
+
exit 2
|
72
|
+
elif (( $UsedPer >= $WARN )); then
|
73
|
+
echo "MEM WARNING - $output"
|
74
|
+
exit 1
|
75
|
+
else
|
76
|
+
echo "MEM OK - $output"
|
77
|
+
exit 0
|
78
|
+
fi
|
data/bin/check-ram.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# check-ram
|
5
|
+
#
|
6
|
+
# DESCRIPTION:
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: sensu-plugin
|
16
|
+
#
|
17
|
+
# USAGE:
|
18
|
+
#
|
19
|
+
# NOTES:
|
20
|
+
#
|
21
|
+
# LICENSE:
|
22
|
+
# Copyright 2012 Sonian, Inc <chefs@sonian.net>
|
23
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
24
|
+
# for details.
|
25
|
+
#
|
26
|
+
require 'sensu-plugin/check/cli'
|
27
|
+
|
28
|
+
class CheckRAM < Sensu::Plugin::Check::CLI
|
29
|
+
option :megabytes,
|
30
|
+
short: '-m',
|
31
|
+
long: '--megabytes',
|
32
|
+
description: 'Unless --megabytes is specified the thresholds are in percents',
|
33
|
+
boolean: true,
|
34
|
+
default: false
|
35
|
+
|
36
|
+
option :warn,
|
37
|
+
short: '-w WARN',
|
38
|
+
proc: proc(&:to_i),
|
39
|
+
default: 10
|
40
|
+
|
41
|
+
option :crit,
|
42
|
+
short: '-c CRIT',
|
43
|
+
proc: proc(&:to_i),
|
44
|
+
default: 5
|
45
|
+
|
46
|
+
def run
|
47
|
+
total_ram = 0
|
48
|
+
free_ram = 0
|
49
|
+
|
50
|
+
`free -m`.split("\n").drop(1).each do |line|
|
51
|
+
# #YELLOW
|
52
|
+
free_ram = line.split[3].to_i if line =~ /^-\/\+ buffers\/cache:/ # rubocop:disable RegexpLiteral
|
53
|
+
total_ram = line.split[1].to_i if line =~ /^Mem:/
|
54
|
+
end
|
55
|
+
|
56
|
+
if config[:megabytes]
|
57
|
+
message "#{free_ram} megabytes free RAM left"
|
58
|
+
|
59
|
+
critical if free_ram < config[:crit]
|
60
|
+
warning if free_ram < config[:warn]
|
61
|
+
ok
|
62
|
+
else
|
63
|
+
unknown 'invalid percentage' if config[:crit] > 100 || config[:warn] > 100
|
64
|
+
|
65
|
+
percents_left = free_ram * 100 / total_ram
|
66
|
+
message "#{percents_left}% free RAM left"
|
67
|
+
|
68
|
+
critical if percents_left < config[:crit]
|
69
|
+
warning if percents_left < config[:warn]
|
70
|
+
ok
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# Checks SWAP usage as a % of the total swap
|
4
|
+
#
|
5
|
+
# Date: 05/12/13
|
6
|
+
# Author: Nick Barrett - EDITD
|
7
|
+
# License: MIT
|
8
|
+
#
|
9
|
+
# Usage: check-swap-percentage.sh -w warn_percent -c critical_percent
|
10
|
+
# Uses free (Linux-only) & bc
|
11
|
+
|
12
|
+
# #RED
|
13
|
+
# input options
|
14
|
+
while getopts ':w:c:' OPT; do
|
15
|
+
case $OPT in
|
16
|
+
w) WARN=$OPTARG;;
|
17
|
+
c) CRIT=$OPTARG;;
|
18
|
+
esac
|
19
|
+
done
|
20
|
+
|
21
|
+
WARN=${WARN:=100}
|
22
|
+
CRIT=${CRIT:=100}
|
23
|
+
|
24
|
+
|
25
|
+
# get swap details
|
26
|
+
USED=`free -m | grep 'Swap:' | awk '{ print $3 }'`
|
27
|
+
TOTAL=`free -m | grep 'Swap:' | awk '{ print $2 }'`
|
28
|
+
|
29
|
+
if [[ $TOTAL -eq 0 ]] ; then
|
30
|
+
echo "There is no SWAP on this machine"
|
31
|
+
exit 0
|
32
|
+
else
|
33
|
+
PERCENT=`echo "scale=3;$USED/$TOTAL*100" | bc -l | awk '{printf "%f", $0}'`
|
34
|
+
|
35
|
+
OUTPUT="Swap usage: $PERCENT%, $USED/$TOTAL"
|
36
|
+
|
37
|
+
if [ "$(echo "$PERCENT >= $CRIT" | bc)" -eq 1 ] ; then
|
38
|
+
echo "SWAP CRITICAL - $OUTPUT"
|
39
|
+
exit 2
|
40
|
+
elif [ "$(echo "$PERCENT >= $WARN" | bc)" -eq 1 ] ; then
|
41
|
+
echo "SWAP WARNING - $OUTPUT"
|
42
|
+
exit 1
|
43
|
+
else
|
44
|
+
echo "SWAP OK - $OUTPUT"
|
45
|
+
exit 0
|
46
|
+
fi
|
47
|
+
fi
|
data/bin/check-swap.sh
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# Evaluate swap memory usage from Linux based systems.
|
4
|
+
#
|
5
|
+
# Date: 2007-11-12
|
6
|
+
# Author: Thomas Borger - ESG
|
7
|
+
# Date: 2012-04-02
|
8
|
+
# Modified: Norman Harman - norman.harman@mutualmobile.com
|
9
|
+
# Date: 2013-03-13
|
10
|
+
# Modified: Jean-Francois Theroux - jtheroux@lapresse.ca
|
11
|
+
#
|
12
|
+
# The swap check is done with following command line:
|
13
|
+
# vmstat | tail -n1 | awk '{ print $3 }'
|
14
|
+
|
15
|
+
# get arguments
|
16
|
+
|
17
|
+
# #RED
|
18
|
+
while getopts 'w:c:hp' OPT; do
|
19
|
+
case $OPT in
|
20
|
+
w) WARN=$OPTARG;;
|
21
|
+
c) CRIT=$OPTARG;;
|
22
|
+
h) hlp="yes";;
|
23
|
+
p) perform="yes";;
|
24
|
+
*) unknown="yes";;
|
25
|
+
esac
|
26
|
+
done
|
27
|
+
|
28
|
+
# usage
|
29
|
+
HELP="
|
30
|
+
usage: $0 [ -w value -c value -p -h ]
|
31
|
+
|
32
|
+
-w --> Warning MB < value
|
33
|
+
-c --> Critical MB < value
|
34
|
+
-p --> print out performance data
|
35
|
+
-h --> print this help screen
|
36
|
+
"
|
37
|
+
|
38
|
+
if [ "$hlp" = "yes" ]; then
|
39
|
+
echo "$HELP"
|
40
|
+
exit 0
|
41
|
+
fi
|
42
|
+
|
43
|
+
WARN=${WARN:=0}
|
44
|
+
CRIT=${CRIT:=0}
|
45
|
+
|
46
|
+
USED_SWAP=$((`vmstat | tail -n1 | awk '{ print $3 }'` / 1024 ))
|
47
|
+
|
48
|
+
if [ "$USED_SWAP" = "" ]; then
|
49
|
+
echo "SWAP UNKNOWN -"
|
50
|
+
exit 3
|
51
|
+
fi
|
52
|
+
|
53
|
+
if [ "$perform" = "yes" ]; then
|
54
|
+
output="used swap memory: $USED_SWAP MB | used swap memory="$USED_SWAP"MB;$WARN;$CRIT;0"
|
55
|
+
else
|
56
|
+
output="used swap memory: $USED_SWAP MB"
|
57
|
+
fi
|
58
|
+
|
59
|
+
if (( $USED_SWAP >= $CRIT )); then
|
60
|
+
echo "SWAP CRITICAL - $output"
|
61
|
+
exit 2
|
62
|
+
elif (( $USED_SWAP >= $WARN )); then
|
63
|
+
echo "SWAP WARNING - $output"
|
64
|
+
exit 1
|
65
|
+
else
|
66
|
+
echo "SWAP OK - $output"
|
67
|
+
exit 0
|
68
|
+
fi
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# mermory-metrics-percent
|
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
|
+
class MemoryGraphite < Sensu::Plugin::Metric::CLI::Graphite
|
32
|
+
option :scheme,
|
33
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
34
|
+
short: '-s SCHEME',
|
35
|
+
long: '--scheme SCHEME',
|
36
|
+
default: "#{Socket.gethostname}.memory_percent"
|
37
|
+
|
38
|
+
def run
|
39
|
+
# Based on memory-metrics.rb
|
40
|
+
|
41
|
+
# Metrics borrowed from hoardd: https://github.com/coredump/hoardd
|
42
|
+
|
43
|
+
mem = metrics_hash
|
44
|
+
|
45
|
+
mem.each do |k, v|
|
46
|
+
output "#{config[:scheme]}.#{k}", v
|
47
|
+
end
|
48
|
+
|
49
|
+
ok
|
50
|
+
end
|
51
|
+
|
52
|
+
def metrics_hash # rubocop:disable all
|
53
|
+
mem = {}
|
54
|
+
memp = {}
|
55
|
+
|
56
|
+
meminfo_output.each_line do |line|
|
57
|
+
mem['total'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^MemTotal/)
|
58
|
+
mem['free'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^MemFree/)
|
59
|
+
mem['buffers'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^Buffers/)
|
60
|
+
mem['cached'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^Cached/)
|
61
|
+
mem['swapTotal'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^SwapTotal/)
|
62
|
+
mem['swapFree'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^SwapFree/)
|
63
|
+
mem['dirty'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^Dirty/)
|
64
|
+
end
|
65
|
+
|
66
|
+
mem['swapUsed'] = mem['swapTotal'] - mem['swapFree']
|
67
|
+
mem['used'] = mem['total'] - mem['free']
|
68
|
+
mem['usedWOBuffersCaches'] = mem['used'] - (mem['buffers'] + mem['cached'])
|
69
|
+
mem['freeWOBuffersCaches'] = mem['free'] + (mem['buffers'] + mem['cached'])
|
70
|
+
|
71
|
+
# to prevent division by zero
|
72
|
+
if mem['swapTotal'] == 0
|
73
|
+
swptot = 1
|
74
|
+
else
|
75
|
+
swptot = mem['swapTotal']
|
76
|
+
end
|
77
|
+
|
78
|
+
mem.each do |k, _v|
|
79
|
+
# with percentages, used and free are exactly complementary
|
80
|
+
# no need to have both
|
81
|
+
# the one to drop here is "used" because "free" will
|
82
|
+
# stack up neatly to 100% with all the others (except swapUsed)
|
83
|
+
# #YELLOW
|
84
|
+
memp[k] = 100.0 * mem[k] / mem['total'] if k != 'total' && k !~ /swap/ && k != 'used'
|
85
|
+
|
86
|
+
# with percentages, swapUsed and swapFree are exactly complementary
|
87
|
+
# no need to have both
|
88
|
+
memp[k] = 100.0 * mem[k] / swptot if k != 'swapTotal' && k =~ /swap/ && k != 'swapFree'
|
89
|
+
end
|
90
|
+
|
91
|
+
memp
|
92
|
+
end
|
93
|
+
|
94
|
+
def meminfo_output
|
95
|
+
File.open('/proc/meminfo', 'r')
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# memory-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
|
+
class MemoryGraphite < Sensu::Plugin::Metric::CLI::Graphite
|
32
|
+
option :scheme,
|
33
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
34
|
+
short: '-s SCHEME',
|
35
|
+
long: '--scheme SCHEME',
|
36
|
+
default: "#{Socket.gethostname}.memory"
|
37
|
+
|
38
|
+
def run
|
39
|
+
# Metrics borrowed from hoardd: https://github.com/coredump/hoardd
|
40
|
+
|
41
|
+
mem = metrics_hash
|
42
|
+
|
43
|
+
mem.each do |k, v|
|
44
|
+
output "#{config[:scheme]}.#{k}", v
|
45
|
+
end
|
46
|
+
|
47
|
+
ok
|
48
|
+
end
|
49
|
+
|
50
|
+
def metrics_hash
|
51
|
+
mem = {}
|
52
|
+
meminfo_output.each_line do |line|
|
53
|
+
mem['total'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^MemTotal/)
|
54
|
+
mem['free'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^MemFree/)
|
55
|
+
mem['buffers'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^Buffers/)
|
56
|
+
mem['cached'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^Cached/)
|
57
|
+
mem['swapTotal'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^SwapTotal/)
|
58
|
+
mem['swapFree'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^SwapFree/)
|
59
|
+
mem['dirty'] = line.split(/\s+/)[1].to_i * 1024 if line.match(/^Dirty/)
|
60
|
+
end
|
61
|
+
|
62
|
+
mem['swapUsed'] = mem['swapTotal'] - mem['swapFree']
|
63
|
+
mem['used'] = mem['total'] - mem['free']
|
64
|
+
mem['usedWOBuffersCaches'] = mem['used'] - (mem['buffers'] + mem['cached'])
|
65
|
+
mem['freeWOBuffersCaches'] = mem['free'] + (mem['buffers'] + mem['cached'])
|
66
|
+
mem['swapUsedPercentage'] = 100 * mem['swapUsed'] / mem['swapTotal'] if mem['swapTotal'] > 0
|
67
|
+
|
68
|
+
mem
|
69
|
+
end
|
70
|
+
|
71
|
+
def meminfo_output
|
72
|
+
File.open('/proc/meminfo', 'r')
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
# encoding: utf-8
|
4
|
+
module SensuPluginsMemoryChecks
|
5
|
+
# This defines the version of the gem
|
6
|
+
module Version
|
7
|
+
MAJOR = 0
|
8
|
+
MINOR = 0
|
9
|
+
PATCH = 1
|
10
|
+
|
11
|
+
VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
|
12
|
+
|
13
|
+
NAME = 'sensu-plugins-memory-checks'
|
14
|
+
BANNER = "#{NAME} v%s"
|
15
|
+
|
16
|
+
module_function
|
17
|
+
|
18
|
+
def version
|
19
|
+
format(BANNER, VER_STRING)
|
20
|
+
end
|
21
|
+
|
22
|
+
def json_version
|
23
|
+
{
|
24
|
+
'version' => VER_STRING
|
25
|
+
}.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-memory-checks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sensu Plugins 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-05-22 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: timeout
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.0.1
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.0.1
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: memcached
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.8.0
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: codeclimate-test-reporter
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0.4'
|
84
|
+
type: :development
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0.4'
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rubocop
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.30'
|
98
|
+
type: :development
|
99
|
+
prerelease: false
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0.30'
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: rspec
|
107
|
+
requirement: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '3.1'
|
112
|
+
type: :development
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '3.1'
|
119
|
+
- !ruby/object:Gem::Dependency
|
120
|
+
name: bundler
|
121
|
+
requirement: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '1.7'
|
126
|
+
type: :development
|
127
|
+
prerelease: false
|
128
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '1.7'
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: rake
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '10.0'
|
140
|
+
type: :development
|
141
|
+
prerelease: false
|
142
|
+
version_requirements: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '10.0'
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
name: github-markup
|
149
|
+
requirement: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '1.3'
|
154
|
+
type: :development
|
155
|
+
prerelease: false
|
156
|
+
version_requirements: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - "~>"
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '1.3'
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
name: redcarpet
|
163
|
+
requirement: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - "~>"
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '3.2'
|
168
|
+
type: :development
|
169
|
+
prerelease: false
|
170
|
+
version_requirements: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - "~>"
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '3.2'
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: yard
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - "~>"
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0.8'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - "~>"
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0.8'
|
189
|
+
- !ruby/object:Gem::Dependency
|
190
|
+
name: pry
|
191
|
+
requirement: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - "~>"
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0.10'
|
196
|
+
type: :development
|
197
|
+
prerelease: false
|
198
|
+
version_requirements: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - "~>"
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0.10'
|
203
|
+
description: Sensu plugins for checking memory
|
204
|
+
email: "<sensu-users@googlegroups.com>"
|
205
|
+
executables: []
|
206
|
+
extensions: []
|
207
|
+
extra_rdoc_files: []
|
208
|
+
files:
|
209
|
+
- CHANGELOG.md
|
210
|
+
- LICENSE
|
211
|
+
- README.md
|
212
|
+
- bin/check-mem.sh
|
213
|
+
- bin/check-memory-pcnt.sh
|
214
|
+
- bin/check-ram.rb
|
215
|
+
- bin/check-swap-percentage.sh
|
216
|
+
- bin/check-swap.sh
|
217
|
+
- bin/metrics-memory-percent.rb
|
218
|
+
- bin/metrics-memory.rb
|
219
|
+
- lib/sensu-plugins-memory-checks.rb
|
220
|
+
- lib/sensu-plugins-memory-checks/version.rb
|
221
|
+
homepage: https://github.com/sensu-plugins/sensu-plugins-memory-checks
|
222
|
+
licenses:
|
223
|
+
- MIT
|
224
|
+
metadata:
|
225
|
+
maintainer: ''
|
226
|
+
development_status: active
|
227
|
+
production_status: unstable - testing recommended
|
228
|
+
release_draft: 'false'
|
229
|
+
release_prerelease: 'false'
|
230
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
231
|
+
in /etc/default/sensu
|
232
|
+
rdoc_options: []
|
233
|
+
require_paths:
|
234
|
+
- lib
|
235
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
236
|
+
requirements:
|
237
|
+
- - ">="
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: 1.9.3
|
240
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
241
|
+
requirements:
|
242
|
+
- - ">="
|
243
|
+
- !ruby/object:Gem::Version
|
244
|
+
version: '0'
|
245
|
+
requirements: []
|
246
|
+
rubyforge_project:
|
247
|
+
rubygems_version: 2.4.6
|
248
|
+
signing_key:
|
249
|
+
specification_version: 4
|
250
|
+
summary: Sensu plugins for checking memory
|
251
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|