rest-ftp-daemon 0.302.3 → 0.304.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -3
- data/README.md +1 -1
- data/bin/rest-ftp-daemon +3 -3
- data/config.ru +1 -1
- data/defaults.yml +2 -2
- data/lib/rest-ftp-daemon/api/root.rb +10 -4
- data/lib/rest-ftp-daemon/api/status.rb +10 -0
- data/lib/rest-ftp-daemon/constants.rb +1 -4
- data/lib/rest-ftp-daemon/counters.rb +4 -2
- data/lib/rest-ftp-daemon/job.rb +11 -12
- data/lib/rest-ftp-daemon/job_queue.rb +10 -12
- data/lib/rest-ftp-daemon/launcher.rb +1 -0
- data/lib/rest-ftp-daemon/metrics.rb +10 -0
- data/lib/rest-ftp-daemon/notification.rb +5 -5
- data/lib/rest-ftp-daemon/paginate.rb +1 -0
- data/lib/rest-ftp-daemon/path.rb +2 -0
- data/lib/rest-ftp-daemon/remote.rb +5 -4
- data/lib/rest-ftp-daemon/remote_ftp.rb +3 -1
- data/lib/rest-ftp-daemon/remote_sftp.rb +4 -2
- data/lib/rest-ftp-daemon/views/dashboard_workers.haml +4 -1
- data/lib/rest-ftp-daemon/worker_pool.rb +6 -7
- data/lib/rest-ftp-daemon/workers/conchita.rb +8 -7
- data/lib/rest-ftp-daemon/workers/reporter.rb +24 -12
- data/lib/rest-ftp-daemon/workers/transfer.rb +8 -7
- data/lib/rest-ftp-daemon/workers/worker.rb +12 -0
- data/lib/rest-ftp-daemon.rb +10 -16
- data/lib/{rest-ftp-daemon → shared}/patch_array.rb +0 -0
- data/lib/{rest-ftp-daemon → shared}/patch_haml.rb +0 -2
- data/rest-ftp-daemon.gemspec +29 -28
- metadata +34 -24
- data/lib/rest-ftp-daemon/logger_pool.rb +0 -61
- data/lib/shared/conf.rb +0 -201
- data/lib/shared/logger_formatter.rb +0 -31
- data/lib/shared/logger_helper.rb +0 -78
- data/lib/shared/worker_base.rb +0 -112
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 879a66df142ffdef4e82af5932e0ae6f862382b1
|
4
|
+
data.tar.gz: d81bb16f0c971a2b7a07e0902aa5ab40bce438e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2fb79546eb167872017b0995e7c055fd26ffea32272c17403e4a278e4b13f63a6245c2e5bb277061a90c6eddef6ad72e7bb00cead8a9d312058213db8b3a8f2
|
7
|
+
data.tar.gz: 39548d2cfbe17d534a4e03f7060399fbb8e8f06fce93a0190c86fe1360d9064b56bf8cb9c70cfc8e508fe19dd8af8e69107aecfbfab944e323cbd6a935f75471
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rest-ftp-daemon (0.
|
4
|
+
rest-ftp-daemon (0.304.0)
|
5
5
|
api-auth
|
6
|
-
|
6
|
+
bmc-daemon-lib (~> 0.2)
|
7
7
|
double-bag-ftps
|
8
8
|
facter
|
9
9
|
get_process_mem
|
@@ -27,6 +27,7 @@ GEM
|
|
27
27
|
i18n (~> 0.7)
|
28
28
|
minitest (~> 5.1)
|
29
29
|
tzinfo (~> 1.1)
|
30
|
+
addressable (2.4.0)
|
30
31
|
api-auth (2.0.0)
|
31
32
|
ast (2.3.0)
|
32
33
|
astrolabe (1.3.1)
|
@@ -35,6 +36,8 @@ GEM
|
|
35
36
|
descendants_tracker (~> 0.0.4)
|
36
37
|
ice_nine (~> 0.11.0)
|
37
38
|
thread_safe (~> 0.3, >= 0.3.1)
|
39
|
+
bmc-daemon-lib (0.2.0)
|
40
|
+
chamber (~> 2.9)
|
38
41
|
builder (3.2.2)
|
39
42
|
chamber (2.9.0)
|
40
43
|
hashie (~> 3.3)
|
@@ -55,7 +58,7 @@ GEM
|
|
55
58
|
eventmachine (1.2.0.1)
|
56
59
|
facter (2.4.6)
|
57
60
|
CFPropertyList (~> 2.2.6)
|
58
|
-
ffi (1.9.
|
61
|
+
ffi (1.9.14)
|
59
62
|
get_process_mem (0.2.1)
|
60
63
|
grape (0.16.2)
|
61
64
|
activesupport
|
@@ -73,8 +76,15 @@ GEM
|
|
73
76
|
haml (4.0.7)
|
74
77
|
tilt
|
75
78
|
hashie (3.4.4)
|
79
|
+
http (2.0.2)
|
80
|
+
addressable (~> 2.3)
|
81
|
+
http-cookie (~> 1.0)
|
82
|
+
http-form_data (~> 1.0.1)
|
83
|
+
http_parser.rb (~> 0.6.0)
|
76
84
|
http-cookie (1.0.2)
|
77
85
|
domain_name (~> 0.5)
|
86
|
+
http-form_data (1.0.1)
|
87
|
+
http_parser.rb (0.6.0)
|
78
88
|
i18n (0.7.0)
|
79
89
|
ice_nine (0.11.2)
|
80
90
|
json (1.8.3)
|
@@ -153,6 +163,7 @@ PLATFORMS
|
|
153
163
|
|
154
164
|
DEPENDENCIES
|
155
165
|
bundler (~> 1.6)
|
166
|
+
http
|
156
167
|
pry
|
157
168
|
rake
|
158
169
|
rest-ftp-daemon!
|
data/README.md
CHANGED
@@ -253,7 +253,7 @@ transfer:
|
|
253
253
|
|
254
254
|
newrelic:
|
255
255
|
debug: false
|
256
|
-
#
|
256
|
+
# license: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
257
257
|
# app_name: "rftpd-bigbusiness-dev" # app_name used for naming app (used as-is if provided)
|
258
258
|
prefix: "rftpd" # app prefix to build app_name
|
259
259
|
# platform: "bigbusiness" # app platform to build app_name
|
data/bin/rest-ftp-daemon
CHANGED
@@ -3,15 +3,15 @@
|
|
3
3
|
# Try to load external libs, helpers and constants
|
4
4
|
begin
|
5
5
|
require "rubygems"
|
6
|
+
require 'bmc-daemon-lib'
|
6
7
|
require "optparse"
|
7
8
|
require "thin"
|
8
9
|
require "socket"
|
9
10
|
require_relative "../lib/rest-ftp-daemon/launcher"
|
10
|
-
require_relative "../lib/shared/conf"
|
11
11
|
rescue LoadError => e
|
12
12
|
raise "EXITING: some basic libs were not found (#{e.message})"
|
13
13
|
end
|
14
|
-
include
|
14
|
+
include BmcDaemonLib
|
15
15
|
include RestFtpDaemon
|
16
16
|
|
17
17
|
|
@@ -119,7 +119,7 @@ puts
|
|
119
119
|
puts "Daemonize \t #{Conf[:daemonize]}"
|
120
120
|
puts "Network port \t #{Conf[:port]}"
|
121
121
|
puts "User:group \t #{Conf[:user]}:#{Conf[:group]}" if Conf[:user] && Conf[:group]
|
122
|
-
puts "Newrelic \t #{Conf.newrelic_enabled? ? Conf.at(:newrelic, :
|
122
|
+
puts "Newrelic \t #{Conf.newrelic_enabled? ? Conf.at(:newrelic, :license) : 'no'}"
|
123
123
|
puts "PID file \t #{Conf[:pidfile]}"
|
124
124
|
puts
|
125
125
|
puts Conf.dump
|
data/config.ru
CHANGED
data/defaults.yml
CHANGED
@@ -49,13 +49,13 @@ transfer:
|
|
49
49
|
|
50
50
|
newrelic:
|
51
51
|
debug: false
|
52
|
-
#
|
52
|
+
# license: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
53
53
|
# app_name: "rftpd-bigbusiness-dev" # app_name used for naming app (used as-is if provided)
|
54
54
|
prefix: "rftpd" # app prefix to build app_name
|
55
55
|
# platform: "bigbusiness" # app platform to build app_name
|
56
56
|
|
57
57
|
logs:
|
58
|
-
path: "/
|
58
|
+
path: "/tmp/"
|
59
59
|
|
60
60
|
thin: "rftpd-environment-thin.log"
|
61
61
|
newrelic: "rftpd-environment-newrelic.log"
|
@@ -32,8 +32,8 @@ module RestFtpDaemon
|
|
32
32
|
end
|
33
33
|
|
34
34
|
### CLASS CONFIG
|
35
|
-
helpers
|
36
|
-
logger
|
35
|
+
helpers BmcDaemonLib::LoggerHelper
|
36
|
+
logger BmcDaemonLib::LoggerPool.instance.get :api
|
37
37
|
do_not_route_head!
|
38
38
|
do_not_route_options!
|
39
39
|
# version 'v1'
|
@@ -54,8 +54,14 @@ module RestFtpDaemon
|
|
54
54
|
super
|
55
55
|
|
56
56
|
# Check that Queue and Pool are available
|
57
|
-
|
58
|
-
|
57
|
+
unless $pool.is_a? RestFtpDaemon::WorkerPool
|
58
|
+
log_error "Metrics.sample: invalid WorkerPool"
|
59
|
+
raise RestFtpDaemon::MissingPool
|
60
|
+
end
|
61
|
+
unless $queue.is_a? RestFtpDaemon::JobQueue
|
62
|
+
log_error "Metrics.sample: invalid JobQueue"
|
63
|
+
raise RestFtpDaemon::MissingQueue
|
64
|
+
end
|
59
65
|
end
|
60
66
|
|
61
67
|
|
@@ -10,6 +10,16 @@ module RestFtpDaemon
|
|
10
10
|
get "/" do
|
11
11
|
status 200
|
12
12
|
|
13
|
+
# Check that Queue and Pool are available
|
14
|
+
unless true
|
15
|
+
log_error "Status API: invalid WorkerPool"
|
16
|
+
return status 501
|
17
|
+
end
|
18
|
+
unless $queue.is_a? RestFtpDaemon::JobQueue
|
19
|
+
log_error "Status API: invalid JobQueue"
|
20
|
+
return status 501
|
21
|
+
end
|
22
|
+
|
13
23
|
# Get counters
|
14
24
|
counters = $counters.stats.dup
|
15
25
|
|
@@ -1,6 +1,3 @@
|
|
1
|
-
# Misc constants
|
2
|
-
|
3
|
-
|
4
1
|
# Configuration defaults
|
5
2
|
DEFAULT_POOL = "default"
|
6
3
|
DEFAULT_SFTP_TIMEOUT = 600 # 10mn
|
@@ -19,7 +16,6 @@ JOB_UPDATE_INTERVAL = 1
|
|
19
16
|
# Constants: logger
|
20
17
|
LOG_ROTATION = "daily"
|
21
18
|
LOG_FORMAT_PROGNAME = "%d\t%s"
|
22
|
-
|
23
19
|
LOG_HEADER_TIME = "%Y-%m-%d %H:%M:%S"
|
24
20
|
LOG_HEADER_FORMAT = "%s \t%d\t%-8s %-10s "
|
25
21
|
LOG_MESSAGE_TRIM = 200
|
@@ -27,6 +23,7 @@ LOG_MESSAGE_TEXT = "%s%s"
|
|
27
23
|
LOG_MESSAGE_ARRAY = "%s - %s"
|
28
24
|
LOG_MESSAGE_HASH = "%s * %-20s %s"
|
29
25
|
|
26
|
+
|
30
27
|
# Constants: logger app-specific prefix
|
31
28
|
LOG_PREFIX_WID = 8
|
32
29
|
LOG_PREFIX_JID = JOB_IDENT_LEN + 4
|
@@ -1,7 +1,9 @@
|
|
1
|
-
|
1
|
+
# Queue that stores all the Jobs waiting to be processed or fully processed
|
2
2
|
|
3
|
-
|
3
|
+
module RestFtpDaemon
|
4
4
|
class Counters
|
5
|
+
|
6
|
+
# Class options
|
5
7
|
attr_reader :stats
|
6
8
|
|
7
9
|
def initialize
|
data/lib/rest-ftp-daemon/job.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
+
# Reprensents work to be done along with parameters to process it
|
1
2
|
require "securerandom"
|
2
3
|
|
3
4
|
module RestFtpDaemon
|
4
|
-
|
5
|
-
# Reprensents work to be done along with parameters to process it
|
6
5
|
class Job
|
7
|
-
include
|
8
|
-
|
6
|
+
include BmcDaemonLib::LoggerHelper
|
7
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
9
8
|
|
9
|
+
# Class constants
|
10
10
|
FIELDS = [:source, :target, :label, :priority, :pool, :notify, :overwrite, :mkdir, :tempfile]
|
11
11
|
|
12
|
+
# Class options
|
13
|
+
attr_reader :logger
|
12
14
|
attr_accessor :wid
|
13
15
|
|
14
16
|
attr_reader :id
|
@@ -51,7 +53,7 @@ module RestFtpDaemon
|
|
51
53
|
@pools = Conf[:pools] || {}
|
52
54
|
|
53
55
|
# Logger
|
54
|
-
@logger =
|
56
|
+
@logger = BmcDaemonLib::LoggerPool.instance.get :transfer
|
55
57
|
|
56
58
|
# Protect with a mutex
|
57
59
|
@mutex = Mutex.new
|
@@ -659,13 +661,10 @@ module RestFtpDaemon
|
|
659
661
|
end
|
660
662
|
|
661
663
|
# NewRelic instrumentation
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
add_transaction_tracer :client_notify, category: :task
|
667
|
-
add_transaction_tracer :initialize, category: :task
|
668
|
-
end
|
664
|
+
add_transaction_tracer :prepare, category: :task
|
665
|
+
add_transaction_tracer :run, category: :task
|
666
|
+
add_transaction_tracer :client_notify, category: :task
|
667
|
+
add_transaction_tracer :initialize, category: :task
|
669
668
|
|
670
669
|
end
|
671
670
|
end
|
@@ -2,7 +2,10 @@ module RestFtpDaemon
|
|
2
2
|
|
3
3
|
# Queue that stores all the Jobs waiting to be processed or fully processed
|
4
4
|
class JobQueue
|
5
|
-
include
|
5
|
+
include BmcDaemonLib::LoggerHelper
|
6
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
7
|
+
|
8
|
+
# Class options
|
6
9
|
attr_reader :logger
|
7
10
|
attr_reader :jobs
|
8
11
|
|
@@ -20,7 +23,7 @@ module RestFtpDaemon
|
|
20
23
|
@mutex = Mutex.new
|
21
24
|
|
22
25
|
# Logger
|
23
|
-
@logger =
|
26
|
+
@logger = BmcDaemonLib::LoggerPool.instance.get :queue
|
24
27
|
|
25
28
|
# Identifiers generator
|
26
29
|
@last_id = 0
|
@@ -232,17 +235,12 @@ module RestFtpDaemon
|
|
232
235
|
"#{@prefix}.#{id}"
|
233
236
|
end
|
234
237
|
|
235
|
-
private
|
236
|
-
|
237
238
|
# NewRelic instrumentation
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
add_transaction_tracer :rate_by, category: :task
|
244
|
-
add_transaction_tracer :jobs_by_status, category: :task
|
245
|
-
end
|
239
|
+
add_transaction_tracer :push, category: :task
|
240
|
+
add_transaction_tracer :pop, category: :task
|
241
|
+
add_transaction_tracer :expire, category: :task
|
242
|
+
add_transaction_tracer :rate_by, category: :task
|
243
|
+
add_transaction_tracer :jobs_by_status, category: :task
|
246
244
|
|
247
245
|
end
|
248
246
|
end
|
@@ -2,6 +2,10 @@ module RestFtpDaemon
|
|
2
2
|
class Metrics
|
3
3
|
|
4
4
|
def self.sample
|
5
|
+
# Check validity of globals
|
6
|
+
return log_error "Metrics.sample: invalid WorkerPool" unless $pool.is_a? RestFtpDaemon::WorkerPool
|
7
|
+
return log_error "Metrics.sample: invalid JobQueue" unless $queue.is_a? RestFtpDaemon::JobQueue
|
8
|
+
|
5
9
|
# Prepare external deps
|
6
10
|
mem = GetProcessMem.new
|
7
11
|
|
@@ -27,6 +31,12 @@ module RestFtpDaemon
|
|
27
31
|
# Init
|
28
32
|
counts = {}
|
29
33
|
|
34
|
+
# Check validity of globals
|
35
|
+
unless $pool.is_a? RestFtpDaemon::WorkerPool
|
36
|
+
log_error "Metrics.workers_count_by_status: invalid WorkerPool"
|
37
|
+
return counts
|
38
|
+
end
|
39
|
+
|
30
40
|
$pool.worker_variables.group_by do |wid, vars|
|
31
41
|
vars[:status]
|
32
42
|
end.each do |status, workers|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'api_auth'
|
2
2
|
require 'rest_client'
|
3
3
|
|
4
|
+
# Handle a notification POST using a dedicated thread
|
4
5
|
module RestFtpDaemon
|
5
|
-
|
6
|
-
# Handles a notification POST using a dedicated thread
|
7
6
|
class Notification
|
8
|
-
include
|
9
|
-
attr_reader :logger
|
7
|
+
include BmcDaemonLib::LoggerHelper
|
10
8
|
|
9
|
+
# Class options
|
10
|
+
attr_reader :logger
|
11
11
|
attr_accessor :job_id
|
12
12
|
attr_accessor :signal
|
13
13
|
attr_accessor :error
|
@@ -26,7 +26,7 @@ module RestFtpDaemon
|
|
26
26
|
@jid = nil
|
27
27
|
|
28
28
|
# Logger
|
29
|
-
@logger =
|
29
|
+
@logger = BmcDaemonLib::LoggerPool.instance.get :notify
|
30
30
|
|
31
31
|
# Handle the notification
|
32
32
|
log_info "initialized [#{@url}]"
|
data/lib/rest-ftp-daemon/path.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# Handles transfers for Job class
|
1
2
|
module RestFtpDaemon
|
2
|
-
|
3
|
-
# Handles transfers for Job class
|
4
3
|
class Remote
|
5
|
-
include
|
4
|
+
include BmcDaemonLib::LoggerHelper
|
5
|
+
|
6
|
+
# Class options
|
6
7
|
attr_reader :logger
|
7
8
|
attr_reader :log_prefix
|
8
9
|
|
@@ -12,7 +13,7 @@ module RestFtpDaemon
|
|
12
13
|
|
13
14
|
# Logger
|
14
15
|
@log_prefix = log_prefix || {}
|
15
|
-
@logger =
|
16
|
+
@logger = BmcDaemonLib::LoggerPool.instance.get :transfer
|
16
17
|
|
17
18
|
# Extract URL parts
|
18
19
|
@url = url
|
@@ -1,9 +1,11 @@
|
|
1
1
|
require "net/ftp"
|
2
2
|
require "double_bag_ftps"
|
3
3
|
|
4
|
+
# Handle FTP and FTPeS transfers for Remote class
|
4
5
|
module RestFtpDaemon
|
5
|
-
# Handles FTP and FTPeS transfers for Remote class
|
6
6
|
class RemoteFTP < Remote
|
7
|
+
|
8
|
+
# Class options
|
7
9
|
attr_reader :ftp
|
8
10
|
|
9
11
|
def initialize url, log_prefix, options = {}
|
@@ -1,8 +1,10 @@
|
|
1
1
|
require "net/sftp"
|
2
2
|
|
3
|
+
# Handle sFTP transfers for Remote class
|
3
4
|
module RestFtpDaemon
|
4
|
-
# Handles sFTP transfers for Remote class
|
5
5
|
class RemoteSFTP < Remote
|
6
|
+
|
7
|
+
# Class options
|
6
8
|
attr_reader :sftp
|
7
9
|
|
8
10
|
def initialize url, log_prefix, options = {}
|
@@ -19,7 +21,7 @@ module RestFtpDaemon
|
|
19
21
|
log_debug "RemoteSFTP.connect [#{@url.user}]@[#{@url.host}]:[#{@url.port}]"
|
20
22
|
|
21
23
|
# Debug level
|
22
|
-
verbosity = @debug ? Logger::
|
24
|
+
verbosity = @debug ? Logger::DEBUG : false
|
23
25
|
|
24
26
|
# Connect remote server
|
25
27
|
@sftp = Net::SFTP.start(@url.host.to_s, @url.user.to_s,
|
@@ -2,13 +2,16 @@ module RestFtpDaemon
|
|
2
2
|
|
3
3
|
# Handles a pool of Worker objects
|
4
4
|
class WorkerPool
|
5
|
-
include
|
5
|
+
include BmcDaemonLib::LoggerHelper
|
6
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
7
|
+
|
8
|
+
# Class options
|
6
9
|
attr_reader :logger
|
7
10
|
attr_reader :wid
|
8
11
|
|
9
12
|
def initialize
|
10
13
|
# Logger
|
11
|
-
@logger =
|
14
|
+
@logger = BmcDaemonLib::LoggerPool.instance.get :workers
|
12
15
|
|
13
16
|
# Prepare status hash and vars
|
14
17
|
@statuses = {}
|
@@ -99,11 +102,7 @@ module RestFtpDaemon
|
|
99
102
|
end
|
100
103
|
|
101
104
|
# NewRelic instrumentation
|
102
|
-
|
103
|
-
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
104
|
-
# add_transaction_tracer :create_conchita_thread, category: :task
|
105
|
-
add_transaction_tracer :create_thread, category: :task
|
106
|
-
end
|
105
|
+
add_transaction_tracer :create_thread, category: :task
|
107
106
|
|
108
107
|
end
|
109
108
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
# Worker used to clean up the queue deleting expired jobs
|
2
2
|
|
3
|
-
|
4
|
-
class ConchitaWorker <
|
3
|
+
module RestFtpDaemon
|
4
|
+
class ConchitaWorker < Worker
|
5
5
|
|
6
6
|
protected
|
7
7
|
|
@@ -31,10 +31,6 @@ module RestFtpDaemon
|
|
31
31
|
|
32
32
|
# Force garbage collector
|
33
33
|
GC.start if @config["garbage_collector"]
|
34
|
-
|
35
|
-
rescue StandardError => e
|
36
|
-
log_error "EXCEPTION: #{e.inspect}"
|
37
|
-
sleep 1
|
38
34
|
end
|
39
35
|
|
40
36
|
private
|
@@ -43,5 +39,10 @@ module RestFtpDaemon
|
|
43
39
|
@config["clean_#{status}"] || 0
|
44
40
|
end
|
45
41
|
|
42
|
+
# NewRelic instrumentation
|
43
|
+
add_transaction_tracer :worker_init, category: :task
|
44
|
+
add_transaction_tracer :worker_after, category: :task
|
45
|
+
add_transaction_tracer :worker_process, category: :task
|
46
|
+
|
46
47
|
end
|
47
48
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
# Worker used to report metrics to various services
|
2
2
|
|
3
|
-
|
4
|
-
class ReporterWorker <
|
3
|
+
module RestFtpDaemon
|
4
|
+
class ReporterWorker < Worker
|
5
5
|
|
6
6
|
protected
|
7
7
|
|
@@ -9,6 +9,9 @@ module RestFtpDaemon
|
|
9
9
|
# Load corker conf
|
10
10
|
config_section :reporter
|
11
11
|
|
12
|
+
# Other configuration options
|
13
|
+
@report_newrelic = Conf.newrelic_enabled?
|
14
|
+
|
12
15
|
# Check that everything is OK
|
13
16
|
return "invalid timer" unless @config[:timer].to_i > 0
|
14
17
|
return false
|
@@ -26,21 +29,21 @@ module RestFtpDaemon
|
|
26
29
|
|
27
30
|
# Report metrics
|
28
31
|
do_metrics
|
29
|
-
|
30
|
-
rescue StandardError => e
|
31
|
-
log_error "EXCEPTION: #{e.inspect}"
|
32
|
-
sleep 1
|
33
32
|
end
|
34
33
|
|
35
34
|
private
|
36
35
|
|
37
36
|
def do_metrics
|
37
|
+
# What metrics to report?
|
38
|
+
report_newrelic = Conf.newrelic_enabled?
|
39
|
+
|
38
40
|
# Get common metrics and dump them to logs
|
41
|
+
log_debug "begin metrics sample"
|
39
42
|
metrics = Metrics.sample
|
40
|
-
log_info "collected metrics", metrics
|
43
|
+
log_info "collected metrics (newrelic: #{@report_newrelic})", metrics
|
41
44
|
|
42
45
|
# Transpose metrics to NewRelic metrics
|
43
|
-
report_newrelic(metrics) if
|
46
|
+
report_newrelic(metrics) if @report_newrelic
|
44
47
|
end
|
45
48
|
|
46
49
|
def report_newrelic metrics
|
@@ -54,10 +57,19 @@ module RestFtpDaemon
|
|
54
57
|
end
|
55
58
|
|
56
59
|
# Don't dump metrics unless we're debugging
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
msg_newrelic = "reported metrics to NewRelic [#{ENV['NEW_RELIC_APP_NAME']}]"
|
61
|
+
if @config[:debug]
|
62
|
+
log_debug msg_newrelic, metrics_newrelic
|
63
|
+
else
|
64
|
+
log_info msg_newrelic
|
65
|
+
end
|
66
|
+
|
60
67
|
end
|
61
68
|
|
69
|
+
# NewRelic instrumentation
|
70
|
+
add_transaction_tracer :worker_init, category: :task
|
71
|
+
add_transaction_tracer :worker_after, category: :task
|
72
|
+
add_transaction_tracer :worker_process, category: :task
|
73
|
+
|
62
74
|
end
|
63
75
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
# Worker used to process Jobs
|
2
2
|
|
3
|
-
|
4
|
-
class TransferWorker <
|
3
|
+
module RestFtpDaemon
|
4
|
+
class TransferWorker < Worker
|
5
5
|
|
6
6
|
protected
|
7
7
|
|
@@ -66,10 +66,6 @@ module RestFtpDaemon
|
|
66
66
|
# Now, requeue this job
|
67
67
|
$queue.requeue job
|
68
68
|
end
|
69
|
-
|
70
|
-
rescue StandardError => ex
|
71
|
-
log_error "WORKER UNHANDLED EXCEPTION: #{ex.message}", ex.backtrace
|
72
|
-
worker_status WORKER_STATUS_CRASHED
|
73
69
|
end
|
74
70
|
|
75
71
|
def work_on_job job
|
@@ -104,5 +100,10 @@ module RestFtpDaemon
|
|
104
100
|
job.oops_after_crash ex unless job.nil?
|
105
101
|
end
|
106
102
|
|
103
|
+
# NewRelic instrumentation
|
104
|
+
add_transaction_tracer :worker_init, category: :task
|
105
|
+
add_transaction_tracer :worker_after, category: :task
|
106
|
+
add_transaction_tracer :worker_process, category: :task
|
107
|
+
|
107
108
|
end
|
108
109
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Instrumented WorkerBase
|
2
|
+
|
3
|
+
module RestFtpDaemon
|
4
|
+
class Worker < BmcDaemonLib::WorkerBase
|
5
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
6
|
+
|
7
|
+
# NewRelic instrumentation
|
8
|
+
add_transaction_tracer :worker_init, category: :task
|
9
|
+
add_transaction_tracer :worker_after, category: :task
|
10
|
+
add_transaction_tracer :worker_process, category: :task
|
11
|
+
end
|
12
|
+
end
|