app_perf_agent 0.0.2
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 +54 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +6 -0
- data/app_perf_agent.gemspec +31 -0
- data/exe/app_perf_agent +7 -0
- data/init.rb +1 -0
- data/lib/app_perf_agent/cli.rb +119 -0
- data/lib/app_perf_agent/dispatcher.rb +84 -0
- data/lib/app_perf_agent/logger.rb +24 -0
- data/lib/app_perf_agent/plugin/base.rb +13 -0
- data/lib/app_perf_agent/plugin/system/cpu.rb +43 -0
- data/lib/app_perf_agent/plugin/system/disk.rb +43 -0
- data/lib/app_perf_agent/plugin/system/load.rb +35 -0
- data/lib/app_perf_agent/plugin/system/memory.rb +47 -0
- data/lib/app_perf_agent/plugin/system/network.rb +31 -0
- data/lib/app_perf_agent/plugin.rb +24 -0
- data/lib/app_perf_agent/types.rb +10 -0
- data/lib/app_perf_agent/worker.rb +50 -0
- data/lib/app_perf_agent.rb +42 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f295019686c69babe601314425a9e226c7019cd5
|
4
|
+
data.tar.gz: 3b293e621e7a75606fe918fdf0322b7aa6a6eefb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aca278899b069347ed29dea4ae576ac44d35885544a1be97217e059db688a67d8e839bc1db788954c503ff9fb7d624c381aa0fb818f25a9fd0b0d62522c109ff
|
7
|
+
data.tar.gz: e68a0c954e35a1e611c2a2f3bd11ff2422803303ecda8f8f96ef01e30ff18ff9e8e02cc8928d38e05dc76b5987f2e637b9196f2787eae30d796d5773e56efe88
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
app_perf_agent (0.0.1)
|
5
|
+
oj (= 3.3.2)
|
6
|
+
vmstat (= 2.3.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.1)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
docile (1.1.5)
|
14
|
+
json (2.1.0)
|
15
|
+
method_source (0.8.2)
|
16
|
+
oj (3.3.2)
|
17
|
+
pry (0.10.4)
|
18
|
+
coderay (~> 1.1.0)
|
19
|
+
method_source (~> 0.8.1)
|
20
|
+
slop (~> 3.4)
|
21
|
+
rake (12.0.0)
|
22
|
+
rspec (3.6.0)
|
23
|
+
rspec-core (~> 3.6.0)
|
24
|
+
rspec-expectations (~> 3.6.0)
|
25
|
+
rspec-mocks (~> 3.6.0)
|
26
|
+
rspec-core (3.6.0)
|
27
|
+
rspec-support (~> 3.6.0)
|
28
|
+
rspec-expectations (3.6.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.6.0)
|
31
|
+
rspec-mocks (3.6.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.6.0)
|
34
|
+
rspec-support (3.6.0)
|
35
|
+
simplecov (0.14.1)
|
36
|
+
docile (~> 1.1.0)
|
37
|
+
json (>= 1.8, < 3)
|
38
|
+
simplecov-html (~> 0.10.0)
|
39
|
+
simplecov-html (0.10.1)
|
40
|
+
slop (3.6.0)
|
41
|
+
vmstat (2.3.0)
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
app_perf_agent!
|
48
|
+
pry (= 0.10.4)
|
49
|
+
rake (= 12.0.0)
|
50
|
+
rspec (= 3.6.0)
|
51
|
+
simplecov (= 0.14.1)
|
52
|
+
|
53
|
+
BUNDLED WITH
|
54
|
+
1.15.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,31 @@
|
|
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 = "app_perf_agent"
|
7
|
+
s.version = "0.0.2"
|
8
|
+
s.date = "2017-07-24"
|
9
|
+
s.summary = "AppPerf Agent"
|
10
|
+
s.description = "Agent for the AppPerf app."
|
11
|
+
s.authors = ["Randy Girard"]
|
12
|
+
s.email = "rgirard59@yahoo.com"
|
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://www.github.com/randy-girard/app_perf_agent"
|
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 "oj", "3.3.2"
|
30
|
+
s.add_runtime_dependency "vmstat", "2.3.0"
|
31
|
+
end
|
data/exe/app_perf_agent
ADDED
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 '../app_perf_agent'
|
7
|
+
|
8
|
+
module AppPerfAgent
|
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 = AppPerfAgent::Worker.new
|
23
|
+
worker.load_plugins
|
24
|
+
|
25
|
+
begin
|
26
|
+
AppPerfAgent.logger.info "Starting AppPerfAgent."
|
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
|
+
AppPerfAgent.logger.info "Shutting down AppPerfAgent."
|
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
|
+
AppPerfAgent.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 = "app_perf_agent [options]"
|
71
|
+
|
72
|
+
o.on '-f', '--foreground', "Daemonize process" do |arg|
|
73
|
+
opts[:daemon] = false
|
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', 'App Perf Host' do |arg|
|
81
|
+
opts[:host] = arg
|
82
|
+
end
|
83
|
+
|
84
|
+
o.on '--ssl', 'Enable SSL To App Perf' do |arg|
|
85
|
+
opts[:ssl] = true
|
86
|
+
end
|
87
|
+
|
88
|
+
o.on '-v', '--verbose', 'Enable verbose logging' do |arg|
|
89
|
+
AppPerfAgent.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
|
+
AppPerfAgent.logger.info "No license key specified. Exiting."
|
102
|
+
exit 1
|
103
|
+
end
|
104
|
+
|
105
|
+
AppPerfAgent.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,84 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'oj'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module AppPerfAgent
|
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
|
+
::AppPerfAgent.logger.error "#{ex.inspect}"
|
39
|
+
::AppPerfAgent.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 = AppPerfAgent.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 = Oj.dump({
|
68
|
+
"host" => AppPerfAgent.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 url
|
81
|
+
@url ||= "http://#{AppPerfAgent.options[:host]}/api/listener/2/#{AppPerfAgent.options[:license_key]}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module AppPerfAgent
|
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
|
+
AppPerfAgent::Logger.logger
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "vmstat"
|
2
|
+
|
3
|
+
module AppPerfAgent
|
4
|
+
module Plugin
|
5
|
+
module System
|
6
|
+
class Cpu < AppPerfAgent::Plugin::Base
|
7
|
+
def call
|
8
|
+
cpus = Vmstat.snapshot.cpus
|
9
|
+
cpus.flat_map {|cpu|
|
10
|
+
[
|
11
|
+
[
|
12
|
+
AppPerfAgent::Types::CPU,
|
13
|
+
"system.cpu.idle",
|
14
|
+
"CPU ##{cpu.num} (Idle)",
|
15
|
+
cpu.idle
|
16
|
+
],
|
17
|
+
[
|
18
|
+
AppPerfAgent::Types::CPU,
|
19
|
+
"system.cpu.nice",
|
20
|
+
"CPU ##{cpu.num} (Nice)",
|
21
|
+
cpu.nice
|
22
|
+
],
|
23
|
+
[
|
24
|
+
AppPerfAgent::Types::CPU,
|
25
|
+
"system.cpu.system",
|
26
|
+
"CPU ##{cpu.num} (System)",
|
27
|
+
cpu.system
|
28
|
+
],
|
29
|
+
[
|
30
|
+
AppPerfAgent::Types::CPU,
|
31
|
+
"system.cpu.user",
|
32
|
+
"CPU ##{cpu.num} (User)",
|
33
|
+
cpu.user
|
34
|
+
]
|
35
|
+
]
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
AppPerfAgent.logger.info "Loading CPU monitoring."
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "vmstat"
|
2
|
+
|
3
|
+
module AppPerfAgent
|
4
|
+
module Plugin
|
5
|
+
module System
|
6
|
+
class Disk < AppPerfAgent::Plugin::Base
|
7
|
+
def call
|
8
|
+
disks = Vmstat.snapshot.disks
|
9
|
+
disks.flat_map {|disk|
|
10
|
+
[
|
11
|
+
[
|
12
|
+
AppPerfAgent::Types::DISK,
|
13
|
+
"system.disk.used_bytes",
|
14
|
+
"#{disk.origin} - #{disk.type} (#{disk.mount})",
|
15
|
+
disk.used_bytes
|
16
|
+
],
|
17
|
+
[
|
18
|
+
AppPerfAgent::Types::DISK,
|
19
|
+
"system.disk.free_bytes",
|
20
|
+
"#{disk.origin} - #{disk.type} (#{disk.mount})",
|
21
|
+
disk.free_bytes
|
22
|
+
],
|
23
|
+
[
|
24
|
+
AppPerfAgent::Types::DISK,
|
25
|
+
"system.disk.available_bytes",
|
26
|
+
"#{disk.origin} - #{disk.type} (#{disk.mount})",
|
27
|
+
disk.available_bytes
|
28
|
+
],
|
29
|
+
[
|
30
|
+
AppPerfAgent::Types::DISK,
|
31
|
+
"system.disk.total_bytes",
|
32
|
+
"#{disk.origin} - #{disk.type} (#{disk.mount})",
|
33
|
+
disk.total_bytes
|
34
|
+
]
|
35
|
+
]
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
AppPerfAgent.logger.info "Loading Disk monitoring."
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "vmstat"
|
2
|
+
|
3
|
+
module AppPerfAgent
|
4
|
+
module Plugin
|
5
|
+
module System
|
6
|
+
class Load < AppPerfAgent::Plugin::Base
|
7
|
+
def call
|
8
|
+
loads = Vmstat.load_average
|
9
|
+
[
|
10
|
+
[
|
11
|
+
AppPerfAgent::Types::LOAD,
|
12
|
+
"system.load.one_minute",
|
13
|
+
"Load - One Minute",
|
14
|
+
loads.one_minute
|
15
|
+
],
|
16
|
+
[
|
17
|
+
AppPerfAgent::Types::LOAD,
|
18
|
+
"system.load.five_minute",
|
19
|
+
"Load - Five Minute",
|
20
|
+
loads.five_minutes
|
21
|
+
],
|
22
|
+
[
|
23
|
+
AppPerfAgent::Types::LOAD,
|
24
|
+
"system.load.fifteen_minute",
|
25
|
+
"Load - Fifteen Minute",
|
26
|
+
loads.fifteen_minutes
|
27
|
+
]
|
28
|
+
]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
AppPerfAgent.logger.info "Loading Load monitoring."
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'vmstat'
|
2
|
+
|
3
|
+
module AppPerfAgent
|
4
|
+
module Plugin
|
5
|
+
module System
|
6
|
+
class Memory < AppPerfAgent::Plugin::Base
|
7
|
+
def call
|
8
|
+
memory = Vmstat.memory
|
9
|
+
[
|
10
|
+
[
|
11
|
+
AppPerfAgent::Types::MEMORY,
|
12
|
+
"system.memory.free_bytes",
|
13
|
+
"Memory (Free)",
|
14
|
+
memory.free_bytes
|
15
|
+
],
|
16
|
+
[
|
17
|
+
AppPerfAgent::Types::MEMORY,
|
18
|
+
"system.memory.inactive_bytes",
|
19
|
+
"Memory (Inactive)",
|
20
|
+
memory.inactive_bytes
|
21
|
+
],
|
22
|
+
[
|
23
|
+
AppPerfAgent::Types::MEMORY,
|
24
|
+
"system.memory.active_bytes",
|
25
|
+
"Memory (Active)",
|
26
|
+
memory.active_bytes
|
27
|
+
],
|
28
|
+
[
|
29
|
+
AppPerfAgent::Types::MEMORY,
|
30
|
+
"system.memory.wired_bytes",
|
31
|
+
"Memory (Wired)",
|
32
|
+
memory.wired_bytes
|
33
|
+
],
|
34
|
+
[
|
35
|
+
AppPerfAgent::Types::MEMORY,
|
36
|
+
"system.memory.total_bytes",
|
37
|
+
"Memory (Total)",
|
38
|
+
memory.total_bytes
|
39
|
+
]
|
40
|
+
]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
AppPerfAgent.logger.info "Loading Memory monitoring."
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "vmstat"
|
2
|
+
|
3
|
+
module AppPerfAgent
|
4
|
+
module Plugin
|
5
|
+
module System
|
6
|
+
class Network < AppPerfAgent::Plugin::Base
|
7
|
+
def call
|
8
|
+
inets = Vmstat.ethernet_devices
|
9
|
+
inets.flat_map {|inet|
|
10
|
+
[
|
11
|
+
[
|
12
|
+
AppPerfAgent::Types::NETWORK,
|
13
|
+
"system.network.in_bytes",
|
14
|
+
inet.name.to_s,
|
15
|
+
inet.in_bytes
|
16
|
+
],
|
17
|
+
[
|
18
|
+
AppPerfAgent::Types::NETWORK,
|
19
|
+
"system.network.out_bytes",
|
20
|
+
inet.name.to_s,
|
21
|
+
inet.out_bytes
|
22
|
+
]
|
23
|
+
]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
AppPerfAgent.logger.info "Loading Network monitoring."
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AppPerfAgent
|
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
|
+
AppPerfAgent.logger.info "Error loading plugin '#{f}' : #{e}"
|
12
|
+
AppPerfAgent.logger.info "#{e.backtrace.first}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def plugins
|
18
|
+
@plugins ||= ::AppPerfAgent::Plugin::Base
|
19
|
+
.descendants
|
20
|
+
.map(&:new)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module AppPerfAgent
|
2
|
+
class Worker
|
3
|
+
def initialize
|
4
|
+
@running = false
|
5
|
+
end
|
6
|
+
|
7
|
+
def load_plugins
|
8
|
+
AppPerfAgent::Plugin.load_plugins
|
9
|
+
end
|
10
|
+
|
11
|
+
def dispatcher
|
12
|
+
@dispatcher ||= AppPerfAgent::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
|
+
AppPerfAgent::Plugin.plugins.each do |plugin|
|
36
|
+
items = plugin.call
|
37
|
+
items.map {|i| AppPerfAgent.logger.debug i }
|
38
|
+
Array(items).each do |item|
|
39
|
+
type, name, label, value = item
|
40
|
+
dispatcher.add_event(["metric", Time.now.to_f, {
|
41
|
+
"type" => type,
|
42
|
+
"name" => name,
|
43
|
+
"label" => label,
|
44
|
+
"value" => value
|
45
|
+
}])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative "app_perf_agent/types"
|
2
|
+
require_relative "app_perf_agent/logger"
|
3
|
+
require_relative "app_perf_agent/plugin"
|
4
|
+
require_relative "app_perf_agent/dispatcher"
|
5
|
+
require_relative "app_perf_agent/worker"
|
6
|
+
|
7
|
+
module AppPerfAgent
|
8
|
+
DEFAULTS = {
|
9
|
+
environment: nil,
|
10
|
+
daemon: false,
|
11
|
+
host: 'localhost:5000',
|
12
|
+
ssl: false,
|
13
|
+
license_key: '',
|
14
|
+
pidfile: File.dirname(__FILE__) + "/../app_perf_agent.pid"
|
15
|
+
}
|
16
|
+
|
17
|
+
def self.hostname
|
18
|
+
@hostname ||= Socket.gethostname
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.options
|
22
|
+
@options ||= DEFAULTS.dup
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.options=(opts)
|
26
|
+
@options = opts
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.logger
|
30
|
+
AppPerfAgent::Logger.logger
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.logger=(log)
|
34
|
+
AppPerfAgent::Logger.logger = log
|
35
|
+
end
|
36
|
+
|
37
|
+
class << self
|
38
|
+
def load
|
39
|
+
AppPerfAgent::Agent::Plugin.load_plugins
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: app_perf_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Randy Girard
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-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: oj
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.3.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.3.2
|
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
|
+
description: Agent for the AppPerf app.
|
98
|
+
email: rgirard59@yahoo.com
|
99
|
+
executables:
|
100
|
+
- app_perf_agent
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- app_perf_agent.gemspec
|
111
|
+
- exe/app_perf_agent
|
112
|
+
- init.rb
|
113
|
+
- lib/app_perf_agent.rb
|
114
|
+
- lib/app_perf_agent/cli.rb
|
115
|
+
- lib/app_perf_agent/dispatcher.rb
|
116
|
+
- lib/app_perf_agent/logger.rb
|
117
|
+
- lib/app_perf_agent/plugin.rb
|
118
|
+
- lib/app_perf_agent/plugin/base.rb
|
119
|
+
- lib/app_perf_agent/plugin/system/cpu.rb
|
120
|
+
- lib/app_perf_agent/plugin/system/disk.rb
|
121
|
+
- lib/app_perf_agent/plugin/system/load.rb
|
122
|
+
- lib/app_perf_agent/plugin/system/memory.rb
|
123
|
+
- lib/app_perf_agent/plugin/system/network.rb
|
124
|
+
- lib/app_perf_agent/types.rb
|
125
|
+
- lib/app_perf_agent/worker.rb
|
126
|
+
homepage: https://www.github.com/randy-girard/app_perf_agent
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.6.11
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: AppPerf Agent
|
150
|
+
test_files: []
|