sensu-plugins-cpu-checks 0.0.1.alpha.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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +6 -0
- data/LICENSE +22 -0
- data/README.md +57 -0
- data/bin/check-cpu.rb +107 -0
- data/bin/check-cpu.sh +82 -0
- data/bin/metrics-cpu-mpstat.rb +88 -0
- data/bin/metrics-cpu-pcnt-usage.rb +81 -0
- data/bin/metrics-cpu.rb +67 -0
- data/bin/metrics-user-pct-usage.rb +70 -0
- data/lib/sensu-plugins-cpu-checks.rb +7 -0
- data.tar.gz.sig +0 -0
- metadata +219 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9726fd4f9ed8c5f89825fb98a032632c479fe9ad
|
4
|
+
data.tar.gz: f0b61c75a0f7d084a45e7b638bd2e3479471ebf5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b62e548c8d701d71a799722c173c7a87c6c5e4646644dc66a5c488661d8c1d36cc7d346c94e1b435d1e437dbc0276dae8f133509d92bd2caa2b1deb85b2056ab
|
7
|
+
data.tar.gz: 59690b48664f6fcdf365caa9dac4837760f1df922c433dec6ba58869411406387b87413b3599111f4ba93cd7b6205f9ade1c7e3b41ba1ddb518843054f6c7868
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/CHANGELOG.md
ADDED
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,57 @@
|
|
1
|
+
## Sensu-Plugins-cpu-checks
|
2
|
+
|
3
|
+
[](https://travis-ci.org/sensu-plugins/sensu-plugins-cpu-checks)
|
4
|
+
[](http://badge.fury.io/rb/sensu-plugins-cpu-checks)
|
5
|
+
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cpu-checks)
|
6
|
+
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cpu-checks)
|
7
|
+
[](https://gemnasium.com/sensu-plugins/sensu-plugins-cpu-checks)
|
8
|
+
|
9
|
+
## Functionality
|
10
|
+
|
11
|
+
## Files
|
12
|
+
* bin/check-cpu.rb
|
13
|
+
* bin/check-cpu.sh
|
14
|
+
* bin/metrics-cpu-mpstat
|
15
|
+
* bin/metrics-cpu-pcnt-usage
|
16
|
+
* bin/metrics-user-pct-usage
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Add the public key (if you haven’t already) as a trusted certificate
|
23
|
+
|
24
|
+
```
|
25
|
+
gem cert --add <(curl -Ls https://raw.githubusercontent.com/sensu-plugins/sensu-plugins.github.io/master/certs/sensu-plugins.pem)
|
26
|
+
gem install sensu-plugins-cpu-checks -P MediumSecurity
|
27
|
+
```
|
28
|
+
|
29
|
+
You can also download the key from /certs/ within each repository.
|
30
|
+
|
31
|
+
#### Rubygems
|
32
|
+
|
33
|
+
`gem install sensu-plugins-cpu-checks`
|
34
|
+
|
35
|
+
#### Bundler
|
36
|
+
|
37
|
+
Add *sensu-plugins-cpu-checks* to your Gemfile and run `bundle install` or `bundle update`
|
38
|
+
|
39
|
+
#### Chef
|
40
|
+
|
41
|
+
Using the Sensu **sensu_gem** LWRP
|
42
|
+
```
|
43
|
+
sensu_gem 'sensu-plugins-cpu-checks' do
|
44
|
+
options('--prerelease')
|
45
|
+
version '0.0.1'
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Using the Chef **gem_package** resource
|
50
|
+
```
|
51
|
+
gem_package 'sensu-plugins-cpu-checks' do
|
52
|
+
options('--prerelease')
|
53
|
+
version '0.0.1'
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
## Notes
|
data/bin/check-cpu.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-cpu
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Check cpu usage
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: sensu-plugin
|
16
|
+
#
|
17
|
+
# USAGE:
|
18
|
+
# #YELLOW
|
19
|
+
#
|
20
|
+
# NOTES:
|
21
|
+
#
|
22
|
+
# LICENSE:
|
23
|
+
# Copyright 2014 Sonian, Inc. and contributors. <support@sensuapp.org>
|
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 CPU
|
32
|
+
#
|
33
|
+
class CheckCPU < Sensu::Plugin::Check::CLI
|
34
|
+
option :warn,
|
35
|
+
short: '-w WARN',
|
36
|
+
proc: proc(&:to_f),
|
37
|
+
default: 80
|
38
|
+
|
39
|
+
option :crit,
|
40
|
+
short: '-c CRIT',
|
41
|
+
proc: proc(&:to_f),
|
42
|
+
default: 100
|
43
|
+
|
44
|
+
option :sleep,
|
45
|
+
long: '--sleep SLEEP',
|
46
|
+
proc: proc(&:to_f),
|
47
|
+
default: 1
|
48
|
+
|
49
|
+
[:user, :nice, :system, :idle, :iowait, :irq, :softirq, :steal, :guest].each do |metric|
|
50
|
+
option metric,
|
51
|
+
long: "--#{metric}",
|
52
|
+
description: "Check cpu #{metric} instead of total cpu usage",
|
53
|
+
boolean: true,
|
54
|
+
default: false
|
55
|
+
end
|
56
|
+
|
57
|
+
def acquire_cpu_stats
|
58
|
+
File.open('/proc/stat', 'r').each_line do |line|
|
59
|
+
info = line.split(/\s+/)
|
60
|
+
name = info.shift
|
61
|
+
return info.map(&:to_f) if name.match(/^cpu$/)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def run # rubocop:disable all
|
66
|
+
metrics = [:user, :nice, :system, :idle, :iowait, :irq, :softirq, :steal, :guest]
|
67
|
+
|
68
|
+
cpu_stats_before = acquire_cpu_stats
|
69
|
+
sleep config[:sleep]
|
70
|
+
cpu_stats_after = acquire_cpu_stats
|
71
|
+
|
72
|
+
# Some kernels don't have a 'guest' value (RHEL5).
|
73
|
+
metrics = metrics.slice(0, cpu_stats_after.length)
|
74
|
+
|
75
|
+
cpu_total_diff = 0.to_f
|
76
|
+
cpu_stats_diff = []
|
77
|
+
metrics.each_index do |i|
|
78
|
+
cpu_stats_diff[i] = cpu_stats_after[i] - cpu_stats_before[i]
|
79
|
+
cpu_total_diff += cpu_stats_diff[i]
|
80
|
+
end
|
81
|
+
|
82
|
+
cpu_stats = []
|
83
|
+
metrics.each_index do |i|
|
84
|
+
cpu_stats[i] = 100 * (cpu_stats_diff[i] / cpu_total_diff)
|
85
|
+
end
|
86
|
+
|
87
|
+
cpu_usage = 100 * (cpu_total_diff - cpu_stats_diff[3]) / cpu_total_diff
|
88
|
+
checked_usage = cpu_usage
|
89
|
+
|
90
|
+
self.class.check_name 'CheckCPU TOTAL'
|
91
|
+
metrics.each do |metric|
|
92
|
+
if config[metric]
|
93
|
+
self.class.check_name "CheckCPU #{metric.to_s.upcase}"
|
94
|
+
checked_usage = cpu_stats[metrics.find_index(metric)]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
msg = "total=#{(cpu_usage * 100).round / 100.0}"
|
99
|
+
cpu_stats.each_index { |i| msg += " #{metrics[i]}=#{(cpu_stats[i] * 100).round / 100.0}" }
|
100
|
+
|
101
|
+
message msg
|
102
|
+
|
103
|
+
critical if checked_usage > config[:crit]
|
104
|
+
warning if checked_usage > config[:warn]
|
105
|
+
ok
|
106
|
+
end
|
107
|
+
end
|
data/bin/check-cpu.sh
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# Check CPU usage
|
4
|
+
#
|
5
|
+
# ===
|
6
|
+
#
|
7
|
+
# Examples:
|
8
|
+
#
|
9
|
+
# check-cpu.sh -w 85 -c 95
|
10
|
+
#
|
11
|
+
# Date: 2014-09-12
|
12
|
+
# Author: Jun Ichikawa <jun1ka0@gmail.com>
|
13
|
+
#
|
14
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
15
|
+
# for details.
|
16
|
+
|
17
|
+
# get arguments
|
18
|
+
while getopts 'w:c:h' OPT; do
|
19
|
+
case $OPT in
|
20
|
+
w) WARN=$OPTARG;;
|
21
|
+
c) CRIT=$OPTARG;;
|
22
|
+
h) hlp="yes";;
|
23
|
+
*) unknown="yes";;
|
24
|
+
esac
|
25
|
+
done
|
26
|
+
|
27
|
+
# usage
|
28
|
+
HELP="
|
29
|
+
usage: $0 [ -w value -c value -p -h ]
|
30
|
+
|
31
|
+
-w --> Warning percentage < value
|
32
|
+
-c --> Critical percentage < value
|
33
|
+
-h --> print this help screen
|
34
|
+
"
|
35
|
+
|
36
|
+
if [ "$hlp" = "yes" ]; then
|
37
|
+
echo "$HELP"
|
38
|
+
exit 0
|
39
|
+
fi
|
40
|
+
|
41
|
+
cpuusage1=(`cat /proc/stat | head -1`)
|
42
|
+
if [ ${#cpuusage1} -eq 0 ]; then
|
43
|
+
echo "CRITICAL - CPU UNKNOWN"
|
44
|
+
exit 2
|
45
|
+
fi
|
46
|
+
sleep 1
|
47
|
+
cpuusage2=(`cat /proc/stat | head -1`)
|
48
|
+
if [ ${#cpuusage2} -eq 0 ]; then
|
49
|
+
echo "CRITICAL - CPU UNKNOWN"
|
50
|
+
exit 2
|
51
|
+
fi
|
52
|
+
|
53
|
+
WARN=${WARN:=90}
|
54
|
+
CRIT=${CRIT:=95}
|
55
|
+
|
56
|
+
cpu_diff=(0)
|
57
|
+
total=0
|
58
|
+
usage_diff=0
|
59
|
+
for i in `seq 1 9`
|
60
|
+
do
|
61
|
+
cpu_diff=("${cpu_diff[@]}" `echo "${cpuusage2[$i]}-${cpuusage1[$i]}" | bc`)
|
62
|
+
total=`echo "$total+${cpu_diff[$i]}" | bc`
|
63
|
+
if [ $i -ne "4" ]; then
|
64
|
+
usage_diff=`echo "$usage_diff+${cpu_diff[$i]}" | bc`
|
65
|
+
else
|
66
|
+
idl=$cpu_diff[$i]
|
67
|
+
fi
|
68
|
+
done
|
69
|
+
cpu_usage=`echo "scale=2; 100*$usage_diff/$total" | bc`
|
70
|
+
|
71
|
+
if [ "$(echo "${cpu_usage} > ${CRIT}" | bc)" -eq 1 ]; then
|
72
|
+
echo "CPU CRITICAL - ${cpu_usage}% is greater than critical point.[${CRIT}]"
|
73
|
+
exit 2
|
74
|
+
fi
|
75
|
+
|
76
|
+
if [ "$(echo "${cpu_usage} > ${WARN}" | bc)" -eq 1 ]; then
|
77
|
+
echo "CPU WARNING - ${cpu_usage}% is greater than warning point.[${WARN}]"
|
78
|
+
exit 1
|
79
|
+
fi
|
80
|
+
|
81
|
+
echo "CPU OK - Usage:${cpu_usage}"
|
82
|
+
exit 0
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# cpu-mpstat-metrics
|
5
|
+
#
|
6
|
+
# DESCRIPTION:
|
7
|
+
# Uses the linux/kstat rubygem to do the hard work in /proc/stat
|
8
|
+
# includes individual cpu and overall cpu usage
|
9
|
+
#
|
10
|
+
# OUTPUT:
|
11
|
+
# metric data
|
12
|
+
#
|
13
|
+
# PLATFORMS:
|
14
|
+
# Linux
|
15
|
+
#
|
16
|
+
# DEPENDENCIES:
|
17
|
+
# gem: sensu-plugin
|
18
|
+
# gem: socket
|
19
|
+
# gem: linux/kstat
|
20
|
+
#
|
21
|
+
# USAGE:
|
22
|
+
#
|
23
|
+
# NOTES:
|
24
|
+
#
|
25
|
+
# LICENSE:
|
26
|
+
# Copyright 2012 Sonian, Inc <chefs@sonian.net>
|
27
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
28
|
+
# for details.
|
29
|
+
#
|
30
|
+
|
31
|
+
require 'sensu-plugin/metric/cli'
|
32
|
+
require 'socket'
|
33
|
+
require 'linux/kstat'
|
34
|
+
|
35
|
+
#
|
36
|
+
# CPU Graphite
|
37
|
+
#
|
38
|
+
class CpuGraphite < Sensu::Plugin::Metric::CLI::Graphite
|
39
|
+
option :scheme,
|
40
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
41
|
+
short: '-s SCHEME',
|
42
|
+
long: '--scheme SCHEME',
|
43
|
+
default: "#{Socket.gethostname}.cpu"
|
44
|
+
|
45
|
+
def acquire_mpstats
|
46
|
+
kstat = Linux::Kstat.new
|
47
|
+
mpstat = {}
|
48
|
+
i = ''
|
49
|
+
until kstat[:"cpu#{i}"].nil?
|
50
|
+
mpstat[:"cpu#{i}"] = kstat[:"cpu#{i}"]
|
51
|
+
if i == ''
|
52
|
+
i = 0
|
53
|
+
else
|
54
|
+
i += 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
mpstat
|
58
|
+
end
|
59
|
+
|
60
|
+
def delta_cpu_metrics(baseline_cpus, sample_cpus)
|
61
|
+
delta_cpus = {}
|
62
|
+
baseline_cpus.each do |cpu, columns|
|
63
|
+
delta_cpus[:"#{cpu}"] = {}
|
64
|
+
columns.each do |task, time|
|
65
|
+
delta_cpus[:"#{cpu}"][:"#{task}"] = sample_cpus[:"#{cpu}"][:"#{task}"] - time
|
66
|
+
end
|
67
|
+
end
|
68
|
+
delta_cpus
|
69
|
+
end
|
70
|
+
|
71
|
+
def run
|
72
|
+
baseline_cpus = acquire_mpstats
|
73
|
+
# measure for a second then get the deltas in jiffies
|
74
|
+
sleep(1)
|
75
|
+
sample_cpus = acquire_mpstats
|
76
|
+
delta_cpus = delta_cpu_metrics(baseline_cpus, sample_cpus)
|
77
|
+
cpu_count = sample_cpus.length - 1
|
78
|
+
delta_cpus.each_pair do |cpu, columns|
|
79
|
+
# assumes architecture's jiffie is 1/100th of a second
|
80
|
+
columns.each_pair do |task, time|
|
81
|
+
# #YELLOW
|
82
|
+
time = time / cpu_count if "#{cpu}" == 'cpu' # rubocop:disable Style/SelfAssignment
|
83
|
+
output "#{config[:scheme]}.#{cpu}.#{task}", time
|
84
|
+
end
|
85
|
+
end
|
86
|
+
ok
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# cpu-pct-usage-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
|
+
require 'sensu-plugin/metric/cli'
|
28
|
+
require 'socket'
|
29
|
+
|
30
|
+
#
|
31
|
+
# CPU Graphite
|
32
|
+
#
|
33
|
+
class CpuGraphite < Sensu::Plugin::Metric::CLI::Graphite
|
34
|
+
option :scheme,
|
35
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
36
|
+
short: '-s SCHEME',
|
37
|
+
long: '--scheme SCHEME',
|
38
|
+
default: "#{Socket.gethostname}.cpu"
|
39
|
+
|
40
|
+
def acquire_proc_stats
|
41
|
+
cpu_metrics = %w(user nice system idle iowait irq softirq steal guest)
|
42
|
+
File.open('/proc/stat', 'r').each_line do |line|
|
43
|
+
info = line.split(/\s+/)
|
44
|
+
next if info.empty?
|
45
|
+
name = info.shift
|
46
|
+
|
47
|
+
# we are matching TOTAL stats and returning a hash of values
|
48
|
+
if name.match(/^cpu$/)
|
49
|
+
# return the CPU metrics sample as a hash
|
50
|
+
# filter out nil values, as some kernels don't have a 'guest' value
|
51
|
+
return Hash[cpu_metrics.zip(info.map(&:to_i))].reject { |_key, value| value.nil? }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def sum_cpu_metrics(metrics)
|
57
|
+
# #YELLOW
|
58
|
+
metrics.values.reduce { |sum, metric| sum + metric } # rubocop:disable SingleLineBlockParams
|
59
|
+
end
|
60
|
+
|
61
|
+
def run # rubocop:disable all
|
62
|
+
cpu_sample1 = acquire_proc_stats
|
63
|
+
sleep(1)
|
64
|
+
cpu_sample2 = acquire_proc_stats
|
65
|
+
cpu_metrics = cpu_sample2.keys
|
66
|
+
|
67
|
+
# we will sum all jiffy counts read in acquire_proc_stats
|
68
|
+
cpu_total1 = sum_cpu_metrics(cpu_sample1)
|
69
|
+
cpu_total2 = sum_cpu_metrics(cpu_sample2)
|
70
|
+
# total cpu usage in last second in CPU jiffs (1/100 s)
|
71
|
+
cpu_total_diff = cpu_total2 - cpu_total1
|
72
|
+
# per CPU metric diff
|
73
|
+
cpu_sample_diff = Hash[cpu_sample2.map { |k, v| [k, v - cpu_sample1[k]] }]
|
74
|
+
|
75
|
+
cpu_metrics.each do |metric|
|
76
|
+
metric_val = sprintf('%.02f', (cpu_sample_diff[metric] / cpu_total_diff.to_f) * 100) # rubocop:disable all
|
77
|
+
output "#{config[:scheme]}.#{metric}", metric_val
|
78
|
+
end
|
79
|
+
ok
|
80
|
+
end
|
81
|
+
end
|
data/bin/metrics-cpu.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# cpu-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
|
+
require 'sensu-plugin/metric/cli'
|
28
|
+
require 'socket'
|
29
|
+
|
30
|
+
#
|
31
|
+
# CPU Graphite
|
32
|
+
#
|
33
|
+
class CpuGraphite < Sensu::Plugin::Metric::CLI::Graphite
|
34
|
+
option :scheme,
|
35
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
36
|
+
short: '-s SCHEME',
|
37
|
+
long: '--scheme SCHEME',
|
38
|
+
default: "#{Socket.gethostname}.cpu"
|
39
|
+
|
40
|
+
def run # rubocop:disable all
|
41
|
+
cpu_metrics = %w(user nice system idle iowait irq softirq steal guest)
|
42
|
+
other_metrics = %w(ctxt processes procs_running procs_blocked btime intr)
|
43
|
+
cpu_count = 0
|
44
|
+
|
45
|
+
File.open('/proc/stat', 'r').each_line do |line|
|
46
|
+
info = line.split(/\s+/)
|
47
|
+
next if info.empty?
|
48
|
+
name = info.shift
|
49
|
+
|
50
|
+
if name.match(/cpu([0-9]+|)/)
|
51
|
+
# #YELLOW
|
52
|
+
cpu_count = cpu_count + 1 # rubocop:disable Style/SelfAssignment
|
53
|
+
name = 'total' if name == 'cpu'
|
54
|
+
info.size.times { |i| output "#{config[:scheme]}.#{name}.#{cpu_metrics[i]}", info[i] }
|
55
|
+
end
|
56
|
+
|
57
|
+
output "#{config[:scheme]}.#{name}", info.last if other_metrics.include? name
|
58
|
+
end
|
59
|
+
if cpu_count > 0
|
60
|
+
# writes the number of cpus, the minus 1 is because /proc/stat/
|
61
|
+
# first line is a "cpu" which is stats for total cpus
|
62
|
+
output "#{config[:scheme]}.cpu_count", cpu_count - 1
|
63
|
+
end
|
64
|
+
|
65
|
+
ok
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# System User Percentage Metric Plugin
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Produces Graphite output of sum of %CPU over all processes by user.
|
7
|
+
# E.g., if user joe is running two processes, each using 10% CPU, and
|
8
|
+
# jane is running one process using 50% CPU, output will be:
|
9
|
+
#
|
10
|
+
# joe 20.0 (timestamp)
|
11
|
+
# jane 50.0 (timestamp)
|
12
|
+
#
|
13
|
+
# OUTPUT:
|
14
|
+
# Graphite metric data.
|
15
|
+
#
|
16
|
+
# PLATFORMS:
|
17
|
+
# Linux, BSD, OS X
|
18
|
+
#
|
19
|
+
# DEPENDENCIES:
|
20
|
+
# gem: sensu-plugin
|
21
|
+
# gem: socket
|
22
|
+
#
|
23
|
+
# USAGE:
|
24
|
+
# ./user-pct-usage-metrics.rb --ignore_inactive true
|
25
|
+
# NOTES:
|
26
|
+
#
|
27
|
+
# LICENSE:
|
28
|
+
# John VanDyk <sensu@sysarchitects.com>
|
29
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
30
|
+
# for details.
|
31
|
+
#
|
32
|
+
|
33
|
+
require 'sensu-plugin/metric/cli'
|
34
|
+
require 'socket'
|
35
|
+
|
36
|
+
#
|
37
|
+
# User Percent
|
38
|
+
#
|
39
|
+
class UserPercent < Sensu::Plugin::Metric::CLI::Graphite
|
40
|
+
option :scheme,
|
41
|
+
description: 'Metric naming scheme prepended to .username',
|
42
|
+
long: '--scheme SCHEME',
|
43
|
+
default: "#{Socket.gethostname}.user_percent"
|
44
|
+
|
45
|
+
option :ignore_inactive,
|
46
|
+
description: 'Boolean. If true, ignore users using 0% CPU',
|
47
|
+
long: '--ignore_inactive',
|
48
|
+
default: true
|
49
|
+
|
50
|
+
def run # rubocop:disable all
|
51
|
+
timestamp = Time.now.to_i
|
52
|
+
pslist = `ps -A -o user= -o %cpu=`
|
53
|
+
|
54
|
+
users = {}
|
55
|
+
pslist.lines.each do |line|
|
56
|
+
user, value = line.split
|
57
|
+
h = { user => value.to_f }
|
58
|
+
users = users.merge(h) { |_key, oldval, newval| newval + oldval }
|
59
|
+
end
|
60
|
+
|
61
|
+
if config[:ignore_inactive]
|
62
|
+
users.delete_if { |_key, value| value == 0 }
|
63
|
+
end
|
64
|
+
|
65
|
+
users.each do |key, value|
|
66
|
+
output [config[:scheme], key].join('.'), value, timestamp
|
67
|
+
end
|
68
|
+
ok
|
69
|
+
end
|
70
|
+
end
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-cpu-checks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha.1
|
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-04-10 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.4'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.4'
|
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: '1.3'
|
126
|
+
type: :development
|
127
|
+
prerelease: false
|
128
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '1.3'
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: redcarpet
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '3.2'
|
140
|
+
type: :development
|
141
|
+
prerelease: false
|
142
|
+
version_requirements: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '3.2'
|
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.8'
|
154
|
+
type: :development
|
155
|
+
prerelease: false
|
156
|
+
version_requirements: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - "~>"
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0.8'
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
name: pry
|
163
|
+
requirement: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - "~>"
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0.10'
|
168
|
+
type: :development
|
169
|
+
prerelease: false
|
170
|
+
version_requirements: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - "~>"
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0.10'
|
175
|
+
description: Sensu plugins for cpu checks and metrics
|
176
|
+
email: "<sensu-users@googlegroups.com>"
|
177
|
+
executables: []
|
178
|
+
extensions: []
|
179
|
+
extra_rdoc_files: []
|
180
|
+
files:
|
181
|
+
- CHANGELOG.md
|
182
|
+
- LICENSE
|
183
|
+
- README.md
|
184
|
+
- bin/check-cpu.rb
|
185
|
+
- bin/check-cpu.sh
|
186
|
+
- bin/metrics-cpu-mpstat.rb
|
187
|
+
- bin/metrics-cpu-pcnt-usage.rb
|
188
|
+
- bin/metrics-cpu.rb
|
189
|
+
- bin/metrics-user-pct-usage.rb
|
190
|
+
- lib/sensu-plugins-cpu-checks.rb
|
191
|
+
homepage: https://github.com/sensu-plugins/sensu-plugins-cpu-checks
|
192
|
+
licenses:
|
193
|
+
- MIT
|
194
|
+
metadata:
|
195
|
+
maintainer: ''
|
196
|
+
development_status: unmaintained
|
197
|
+
production_status: unstable - testing recommended
|
198
|
+
post_install_message:
|
199
|
+
rdoc_options: []
|
200
|
+
require_paths:
|
201
|
+
- lib
|
202
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: 1.9.3
|
207
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - ">"
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: 1.3.1
|
212
|
+
requirements: []
|
213
|
+
rubyforge_project:
|
214
|
+
rubygems_version: 2.2.2
|
215
|
+
signing_key:
|
216
|
+
specification_version: 4
|
217
|
+
summary: Sensu plugins for cpu checks and metrics
|
218
|
+
test_files: []
|
219
|
+
has_rdoc:
|
metadata.gz.sig
ADDED
Binary file
|