baseline_red_agent 1.0.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
- data/.gitignore +2 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +58 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +6 -0
- data/baseline_red_agent.gemspec +32 -0
- data/exe/baseline_red_agent +7 -0
- data/init.rb +1 -0
- data/lib/baseline_red_agent/cli.rb +119 -0
- data/lib/baseline_red_agent/dispatcher.rb +88 -0
- data/lib/baseline_red_agent/logger.rb +24 -0
- data/lib/baseline_red_agent/plugin/base.rb +13 -0
- data/lib/baseline_red_agent/plugin/system/cpu.rb +34 -0
- data/lib/baseline_red_agent/plugin/system/disk.rb +24 -0
- data/lib/baseline_red_agent/plugin/system/load.rb +21 -0
- data/lib/baseline_red_agent/plugin/system/memory.rb +23 -0
- data/lib/baseline_red_agent/plugin/system/network.rb +22 -0
- data/lib/baseline_red_agent/plugin/system/processes.rb +44 -0
- data/lib/baseline_red_agent/plugin.rb +24 -0
- data/lib/baseline_red_agent/worker.rb +46 -0
- data/lib/baseline_red_agent.rb +41 -0
- metadata +164 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 55cbc1b65789089d4e200514c75a5e3ea723a6d9
|
|
4
|
+
data.tar.gz: b5aba5c71cda6915876c00be7c74fbeae68e2e00
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 262810e6e3b63af89e2f1404bd54472443a7989d1ca4109da78a2def33fe251c79287a6c1de727dbdc7e568ce2a233d7f468ab2502f2d4aa6d4065ef3b73f110
|
|
7
|
+
data.tar.gz: 22a38c6bbe0e371672c9c8f9217a4b685d5b73ee770e650f8b0f70e59d01f982feed0ed852108d3b20f22962a1f4cd196f9f91149e07b7ea2a00ab7a33ae4b46
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
baseline_red_agent (1.0.0)
|
|
5
|
+
msgpack
|
|
6
|
+
sys-proctable (= 1.2.1)
|
|
7
|
+
vmstat (= 2.3.0)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
coderay (1.1.1)
|
|
13
|
+
diff-lcs (1.3)
|
|
14
|
+
docile (1.1.5)
|
|
15
|
+
ffi (1.9.25)
|
|
16
|
+
json (2.1.0)
|
|
17
|
+
method_source (0.8.2)
|
|
18
|
+
msgpack (1.2.4)
|
|
19
|
+
pry (0.10.4)
|
|
20
|
+
coderay (~> 1.1.0)
|
|
21
|
+
method_source (~> 0.8.1)
|
|
22
|
+
slop (~> 3.4)
|
|
23
|
+
rake (12.0.0)
|
|
24
|
+
rspec (3.6.0)
|
|
25
|
+
rspec-core (~> 3.6.0)
|
|
26
|
+
rspec-expectations (~> 3.6.0)
|
|
27
|
+
rspec-mocks (~> 3.6.0)
|
|
28
|
+
rspec-core (3.6.0)
|
|
29
|
+
rspec-support (~> 3.6.0)
|
|
30
|
+
rspec-expectations (3.6.0)
|
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
32
|
+
rspec-support (~> 3.6.0)
|
|
33
|
+
rspec-mocks (3.6.0)
|
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
35
|
+
rspec-support (~> 3.6.0)
|
|
36
|
+
rspec-support (3.6.0)
|
|
37
|
+
simplecov (0.14.1)
|
|
38
|
+
docile (~> 1.1.0)
|
|
39
|
+
json (>= 1.8, < 3)
|
|
40
|
+
simplecov-html (~> 0.10.0)
|
|
41
|
+
simplecov-html (0.10.1)
|
|
42
|
+
slop (3.6.0)
|
|
43
|
+
sys-proctable (1.2.1)
|
|
44
|
+
ffi
|
|
45
|
+
vmstat (2.3.0)
|
|
46
|
+
|
|
47
|
+
PLATFORMS
|
|
48
|
+
ruby
|
|
49
|
+
|
|
50
|
+
DEPENDENCIES
|
|
51
|
+
baseline_red_agent!
|
|
52
|
+
pry (= 0.10.4)
|
|
53
|
+
rake (= 12.0.0)
|
|
54
|
+
rspec (= 3.6.0)
|
|
55
|
+
simplecov (= 0.14.1)
|
|
56
|
+
|
|
57
|
+
BUNDLED WITH
|
|
58
|
+
1.16.3
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Randy Girard
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#-*- coding: utf-8 -*-
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "baseline_red_agent"
|
|
7
|
+
s.version = "1.0.1"
|
|
8
|
+
s.date = "2018-11-24"
|
|
9
|
+
s.summary = "Baseline Red Agent"
|
|
10
|
+
s.description = "Agent for Baseline Red."
|
|
11
|
+
s.authors = ["Jim Jones"]
|
|
12
|
+
s.email = "jim@baseline.red"
|
|
13
|
+
|
|
14
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
15
|
+
f.match(%r{^(test|spec|features)/})
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
s.bindir = "exe"
|
|
19
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
s.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
s.homepage = "https://baseline.red"
|
|
23
|
+
s.license = "MIT"
|
|
24
|
+
|
|
25
|
+
s.add_development_dependency "rake", "12.0.0"
|
|
26
|
+
s.add_development_dependency "rspec", "3.6.0"
|
|
27
|
+
s.add_development_dependency "pry", "0.10.4"
|
|
28
|
+
s.add_development_dependency "simplecov", "0.14.1"
|
|
29
|
+
s.add_runtime_dependency "msgpack"
|
|
30
|
+
s.add_runtime_dependency "vmstat", "2.3.0"
|
|
31
|
+
s.add_runtime_dependency "sys-proctable", "1.2.1"
|
|
32
|
+
end
|
data/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require_relative'./lib/agent'
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
$stdout.sync = true
|
|
2
|
+
|
|
3
|
+
require 'singleton'
|
|
4
|
+
require 'optparse'
|
|
5
|
+
|
|
6
|
+
require_relative '../baseline_red_agent'
|
|
7
|
+
|
|
8
|
+
module BaselineRedAgent
|
|
9
|
+
class CLI
|
|
10
|
+
include Singleton unless $TESTING
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def parse(args=ARGV)
|
|
16
|
+
setup_options(args)
|
|
17
|
+
daemonize
|
|
18
|
+
write_pid
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def run
|
|
22
|
+
worker = BaselineRedAgent::Worker.new
|
|
23
|
+
worker.load_plugins
|
|
24
|
+
|
|
25
|
+
begin
|
|
26
|
+
BaselineRedAgent.logger.info "Starting BaselineRedAgent."
|
|
27
|
+
worker.start
|
|
28
|
+
|
|
29
|
+
while readable_io = IO.select([self_read])
|
|
30
|
+
signal = readable_io.first[0].gets.strip
|
|
31
|
+
handle_signal(signal)
|
|
32
|
+
end
|
|
33
|
+
rescue Interrupt
|
|
34
|
+
BaselineRedAgent.logger.info "Shutting down BaselineRedAgent."
|
|
35
|
+
worker.stop
|
|
36
|
+
exit(0)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def handle_signal(sig)
|
|
41
|
+
case sig
|
|
42
|
+
when 'INT'
|
|
43
|
+
raise Interrupt
|
|
44
|
+
when 'TERM'
|
|
45
|
+
raise Interrupt
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def options
|
|
50
|
+
BaselineRedAgent.options
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def daemonize
|
|
56
|
+
return unless options[:daemon]
|
|
57
|
+
|
|
58
|
+
::Process.daemon(true, true)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def setup_options(args)
|
|
62
|
+
opts = parse_options(args)
|
|
63
|
+
options.merge!(opts)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def parse_options(argv)
|
|
67
|
+
opts = {}
|
|
68
|
+
|
|
69
|
+
parser = OptionParser.new do |o|
|
|
70
|
+
o.banner = "baseline_red_agent [options]"
|
|
71
|
+
|
|
72
|
+
o.on '-d', '--daemon', "Daemonize process" do |arg|
|
|
73
|
+
opts[:daemon] = arg
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
o.on '-l', '--license-key LICENSE_KEY', "License Key" do |arg|
|
|
77
|
+
opts[:license_key] = arg
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
o.on '--host HOST', 'Baseline Red Host' do |arg|
|
|
81
|
+
opts[:host] = arg
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
o.on '--ssl', 'Enable SSL To App Perf' do |arg|
|
|
85
|
+
opts[:ssl] = arg
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
o.on '-v', '--verbose', 'Enable verbose logging' do |arg|
|
|
89
|
+
BaselineRedAgent.logger.level = ::Logger::DEBUG
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
o.on_tail "-h", "--help", "Show help" do
|
|
93
|
+
puts o
|
|
94
|
+
exit
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
parser.parse!(argv)
|
|
99
|
+
|
|
100
|
+
if opts[:license_key].to_s.length == 0
|
|
101
|
+
BaselineRedAgent.logger.info "No license key specified. Exiting."
|
|
102
|
+
exit 1
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
BaselineRedAgent.logger.info "Initializing with options: #{opts}"
|
|
106
|
+
|
|
107
|
+
opts
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def write_pid
|
|
111
|
+
if path = options[:pidfile]
|
|
112
|
+
pidfile = File.expand_path(path)
|
|
113
|
+
File.open(pidfile, 'w') do |f|
|
|
114
|
+
f.puts ::Process.pid
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'msgpack'
|
|
3
|
+
require 'base64'
|
|
4
|
+
|
|
5
|
+
module BaselineRedAgent
|
|
6
|
+
class Dispatcher
|
|
7
|
+
def initialize
|
|
8
|
+
@start_time = Time.now
|
|
9
|
+
@queue = Queue.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add_event(event)
|
|
13
|
+
@queue << event
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def queue_empty?
|
|
17
|
+
@queue.size.to_i == 0
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def dispatch_interval
|
|
21
|
+
30
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def ready?
|
|
25
|
+
Time.now > @start_time + dispatch_interval.to_f && !queue_empty?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def reset
|
|
29
|
+
@queue.clear
|
|
30
|
+
@start_time = Time.now
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def dispatch
|
|
34
|
+
begin
|
|
35
|
+
events = drain(@queue)
|
|
36
|
+
dispatch_events(events.dup)
|
|
37
|
+
rescue => ex
|
|
38
|
+
::BaselineRedAgent.logger.error "#{ex.inspect}"
|
|
39
|
+
::BaselineRedAgent.logger.error "#{ex.backtrace.inspect}"
|
|
40
|
+
ensure
|
|
41
|
+
reset
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def dispatch_events(data)
|
|
48
|
+
if data && data.length > 0
|
|
49
|
+
uri = URI(url)
|
|
50
|
+
|
|
51
|
+
sock = Net::HTTP.new(uri.host, uri.port)
|
|
52
|
+
sock.use_ssl = BaselineRedAgent.options[:ssl]
|
|
53
|
+
|
|
54
|
+
req = Net::HTTP::Post.new(uri.path, { "Content-Type" => "application/json", "Accept-Encoding" => "gzip", "User-Agent" => "gzip" })
|
|
55
|
+
req.body = compress_body(data)
|
|
56
|
+
req.content_type = "application/octet-stream"
|
|
57
|
+
|
|
58
|
+
res = sock.start do |http|
|
|
59
|
+
http.read_timeout = 30
|
|
60
|
+
http.request(req)
|
|
61
|
+
end
|
|
62
|
+
data.clear
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def compress_body(data)
|
|
67
|
+
body = MessagePack.pack({
|
|
68
|
+
"host" => BaselineRedAgent.hostname,
|
|
69
|
+
"data" => data
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
compressed_body = Zlib::Deflate.deflate(body, Zlib::DEFAULT_COMPRESSION)
|
|
73
|
+
Base64.encode64(compressed_body)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def drain(queue)
|
|
77
|
+
Array.new(queue.size) { queue.pop }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def protocol
|
|
81
|
+
@protocol ||= BaselineRedAgent.options[:ssl] ? "https" : "http"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def url
|
|
85
|
+
@url ||= "#{protocol}://#{BaselineRedAgent.options[:host] || "baseline.red"}/api/listener/2/#{BaselineRedAgent.options[:license_key]}"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
|
|
3
|
+
module BaselineRedAgent
|
|
4
|
+
class Logger
|
|
5
|
+
def self.initialize_logger(log_target = STDOUT)
|
|
6
|
+
oldlogger = defined?(@logger) ? @logger : nil
|
|
7
|
+
@logger = ::Logger.new(log_target)
|
|
8
|
+
@logger.level = ::Logger::INFO
|
|
9
|
+
@logger
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.logger
|
|
13
|
+
defined?(@logger) ? @logger : initialize_logger
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.logger=(log)
|
|
17
|
+
@logger = (log ? log : ::Logger.new(File::NULL))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def logger
|
|
21
|
+
BaselineRedAgent::Logger.logger
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require "vmstat"
|
|
2
|
+
require_relative "../base"
|
|
3
|
+
|
|
4
|
+
module BaselineRedAgent
|
|
5
|
+
module Plugin
|
|
6
|
+
module System
|
|
7
|
+
class Cpu < BaselineRedAgent::Plugin::Base
|
|
8
|
+
attr_accessor :last
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
self.last = Vmstat.snapshot.cpus
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def call
|
|
16
|
+
cpus = Vmstat.snapshot.cpus
|
|
17
|
+
metrics = cpus.each_with_index.flat_map {|cpu, index|
|
|
18
|
+
total = (cpu.idle + cpu.nice + cpu.system + cpu.user) - (last[index].idle + last[index].nice + last[index].system + last[index].user)
|
|
19
|
+
[
|
|
20
|
+
["system.cpu.idle", (cpu.idle - last[index].idle).to_f / total.to_f * 100.to_f, { "num" => cpu.num }],
|
|
21
|
+
["system.cpu.nice", (cpu.nice - last[index].nice).to_f / total.to_f * 100.to_f, { "num" => cpu.num }],
|
|
22
|
+
["system.cpu.system", (cpu.system - last[index].system).to_f / total.to_f * 100.to_f, { "num" => cpu.num }],
|
|
23
|
+
["system.cpu.user", (cpu.user - last[index].user).to_f / total.to_f * 100.to_f, { "num" => cpu.num }]
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
self.last = cpus
|
|
27
|
+
metrics
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
BaselineRedAgent.logger.info "Loading CPU monitoring."
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require "vmstat"
|
|
2
|
+
require_relative "../base"
|
|
3
|
+
|
|
4
|
+
module BaselineRedAgent
|
|
5
|
+
module Plugin
|
|
6
|
+
module System
|
|
7
|
+
class Disk < BaselineRedAgent::Plugin::Base
|
|
8
|
+
def call
|
|
9
|
+
disks = Vmstat.snapshot.disks
|
|
10
|
+
disks.flat_map {|disk|
|
|
11
|
+
[
|
|
12
|
+
["system.disk.used_bytes", disk.used_bytes, { "origin" => disk.origin, "type" => disk.type, "mount" => disk.mount }],
|
|
13
|
+
["system.disk.free_bytes", disk.free_bytes, { "origin" => disk.origin, "type" => disk.type, "mount" => disk.mount }],
|
|
14
|
+
["system.disk.available_bytes", disk.available_bytes, { "origin" => disk.origin, "type" => disk.type, "mount" => disk.mount }],
|
|
15
|
+
["system.disk.total_bytes", disk.total_bytes, { "origin" => disk.origin, "type" => disk.type, "mount" => disk.mount }]
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
BaselineRedAgent.logger.info "Loading Disk monitoring."
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "vmstat"
|
|
2
|
+
require_relative "../base"
|
|
3
|
+
|
|
4
|
+
module BaselineRedAgent
|
|
5
|
+
module Plugin
|
|
6
|
+
module System
|
|
7
|
+
class Load < BaselineRedAgent::Plugin::Base
|
|
8
|
+
def call
|
|
9
|
+
loads = Vmstat.load_average
|
|
10
|
+
[
|
|
11
|
+
["system.load.one_minute", loads.one_minute],
|
|
12
|
+
["system.load.five_minute", loads.five_minutes],
|
|
13
|
+
["system.load.fifteen_minute", loads.fifteen_minutes]
|
|
14
|
+
]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
BaselineRedAgent.logger.info "Loading Load monitoring."
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'vmstat'
|
|
2
|
+
require_relative "../base"
|
|
3
|
+
|
|
4
|
+
module BaselineRedAgent
|
|
5
|
+
module Plugin
|
|
6
|
+
module System
|
|
7
|
+
class Memory < BaselineRedAgent::Plugin::Base
|
|
8
|
+
def call
|
|
9
|
+
memory = Vmstat.memory
|
|
10
|
+
[
|
|
11
|
+
["system.memory.free_bytes", memory.free_bytes],
|
|
12
|
+
["system.memory.inactive_bytes", memory.inactive_bytes],
|
|
13
|
+
["system.memory.active_bytes", memory.active_bytes],
|
|
14
|
+
["system.memory.wired_bytes", memory.wired_bytes],
|
|
15
|
+
["system.memory.total_bytes", memory.total_bytes]
|
|
16
|
+
]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
BaselineRedAgent.logger.info "Loading Memory monitoring."
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "vmstat"
|
|
2
|
+
require_relative "../base"
|
|
3
|
+
|
|
4
|
+
module BaselineRedAgent
|
|
5
|
+
module Plugin
|
|
6
|
+
module System
|
|
7
|
+
class Network < BaselineRedAgent::Plugin::Base
|
|
8
|
+
def call
|
|
9
|
+
inets = Vmstat.ethernet_devices
|
|
10
|
+
inets.flat_map {|inet|
|
|
11
|
+
[
|
|
12
|
+
["system.network.in_bytes", inet.in_bytes, { "name" => inet.name.to_s }],
|
|
13
|
+
["system.network.out_bytes", inet.out_bytes, { "name" => inet.name.to_s }]
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
BaselineRedAgent.logger.info "Loading Network monitoring."
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require_relative "../base"
|
|
2
|
+
require 'sys/proctable'
|
|
3
|
+
|
|
4
|
+
module BaselineRedAgent
|
|
5
|
+
module Plugin
|
|
6
|
+
module System
|
|
7
|
+
class Processes < BaselineRedAgent::Plugin::Base
|
|
8
|
+
include Sys
|
|
9
|
+
|
|
10
|
+
ALLOWED_PROCESSES_REGEX = /(ruby|puma|passenger|unicorn)/i
|
|
11
|
+
|
|
12
|
+
def call
|
|
13
|
+
items = []
|
|
14
|
+
|
|
15
|
+
ProcTable.ps.each do |process|
|
|
16
|
+
next unless process.comm =~ ALLOWED_PROCESSES_REGEX
|
|
17
|
+
|
|
18
|
+
items << ["system.processes.rss", process.respond_to?(:pctmem) ? process.pctmem : 0,
|
|
19
|
+
{ "name" => "#{BaselineRedAgent.options[:host]} - #{process.comm} (#{process.pid.to_s})" ,
|
|
20
|
+
"process" => {
|
|
21
|
+
"name" => process.name,
|
|
22
|
+
"pid" => process.pid.to_s,
|
|
23
|
+
"command_line" => process.comm,
|
|
24
|
+
}
|
|
25
|
+
}]
|
|
26
|
+
|
|
27
|
+
items << ["system.processes.cpu", process.respond_to?(:pctcpu) ? process.pctcpu : 0,
|
|
28
|
+
{ "name" => "#{BaselineRedAgent.options[:host]} - #{process.comm} (#{process.pid.to_s})",
|
|
29
|
+
"process" => {
|
|
30
|
+
"name" => process.name,
|
|
31
|
+
"pid" => process.pid.to_s,
|
|
32
|
+
"command_line" => process.comm,
|
|
33
|
+
}
|
|
34
|
+
}]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
items
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
BaselineRedAgent.logger.info "Loading Process monitoring."
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module BaselineRedAgent
|
|
2
|
+
module Plugin
|
|
3
|
+
class << self
|
|
4
|
+
def load_plugins
|
|
5
|
+
pattern = File.join(File.dirname(__FILE__), 'plugin', '**', '*.rb')
|
|
6
|
+
|
|
7
|
+
Dir.glob(pattern) do |f|
|
|
8
|
+
begin
|
|
9
|
+
require f
|
|
10
|
+
rescue => e
|
|
11
|
+
BaselineRedAgent.logger.info "Error loading plugin '#{f}' : #{e}"
|
|
12
|
+
BaselineRedAgent.logger.info "#{e.backtrace.first}"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def plugins
|
|
18
|
+
@plugins ||= ::BaselineRedAgent::Plugin::Base
|
|
19
|
+
.descendants
|
|
20
|
+
.map(&:new)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module BaselineRedAgent
|
|
2
|
+
class Worker
|
|
3
|
+
def initialize
|
|
4
|
+
@running = false
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def load_plugins
|
|
8
|
+
BaselineRedAgent::Plugin.load_plugins
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def dispatcher
|
|
12
|
+
@dispatcher ||= BaselineRedAgent::Dispatcher.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def stop
|
|
16
|
+
@running = false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def start
|
|
20
|
+
@running = true
|
|
21
|
+
|
|
22
|
+
while @running
|
|
23
|
+
collect if dispatcher.queue_empty?
|
|
24
|
+
|
|
25
|
+
if dispatcher.ready?
|
|
26
|
+
dispatcher.dispatch
|
|
27
|
+
dispatcher.reset
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
sleep 1
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def collect
|
|
35
|
+
BaselineRedAgent::Plugin.plugins.each do |plugin|
|
|
36
|
+
items = plugin.call
|
|
37
|
+
items.map {|i| BaselineRedAgent.logger.debug i }
|
|
38
|
+
Array(items).each do |item|
|
|
39
|
+
key, value, tags = item
|
|
40
|
+
metric = ["metric", Time.now.to_f, key, value, tags || {}]
|
|
41
|
+
dispatcher.add_event(metric)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require_relative "baseline_red_agent/logger"
|
|
2
|
+
require_relative "baseline_red_agent/plugin"
|
|
3
|
+
require_relative "baseline_red_agent/dispatcher"
|
|
4
|
+
require_relative "baseline_red_agent/worker"
|
|
5
|
+
|
|
6
|
+
module BaselineRedAgent
|
|
7
|
+
DEFAULTS = {
|
|
8
|
+
environment: nil,
|
|
9
|
+
daemon: false,
|
|
10
|
+
host: 'localhost:5000',
|
|
11
|
+
ssl: false,
|
|
12
|
+
license_key: '',
|
|
13
|
+
pidfile: File.dirname(__FILE__) + "/../baseline_red_agent.pid"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
def self.hostname
|
|
17
|
+
@hostname ||= Socket.gethostname
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.options
|
|
21
|
+
@options ||= DEFAULTS.dup
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.options=(opts)
|
|
25
|
+
@options = opts
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.logger
|
|
29
|
+
BaselineRedAgent::Logger.logger
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.logger=(log)
|
|
33
|
+
BaselineRedAgent::Logger.logger = log
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class << self
|
|
37
|
+
def load
|
|
38
|
+
BaselineRedAgent::Agent::Plugin.load_plugins
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: baseline_red_agent
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jim Jones
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-11-24 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rake
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 12.0.0
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 12.0.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 3.6.0
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 3.6.0
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: pry
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.10.4
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.10.4
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: simplecov
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.14.1
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.14.1
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: msgpack
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :runtime
|
|
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: vmstat
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - '='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 2.3.0
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - '='
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 2.3.0
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: sys-proctable
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - '='
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: 1.2.1
|
|
104
|
+
type: :runtime
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - '='
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: 1.2.1
|
|
111
|
+
description: Agent for Baseline Red.
|
|
112
|
+
email: jim@baseline.red
|
|
113
|
+
executables:
|
|
114
|
+
- baseline_red_agent
|
|
115
|
+
extensions: []
|
|
116
|
+
extra_rdoc_files: []
|
|
117
|
+
files:
|
|
118
|
+
- ".gitignore"
|
|
119
|
+
- Gemfile
|
|
120
|
+
- Gemfile.lock
|
|
121
|
+
- LICENSE
|
|
122
|
+
- README.md
|
|
123
|
+
- Rakefile
|
|
124
|
+
- baseline_red_agent.gemspec
|
|
125
|
+
- exe/baseline_red_agent
|
|
126
|
+
- init.rb
|
|
127
|
+
- lib/baseline_red_agent.rb
|
|
128
|
+
- lib/baseline_red_agent/cli.rb
|
|
129
|
+
- lib/baseline_red_agent/dispatcher.rb
|
|
130
|
+
- lib/baseline_red_agent/logger.rb
|
|
131
|
+
- lib/baseline_red_agent/plugin.rb
|
|
132
|
+
- lib/baseline_red_agent/plugin/base.rb
|
|
133
|
+
- lib/baseline_red_agent/plugin/system/cpu.rb
|
|
134
|
+
- lib/baseline_red_agent/plugin/system/disk.rb
|
|
135
|
+
- lib/baseline_red_agent/plugin/system/load.rb
|
|
136
|
+
- lib/baseline_red_agent/plugin/system/memory.rb
|
|
137
|
+
- lib/baseline_red_agent/plugin/system/network.rb
|
|
138
|
+
- lib/baseline_red_agent/plugin/system/processes.rb
|
|
139
|
+
- lib/baseline_red_agent/worker.rb
|
|
140
|
+
homepage: https://baseline.red
|
|
141
|
+
licenses:
|
|
142
|
+
- MIT
|
|
143
|
+
metadata: {}
|
|
144
|
+
post_install_message:
|
|
145
|
+
rdoc_options: []
|
|
146
|
+
require_paths:
|
|
147
|
+
- lib
|
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
|
+
requirements:
|
|
155
|
+
- - ">="
|
|
156
|
+
- !ruby/object:Gem::Version
|
|
157
|
+
version: '0'
|
|
158
|
+
requirements: []
|
|
159
|
+
rubyforge_project:
|
|
160
|
+
rubygems_version: 2.6.13
|
|
161
|
+
signing_key:
|
|
162
|
+
specification_version: 4
|
|
163
|
+
summary: Baseline Red Agent
|
|
164
|
+
test_files: []
|