metrics-load.rb
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/env ruby
# encoding: UTF-8
# <script name>
#
# DESCRIPTION:
# This plugin uses uptime to collect load metrics
# Basically copied from sensu-community-plugins/plugins/system/vmstat-metrics.rb
#
# Load per processor
# ------------------
#
# Optionally, with `--per-core`, this plugin will calculate load per
# processor from the raw load average by dividing load average by the number
# of processors.
#
# The number of CPUs is determined by reading `/proc/cpuinfo`. This makes the
# feature Linux specific. Other OSs can be supported by adding OS # detection
# and a method to determine the number of CPUs.
#
# OUTPUT:
# metric data
#
# PLATFORMS:
# Linux, BSD, Solaris, etc
#
# DEPENDENCIES:
# gem: sensu-plugin
# gem: socket
#
# USAGE:
#
# NOTES:
#
# LICENSE:
# Copyright 2012 Sonian, Inc <chefs@sonian.net>
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
#
require 'sensu-plugin/metric/cli'
require_relative '../lib/sensu-plugins-load-checks/load-average.rb'
require 'socket'
class LoadStat < Sensu::Plugin::Metric::CLI::Graphite
option :scheme,
description: 'Metric naming scheme, text to prepend to .$parent.$child',
long: '--scheme SCHEME',
default: Socket.gethostname.to_s
def run
data = LoadAverage.new
unknown 'Could not read load average from /proc or `uptime`' if data.failed?
timestamp = Time.now.to_i
metrics = {
load_avg: {
one: data.load_avg[0].round(2),
five: data.load_avg[1].round(2),
fifteen: data.load_avg[2].round(2)
}
}
metrics.each do |parent, children|
children.each do |child, value|
output [config[:scheme], parent, child].join('.'), value, timestamp
end
end
ok
end
end