sensu-extensions-system-profile 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/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/lib/sensu/extensions/system-profile.rb +193 -0
- data/sensu-extensions-system-profile.gemspec +23 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e7a45c7bde551239aae561b97017e37a491a882b
|
4
|
+
data.tar.gz: b68d4d7a92fb08776491d9134a6ec26cd964ff50
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2464a7ea2bcc87450a73cc70908752e02e5713348bee91684b61d5eea19a9c78e55c0b45ef0dc07f4de7934f8f9018a6ba18e5c10a09ca3706a4adcf60da1a3c
|
7
|
+
data.tar.gz: bec279ff735f5ba1762f6e362b2f8dce5e9bf715c86c092cf04d1883844e40aa658665ea1c8de73cc353dac505e5fe792caf201ca9f5739c1a7ed1bf419b987c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Sensu::Extensions::Only::Check::Output
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sensu/extensions/only/check/output`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'sensu-extensions-only-check-output'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sensu-extensions-only-check-output
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sensu-extensions-only-check-output.
|
36
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
require "sensu/extension"
|
2
|
+
|
3
|
+
module Sensu
|
4
|
+
module Extension
|
5
|
+
class SystemProfile < Check
|
6
|
+
def name
|
7
|
+
'system_profile'
|
8
|
+
end
|
9
|
+
|
10
|
+
def description
|
11
|
+
'collects system metrics, using the graphite plain-text format'
|
12
|
+
end
|
13
|
+
|
14
|
+
def definition
|
15
|
+
{
|
16
|
+
type: 'metric',
|
17
|
+
name: name,
|
18
|
+
interval: options[:interval],
|
19
|
+
standalone: true,
|
20
|
+
handler: options[:handler]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def post_init
|
25
|
+
@metrics = []
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
proc_stat_metrics do
|
30
|
+
proc_loadavg_metrics do
|
31
|
+
proc_net_dev_metrics do
|
32
|
+
proc_meminfo_metrics do
|
33
|
+
yield flush_metrics, 0
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def options
|
43
|
+
return @options if @options
|
44
|
+
@options = {
|
45
|
+
interval: 10,
|
46
|
+
handler: 'graphite',
|
47
|
+
add_client_prefix: true,
|
48
|
+
path_prefix: 'system',
|
49
|
+
prefix_at_start: 0
|
50
|
+
}
|
51
|
+
if settings[:system_profile].is_a?(Hash)
|
52
|
+
@options.merge!(settings[:system_profile])
|
53
|
+
end
|
54
|
+
@options
|
55
|
+
end
|
56
|
+
|
57
|
+
def flush_metrics
|
58
|
+
metrics = @metrics.join("\n") + "\n"
|
59
|
+
@metrics = []
|
60
|
+
metrics
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_metric(*args)
|
64
|
+
value = args.pop
|
65
|
+
path = []
|
66
|
+
path << options[:path_prefix] if options[:prefix_at_start]
|
67
|
+
path << settings[:client][:name] if options[:add_client_prefix]
|
68
|
+
path << options[:path_prefix] unless options[:prefix_at_start]
|
69
|
+
path = (path + args).join('.')
|
70
|
+
@metrics << [path, value, Time.now.to_i].join(' ')
|
71
|
+
end
|
72
|
+
|
73
|
+
def read_file(file_path, chunk_size = nil)
|
74
|
+
content = ''
|
75
|
+
File.open(file_path, 'r') do |file|
|
76
|
+
read_chunk = proc do
|
77
|
+
content << file.read(chunk_size)
|
78
|
+
# #YELLOW
|
79
|
+
unless file.eof? # rubocop:disable UnlessElse
|
80
|
+
EM.next_tick(read_chunk)
|
81
|
+
else
|
82
|
+
yield content
|
83
|
+
end
|
84
|
+
end
|
85
|
+
read_chunk.call
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def parse_proc_stat
|
90
|
+
sample = {}
|
91
|
+
cpu_metrics = %w(user nice system idle iowait irq softirq steal guest)
|
92
|
+
misc_metrics = %w(ctxt processes procs_running procs_blocked btime intr)
|
93
|
+
read_file('/proc/stat') do |proc_stat|
|
94
|
+
proc_stat.each_line do |line|
|
95
|
+
next if line.empty?
|
96
|
+
data = line.split(/\s+/)
|
97
|
+
key = data.shift
|
98
|
+
values = data.map(&:to_i)
|
99
|
+
if key =~ /cpu([0-9]+|)/
|
100
|
+
sample[key] = Hash[cpu_metrics.zip(values)]
|
101
|
+
sample[key]['total'] = values.inject(:+)
|
102
|
+
elsif misc_metrics.include?(key)
|
103
|
+
sample[key] = values.last
|
104
|
+
end
|
105
|
+
end
|
106
|
+
yield sample
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def proc_stat_metrics
|
111
|
+
parse_proc_stat do |previous|
|
112
|
+
EM::Timer.new(1) do
|
113
|
+
parse_proc_stat do |sample|
|
114
|
+
sample.each do |key, data|
|
115
|
+
if key =~ /^cpu/
|
116
|
+
cpu_total_diff = (data.delete('total') - previous[key]['total']) + 1
|
117
|
+
data.each do |metric, value|
|
118
|
+
next if value.nil?
|
119
|
+
diff = value - previous[key][metric]
|
120
|
+
used = sprintf('%.02f', (diff / cpu_total_diff.to_f) * 100)
|
121
|
+
add_metric(key, metric, used)
|
122
|
+
end
|
123
|
+
else
|
124
|
+
add_metric(key, data)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
yield
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def proc_loadavg_metrics
|
134
|
+
read_file('/proc/loadavg') do |proc_loadavg|
|
135
|
+
values = proc_loadavg.split(/\s+/).take(3).map(&:to_f)
|
136
|
+
add_metric('load_avg', '1_min', values[0])
|
137
|
+
add_metric('load_avg', '5_min', values[1])
|
138
|
+
add_metric('load_avg', '15_min', values[2])
|
139
|
+
yield
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def proc_net_dev_metrics
|
144
|
+
dev_metrics = %w(rxBytes
|
145
|
+
rxPackets
|
146
|
+
rxErrors
|
147
|
+
rxDrops
|
148
|
+
rxFifo
|
149
|
+
rxFrame
|
150
|
+
rxCompressed
|
151
|
+
rxMulticast
|
152
|
+
txBytes
|
153
|
+
txPackets
|
154
|
+
txErrors
|
155
|
+
txDrops
|
156
|
+
txFifo
|
157
|
+
txColls
|
158
|
+
txCarrier
|
159
|
+
txCompressed)
|
160
|
+
read_file('/proc/net/dev') do |proc_net_dev|
|
161
|
+
proc_net_dev.each_line do |line|
|
162
|
+
interface, data = line.scan(/^\s*([^:]+):\s*(.*)$/).first
|
163
|
+
next unless interface
|
164
|
+
values = data.split(/\s+/).map(&:to_i)
|
165
|
+
Hash[dev_metrics.zip(values)].each do |key, value|
|
166
|
+
add_metric('net', interface, key.downcase, value)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
yield
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def proc_meminfo_metrics
|
174
|
+
read_file('/proc/meminfo') do |proc_meminfo|
|
175
|
+
proc_meminfo.each_line do |line|
|
176
|
+
next if line.strip.empty?
|
177
|
+
root, data = line.split(':')
|
178
|
+
values = data.strip.split(/\s+/).map(&:to_i)
|
179
|
+
case root
|
180
|
+
when /Mem\w+/, 'Buffers', 'Cached', 'Active', 'Committed_AS'
|
181
|
+
key = root.gsub(/^Mem/, '').downcase
|
182
|
+
add_metric('memory', key, values.first)
|
183
|
+
when /Swap\w+/
|
184
|
+
key = root.gsub(/^Swap/, '').downcase
|
185
|
+
add_metric('swap', key, values.first)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
yield
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "sensu-extensions-system-profile"
|
5
|
+
spec.version = "0.0.1"
|
6
|
+
spec.authors = ["Sean Porter"]
|
7
|
+
spec.email = ["portertech@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "Check extension to collect Linux system metrics"
|
10
|
+
spec.description = "Check extension to collect Linux system metrics"
|
11
|
+
spec.homepage = "https://github.com/sensu-extensions/sensu-extensions-system-profile"
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_dependency "sensu-extension"
|
17
|
+
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
19
|
+
spec.add_development_dependency "rake"
|
20
|
+
spec.add_development_dependency "rspec"
|
21
|
+
spec.add_development_dependency "sensu-logger"
|
22
|
+
spec.add_development_dependency "sensu-settings"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-extensions-system-profile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Porter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sensu-extension
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sensu-logger
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sensu-settings
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Check extension to collect Linux system metrics
|
98
|
+
email:
|
99
|
+
- portertech@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- lib/sensu/extensions/system-profile.rb
|
109
|
+
- sensu-extensions-system-profile.gemspec
|
110
|
+
homepage: https://github.com/sensu-extensions/sensu-extensions-system-profile
|
111
|
+
licenses: []
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.6.3
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Check extension to collect Linux system metrics
|
133
|
+
test_files: []
|