tcell_agent 1.1.3 → 1.1.4
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 +4 -4
- data/bin/tcell_agent +10 -2
- data/lib/tcell_agent.rb +3 -3
- data/lib/tcell_agent/agent.rb +42 -52
- data/lib/tcell_agent/agent/event_processor.rb +129 -162
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +57 -62
- data/lib/tcell_agent/agent/policy_manager.rb +83 -104
- data/lib/tcell_agent/agent/policy_types.rb +24 -29
- data/lib/tcell_agent/agent/route_manager.rb +36 -46
- data/lib/tcell_agent/agent/static_agent.rb +19 -21
- data/lib/tcell_agent/api.rb +23 -28
- data/lib/tcell_agent/appsensor/injections_reporter.rb +7 -11
- data/lib/tcell_agent/authlogic.rb +7 -7
- data/lib/tcell_agent/cmdi.rb +22 -23
- data/lib/tcell_agent/config/unknown_options.rb +71 -69
- data/lib/tcell_agent/configuration.rb +187 -191
- data/lib/tcell_agent/devise.rb +13 -15
- data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
- data/lib/tcell_agent/instrumentation.rb +120 -124
- data/lib/tcell_agent/logger.rb +29 -45
- data/lib/tcell_agent/patches.rb +5 -5
- data/lib/tcell_agent/policies/dataloss_policy.rb +263 -288
- data/lib/tcell_agent/policies/http_redirect_policy.rb +25 -37
- data/lib/tcell_agent/policies/http_tx_policy.rb +48 -52
- data/lib/tcell_agent/policies/login_fraud_policy.rb +15 -20
- data/lib/tcell_agent/policies/policy.rb +0 -2
- data/lib/tcell_agent/policies/rust_policies.rb +24 -29
- data/lib/tcell_agent/rails.rb +2 -3
- data/lib/tcell_agent/rails/auth/authlogic.rb +2 -2
- data/lib/tcell_agent/rails/auth/devise.rb +2 -2
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +2 -2
- data/lib/tcell_agent/rails/better_ip.rb +12 -16
- data/lib/tcell_agent/rails/csrf_exception.rb +4 -7
- data/lib/tcell_agent/rails/dlp.rb +208 -107
- data/lib/tcell_agent/rails/dlp/process_request.rb +37 -47
- data/lib/tcell_agent/rails/dlp_handler.rb +9 -11
- data/lib/tcell_agent/rails/js_agent_insert.rb +11 -14
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +8 -7
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +4 -5
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +5 -8
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +24 -27
- data/lib/tcell_agent/rails/on_start.rb +5 -5
- data/lib/tcell_agent/rails/responses.rb +7 -9
- data/lib/tcell_agent/rails/routes.rb +62 -81
- data/lib/tcell_agent/rails/routes/grape.rb +25 -30
- data/lib/tcell_agent/rails/routes/route_id.rb +9 -14
- data/lib/tcell_agent/rails/settings_reporter.rb +44 -33
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +15 -18
- data/lib/tcell_agent/routes/table.rb +31 -33
- data/lib/tcell_agent/rust/{libtcellagent-1.3.0.dylib → libtcellagent-1.3.1.dylib} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-1.3.0.so → libtcellagent-1.3.1.so} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.0.so → libtcellagent-alpine-1.3.1.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +32 -37
- data/lib/tcell_agent/rust/tcellagent-1.3.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +101 -104
- data/lib/tcell_agent/sensor_events/app_config.rb +7 -7
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +26 -27
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +20 -88
- data/lib/tcell_agent/sensor_events/command_injection.rb +52 -80
- data/lib/tcell_agent/sensor_events/discovery.rb +27 -27
- data/lib/tcell_agent/sensor_events/dlp.rb +50 -56
- data/lib/tcell_agent/sensor_events/honeytokens.rb +9 -9
- data/lib/tcell_agent/sensor_events/metrics.rb +20 -21
- data/lib/tcell_agent/sensor_events/patches.rb +10 -12
- data/lib/tcell_agent/sensor_events/sensor.rb +32 -36
- data/lib/tcell_agent/sensor_events/server_agent.rb +130 -127
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +60 -80
- data/lib/tcell_agent/sensor_events/util/utils.rb +3 -5
- data/lib/tcell_agent/servers/passenger.rb +5 -9
- data/lib/tcell_agent/servers/puma.rb +18 -27
- data/lib/tcell_agent/servers/rails_server.rb +5 -9
- data/lib/tcell_agent/servers/thin.rb +2 -4
- data/lib/tcell_agent/servers/unicorn.rb +18 -27
- data/lib/tcell_agent/servers/webrick.rb +2 -4
- data/lib/tcell_agent/settings_reporter.rb +126 -0
- data/lib/tcell_agent/sinatra.rb +24 -26
- data/lib/tcell_agent/start_background_thread.rb +21 -142
- data/lib/tcell_agent/system_info.rb +4 -3
- data/lib/tcell_agent/tcell_context.rb +150 -0
- data/lib/tcell_agent/userinfo.rb +3 -3
- data/lib/tcell_agent/utils/io.rb +19 -24
- data/lib/tcell_agent/utils/params.rb +9 -15
- data/lib/tcell_agent/utils/queue_with_timeout.rb +26 -32
- data/lib/tcell_agent/utils/strings.rb +4 -6
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +5 -5
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +7 -7
- data/spec/lib/tcell_agent/cmdi_spec.rb +21 -21
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +29 -24
- data/spec/lib/tcell_agent/instrumentation_spec.rb +4 -4
- data/spec/lib/tcell_agent/patches_spec.rb +8 -8
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +23 -23
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +69 -0
- data/spec/lib/tcell_agent/rails/dlp_spec.rb +1039 -0
- data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +271 -0
- data/spec/lib/tcell_agent/rails/logger_spec.rb +5 -5
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +3 -3
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +4 -4
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +5 -5
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +1 -1
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +11 -8
- data/spec/lib/tcell_agent/rails/responses_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +1 -1
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +4 -4
- data/spec/lib/tcell_agent/rust/models_spec.rb +83 -75
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +14 -14
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +19 -70
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +1 -1
- data/spec/lib/tcell_agent/settings_reporter_spec.rb +162 -0
- data/spec/lib/tcell_agent/tcell_context_spec.rb +154 -0
- data/spec/spec_helper.rb +5 -0
- metadata +18 -10
- data/lib/tcell_agent/appsensor/meta_data.rb +0 -132
- data/lib/tcell_agent/patches/meta_data.rb +0 -59
- data/lib/tcell_agent/rust/tcellagent-1.3.0.dll +0 -0
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +0 -71
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fee1b53b8297dddbb44b9f4ae21b6371f61b138
|
4
|
+
data.tar.gz: a78a2255a86ff92852a058b58699acd5537c13e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23478b101ec414872fb96958c4de2208ad099d898513636e50c5ff22b18ff660b4d73068e0ebfc405a9512c56426ef4d189753f03280c6e1d80d541ff0fd1476
|
7
|
+
data.tar.gz: ea0ce97ae0cbf568cace44c6cfed0a39de4954bec81d0e5e2f012c0a7f710de4ddf19226024d36bac23c00bffdba93b9a64a2d54a69ec62355c5c8a8be37b903
|
data/bin/tcell_agent
CHANGED
@@ -227,9 +227,17 @@ elsif command == 'test'
|
|
227
227
|
end
|
228
228
|
puts 'passed'
|
229
229
|
|
230
|
-
printf '%-50s', 'Application has
|
230
|
+
printf '%-50s', 'Application has app_id... '
|
231
231
|
tcell_application = config_hash.fetch('applications')[0]
|
232
|
-
if !tcell_application.key?('app_id')
|
232
|
+
if !tcell_application.key?('app_id') && !ENV['TCELL_AGENT_APP_ID']
|
233
|
+
puts 'failed'
|
234
|
+
Kernel.exit(1)
|
235
|
+
end
|
236
|
+
puts 'passed'
|
237
|
+
|
238
|
+
printf '%-50s', 'Application has api_key... '
|
239
|
+
tcell_application = config_hash.fetch('applications')[0]
|
240
|
+
if !tcell_application.key?('api_key') && !ENV['TCELL_AGENT_API_KEY']
|
233
241
|
puts 'failed'
|
234
242
|
Kernel.exit(1)
|
235
243
|
end
|
data/lib/tcell_agent.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# See the file "LICENSE" for the full license governing this code.
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'tcell_agent/utils/passwords'
|
4
|
+
require 'tcell_agent/utils/strings'
|
5
|
+
require 'tcell_agent/utils/io'
|
6
6
|
require 'tcell_agent/logger'
|
7
7
|
require 'tcell_agent/configuration'
|
8
8
|
|
data/lib/tcell_agent/agent.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
# See the file "LICENSE" for the full license governing this code.
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require 'tcell_agent/logger'
|
4
|
+
require 'tcell_agent/version'
|
5
|
+
require 'tcell_agent/api'
|
6
|
+
require 'tcell_agent/configuration'
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
8
|
+
require 'tcell_agent/sensor_events/server_agent'
|
9
|
+
require 'tcell_agent/utils/queue_with_timeout'
|
10
10
|
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
11
|
+
require 'tcell_agent/agent/event_processor'
|
12
|
+
require 'tcell_agent/agent/policy_manager'
|
13
|
+
require 'tcell_agent/agent/static_agent'
|
14
|
+
require 'tcell_agent/agent/policy_types'
|
15
|
+
require 'tcell_agent/agent/route_manager'
|
16
|
+
require 'tcell_agent/agent/fork_pipe_manager'
|
17
17
|
|
18
|
-
require
|
18
|
+
require 'tcell_agent/routes/table'
|
19
19
|
|
20
20
|
require 'net/http'
|
21
21
|
require 'thread'
|
@@ -25,9 +25,8 @@ require 'monitor'
|
|
25
25
|
|
26
26
|
module TCellAgent
|
27
27
|
class Agent
|
28
|
-
|
29
28
|
attr_accessor :start_pid
|
30
|
-
attr_accessor :
|
29
|
+
attr_accessor :event_queue
|
31
30
|
|
32
31
|
attr_accessor :fork_event_queue
|
33
32
|
attr_accessor :fork_event_thread
|
@@ -49,53 +48,46 @@ module TCellAgent
|
|
49
48
|
attr_accessor :policy_polling_thread
|
50
49
|
attr_accessor :policy_polling_worker_mutex
|
51
50
|
|
52
|
-
|
53
51
|
attr_accessor :event_queue_monitor
|
54
52
|
attr_accessor :event_dispatch_monitor
|
55
53
|
|
56
54
|
attr_accessor :stop_agent
|
57
55
|
attr_accessor :complete_policy_cache
|
58
56
|
|
59
|
-
|
60
|
-
def initialize(start_pid=Process.pid)
|
57
|
+
def initialize(start_pid = Process.pid)
|
61
58
|
@start_pid = start_pid
|
62
|
-
@
|
63
|
-
@
|
59
|
+
@dispatch_events_timeout = TCellAgent.configuration.event_time_limit_seconds || 55
|
60
|
+
@dispatch_events_limit = TCellAgent.configuration.event_batch_size_limit || 20
|
64
61
|
@worker_mutex = Mutex.new
|
65
62
|
@policy_polling_worker_mutex = Mutex.new
|
66
63
|
@@policy_tapi = TCellApi.new
|
67
64
|
|
68
65
|
# Agent request thread
|
69
66
|
@policies = {
|
70
|
-
TCellAgent::PolicyTypes::
|
67
|
+
TCellAgent::PolicyTypes::RUST => TCellAgent::Policies::RustPolicies.new
|
71
68
|
}
|
72
69
|
@lock = Monitor.new
|
73
70
|
|
74
|
-
|
71
|
+
initialize_processor_variables
|
75
72
|
|
76
|
-
if TCellAgent.configuration.preload_policy_filename
|
77
|
-
TCellAgent.logger.info(
|
73
|
+
if TCellAgent.configuration.preload_policy_filename
|
74
|
+
TCellAgent.logger.info('Preloading a policy file')
|
78
75
|
begin
|
79
76
|
policy_file = File.open(TCellAgent.configuration.preload_policy_filename).read
|
80
77
|
policy_jsons = JSON.parse(policy_file)
|
81
|
-
if policy_jsons.key?(
|
82
|
-
|
83
|
-
end
|
84
|
-
processPolicyJson(policy_jsons, false)
|
78
|
+
policy_jsons = policy_jsons['result'] if policy_jsons.key?('result')
|
79
|
+
process_policy_json(policy_jsons, false)
|
85
80
|
rescue StandardError => e
|
86
81
|
TCellAgent.logger.error(e.message)
|
87
82
|
end
|
88
83
|
end
|
89
84
|
cached_policies = policies_from_cachefile
|
90
|
-
if
|
91
|
-
processPolicyJson(cached_policies, false)
|
92
|
-
end
|
85
|
+
process_policy_json(cached_policies, false) if cached_policies
|
93
86
|
end
|
94
87
|
|
95
88
|
def initialize_processor_variables
|
96
89
|
@complete_policy_cache = {}
|
97
90
|
|
98
|
-
@metricsLock = Monitor.new
|
99
91
|
@stop_agent = false
|
100
92
|
@route_table = TCellAgent::Routes::RouteTable.new
|
101
93
|
|
@@ -103,43 +95,41 @@ module TCellAgent
|
|
103
95
|
@event_dispatch_monitor = Monitor.new
|
104
96
|
@mutex = Monitor.new
|
105
97
|
|
106
|
-
|
107
98
|
@response_time_table = {}
|
108
99
|
@sessions_metrics = TCellAgent::SensorEvents::SessionsMetric.new
|
109
100
|
@sessions_metrics_mutex = Monitor.new
|
110
101
|
|
111
|
-
@
|
112
|
-
@
|
102
|
+
@dispatch_events = []
|
103
|
+
@event_queue = BoundedQueue.new(200)
|
113
104
|
|
114
|
-
@fork_event_queue=Queue.new
|
115
|
-
@fork_event_thread_mutex=Monitor.new
|
105
|
+
@fork_event_queue = Queue.new
|
106
|
+
@fork_event_thread_mutex = Monitor.new
|
116
107
|
|
117
|
-
@metrics_event_queue=Queue.new
|
118
|
-
@metrics_event_thread_mutex=Monitor.new
|
108
|
+
@metrics_event_queue = Queue.new
|
109
|
+
@metrics_event_thread_mutex = Monitor.new
|
119
110
|
end
|
120
111
|
|
121
|
-
def
|
112
|
+
def parent_process?
|
122
113
|
@start_pid == Process.pid
|
123
114
|
end
|
124
115
|
|
125
116
|
def start
|
126
|
-
if
|
127
|
-
|
128
|
-
puts
|
129
|
-
puts
|
130
|
-
puts
|
131
|
-
puts
|
132
|
-
puts
|
133
|
-
puts
|
117
|
+
if TCellAgent::Utils::Strings.blank?(TCellAgent.configuration.api_key) ||
|
118
|
+
TCellAgent::Utils::Strings.blank?(TCellAgent.configuration.app_id)
|
119
|
+
puts ' ********* ********* ********* *********'
|
120
|
+
puts '* tCell.io *'
|
121
|
+
puts '* Configuration info is missing, you may *'
|
122
|
+
puts '* need to download config file and place *'
|
123
|
+
puts '* it in the config/ directory *'
|
124
|
+
puts ' ********* ********* ********* *********'
|
134
125
|
TCellAgent.configuration.enabled = false
|
135
126
|
return
|
136
127
|
end
|
137
128
|
|
138
|
-
TCellAgent.logger.debug(
|
129
|
+
TCellAgent.logger.debug('Starting thread agent')
|
139
130
|
|
140
|
-
|
141
|
-
|
131
|
+
ensure_policy_polling_running
|
132
|
+
ensure_event_processor_running
|
142
133
|
end
|
143
|
-
|
144
134
|
end
|
145
135
|
end
|
@@ -1,37 +1,33 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
# See the file "LICENSE" for the full license governing this code.
|
4
2
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
3
|
+
require 'tcell_agent/logger'
|
4
|
+
require 'tcell_agent/version'
|
5
|
+
require 'tcell_agent/api'
|
6
|
+
require 'tcell_agent/configuration'
|
9
7
|
|
10
|
-
require
|
11
|
-
require
|
8
|
+
require 'tcell_agent/policies/http_tx_policy'
|
9
|
+
require 'tcell_agent/policies/http_redirect_policy'
|
12
10
|
|
13
|
-
require
|
14
|
-
require
|
11
|
+
require 'tcell_agent/sensor_events/server_agent'
|
12
|
+
require 'tcell_agent/sensor_events/metrics'
|
15
13
|
|
16
|
-
require
|
14
|
+
require 'tcell_agent/utils/queue_with_timeout'
|
17
15
|
|
18
|
-
require
|
19
|
-
require
|
16
|
+
require 'tcell_agent/agent/fork_pipe_manager'
|
17
|
+
require 'tcell_agent/agent/static_agent'
|
20
18
|
|
21
19
|
require 'net/http'
|
22
20
|
require 'thread'
|
23
21
|
require 'logger'
|
24
22
|
require 'json'
|
25
23
|
|
26
|
-
|
27
24
|
module TCellAgent
|
28
|
-
class Agent
|
29
|
-
|
25
|
+
class Agent # rubocop:disable Metrics/ClassLength
|
30
26
|
# cmdi events are special because they can be triggered very easily by running any shell command.
|
31
27
|
# Startup scripts are likely to run shell commands. It's not a good idea to startup the event
|
32
28
|
# processor before worker processses are forked, so the safest thing to do is let a different
|
33
29
|
# event start the event processor to avoid deadlocking worker processes.
|
34
|
-
def safe_to_send_cmdi_events?
|
30
|
+
def safe_to_send_cmdi_events?
|
35
31
|
event_processor_running?
|
36
32
|
end
|
37
33
|
|
@@ -40,71 +36,63 @@ module TCellAgent
|
|
40
36
|
return if TCellAgent.configuration.should_start_event_manager? == false
|
41
37
|
@worker_mutex.synchronize do
|
42
38
|
return if event_processor_running?
|
43
|
-
if
|
44
|
-
self.initialize_processor_variables
|
45
|
-
end
|
39
|
+
initialize_processor_variables if parent_process? == false
|
46
40
|
start_event_processor
|
47
41
|
end
|
48
42
|
end
|
49
43
|
|
50
44
|
def event_processor_running?
|
51
|
-
if TCellAgent::Agent.
|
52
|
-
return true
|
53
|
-
end
|
45
|
+
return true if TCellAgent::Agent.parent_process? == false
|
54
46
|
@event_processor_thread && @event_processor_thread.alive?
|
55
47
|
end
|
56
48
|
|
57
49
|
def stop_event_processor
|
58
|
-
TCellAgent.logger.debug(
|
59
|
-
if @event_processor_thread && @event_processor_thread.alive?
|
60
|
-
@event_processor_thread.exit
|
61
|
-
end
|
50
|
+
TCellAgent.logger.debug('Stopping event processor thread')
|
51
|
+
@event_processor_thread.exit if @event_processor_thread && @event_processor_thread.alive?
|
62
52
|
end
|
63
53
|
|
64
54
|
def send_dispatch_events(tapi)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
if @sessions_metrics.has_sessions?
|
79
|
-
sessions_to_send = []
|
80
|
-
@sessions_metrics_mutex.synchronize do
|
81
|
-
sessions_to_send = @sessions_metrics
|
82
|
-
@sessions_metrics = TCellAgent::SensorEvents::SessionsMetric.new
|
83
|
-
end
|
84
|
-
events_to_send.push( sessions_to_send )
|
55
|
+
events_to_send = []
|
56
|
+
@event_dispatch_monitor.synchronize do
|
57
|
+
events_to_send = @dispatch_events
|
58
|
+
@dispatch_events = []
|
59
|
+
end
|
60
|
+
|
61
|
+
unless @response_time_table.empty?
|
62
|
+
metrics_event = TCellAgent::SensorEvents::MetricsEvent.new
|
63
|
+
metrics_event.set_route_count_table(@response_time_table)
|
64
|
+
events_to_send.push(metrics_event)
|
65
|
+
@mutex.synchronize do
|
66
|
+
@response_time_table = {}
|
85
67
|
end
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
68
|
+
end
|
69
|
+
|
70
|
+
if @sessions_metrics.sessions?
|
71
|
+
sessions_to_send = []
|
72
|
+
@sessions_metrics_mutex.synchronize do
|
73
|
+
sessions_to_send = @sessions_metrics
|
74
|
+
@sessions_metrics = TCellAgent::SensorEvents::SessionsMetric.new
|
92
75
|
end
|
93
|
-
|
76
|
+
events_to_send.push(sessions_to_send)
|
77
|
+
end
|
78
|
+
|
79
|
+
return if tapi.send_event_set(events_to_send)
|
94
80
|
|
81
|
+
ensured_events = events_to_send.find_all { |item| item.ensure == true }
|
82
|
+
@event_dispatch_monitor.synchronize do
|
83
|
+
@dispatch_events.push(*ensured_events)
|
84
|
+
end
|
85
|
+
end
|
95
86
|
|
96
|
-
def start_event_processor(send_empties=true)
|
87
|
+
def start_event_processor(send_empties = true)
|
97
88
|
return if TCellAgent.configuration.should_start_event_manager? == false
|
98
89
|
|
99
|
-
if TCellAgent::Agent.
|
100
|
-
return
|
101
|
-
end
|
90
|
+
return if TCellAgent::Agent.parent_process? == false
|
102
91
|
|
103
|
-
TCellAgent.logger.debug(
|
92
|
+
TCellAgent.logger.debug('Starting event processor thread')
|
104
93
|
@events_send_empties = send_empties
|
105
94
|
Thread.abort_on_exception = true
|
106
95
|
@event_processor_thread = Thread.new do
|
107
|
-
|
108
96
|
begin
|
109
97
|
tapi = TCellApi.new
|
110
98
|
|
@@ -113,30 +101,32 @@ module TCellAgent
|
|
113
101
|
begin
|
114
102
|
begin
|
115
103
|
now = Time.now
|
116
|
-
wait_for = @
|
117
|
-
event = @
|
118
|
-
if event
|
119
|
-
if
|
104
|
+
wait_for = @dispatch_events_timeout - (now - last_run_time).to_i.abs
|
105
|
+
event = @event_queue.pop([wait_for, 1].max)
|
106
|
+
if event.nil?
|
107
|
+
if @events_send_empties || !@dispatch_events.empty?
|
120
108
|
last_run_time = Time.now
|
121
|
-
|
109
|
+
send_dispatch_events(tapi)
|
122
110
|
end
|
123
111
|
else
|
124
112
|
event.post_process
|
125
113
|
if event.send == true
|
126
|
-
@event_dispatch_monitor.synchronize
|
127
|
-
@
|
128
|
-
|
114
|
+
@event_dispatch_monitor.synchronize do
|
115
|
+
@dispatch_events.push(event)
|
116
|
+
end
|
129
117
|
end
|
130
|
-
if
|
118
|
+
if event.flush || @dispatch_events.length >= @dispatch_events_limit || wait_for < 0
|
131
119
|
last_run_time = Time.now
|
132
|
-
|
120
|
+
send_dispatch_events(tapi)
|
133
121
|
end
|
134
122
|
end
|
135
|
-
rescue ThreadError
|
123
|
+
rescue ThreadError => te
|
124
|
+
TCellAgent.logger.error("ThreadError while processing events: #{te.message}")
|
125
|
+
TCellAgent.logger.debug(te.backtrace)
|
136
126
|
last_run_time = Time.now
|
137
|
-
@event_dispatch_monitor.synchronize
|
138
|
-
@
|
139
|
-
|
127
|
+
@event_dispatch_monitor.synchronize do
|
128
|
+
@dispatch_events = []
|
129
|
+
end
|
140
130
|
end
|
141
131
|
rescue TCellAgent::ConfigurationException
|
142
132
|
Thread.exit
|
@@ -144,18 +134,16 @@ module TCellAgent
|
|
144
134
|
last_run_time = Time.now
|
145
135
|
TCellAgent.logger.error("Exception while processing events: #{e.message}")
|
146
136
|
TCellAgent.logger.debug(e.backtrace)
|
147
|
-
@event_dispatch_monitor.synchronize
|
148
|
-
@
|
149
|
-
|
137
|
+
@event_dispatch_monitor.synchronize do
|
138
|
+
@dispatch_events = []
|
139
|
+
end
|
150
140
|
end
|
151
141
|
end
|
152
142
|
rescue StandardError => xyz
|
153
143
|
TCellAgent.logger.error("Exception while starting processor: #{xyz.message}")
|
154
144
|
TCellAgent.logger.debug(xyz.backtrace)
|
155
145
|
end
|
156
|
-
|
157
146
|
end
|
158
|
-
|
159
147
|
end
|
160
148
|
|
161
149
|
def ensure_fork_event_thread_running
|
@@ -167,46 +155,38 @@ module TCellAgent
|
|
167
155
|
end
|
168
156
|
|
169
157
|
def event_fork_thread_running?
|
170
|
-
if TCellAgent::Agent.
|
171
|
-
return true
|
172
|
-
end
|
158
|
+
return true if TCellAgent::Agent.parent_process?
|
173
159
|
@fork_event_thread && @fork_event_thread.alive?
|
174
160
|
end
|
175
161
|
|
176
162
|
def start_fork_event_thread
|
177
163
|
@fork_event_thread = Thread.new do
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
TCellAgent::Agent.send_to_event_pipe(event)
|
186
|
-
end
|
187
|
-
rescue StandardError => e
|
188
|
-
TCellAgent.logger.error("Exception while processing (forked) events: #{e.message}")
|
189
|
-
TCellAgent.logger.debug(e.backtrace)
|
164
|
+
loop do
|
165
|
+
begin
|
166
|
+
event = @fork_event_queue.pop
|
167
|
+
if event.send
|
168
|
+
TCellAgent::Agent.send_to_event_pipe(event)
|
169
|
+
else
|
170
|
+
event.post_process
|
190
171
|
end
|
172
|
+
rescue StandardError => e
|
173
|
+
TCellAgent.logger.error("Exception while processing (forked) events: #{e.message}")
|
174
|
+
TCellAgent.logger.debug(e.backtrace)
|
191
175
|
end
|
192
|
-
rescue StandardError => e
|
193
|
-
TCellAgent.logger.error("Exception while running (forked) events: #{e.message}")
|
194
|
-
TCellAgent.logger.debug(e.backtrace)
|
195
176
|
end
|
196
177
|
end
|
197
178
|
end
|
198
179
|
|
199
180
|
def queue_forked_event(event)
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
return
|
205
|
-
end
|
206
|
-
@fork_event_queue.push(event)
|
207
|
-
rescue StandardError => queue_exception
|
208
|
-
TCellAgent.logger.debug("Could not add (forked) event #{queue_exception.message}")
|
181
|
+
ensure_fork_event_thread_running
|
182
|
+
if @fork_event_queue.length > 100
|
183
|
+
TCellAgent.logger.debug('Dropping (forked) event because queue full')
|
184
|
+
return
|
209
185
|
end
|
186
|
+
@fork_event_queue.push(event)
|
187
|
+
rescue StandardError => queue_exception
|
188
|
+
TCellAgent.logger.debug("Could not add (forked) event #{queue_exception.message}")
|
189
|
+
TCellAgent.logger.debug(queue_exception.backtrace)
|
210
190
|
end
|
211
191
|
|
212
192
|
def ensure_metrics_event_thread_running
|
@@ -218,17 +198,13 @@ module TCellAgent
|
|
218
198
|
end
|
219
199
|
|
220
200
|
def event_metrics_thread_running?
|
221
|
-
if TCellAgent::Agent.
|
222
|
-
return true
|
223
|
-
end
|
201
|
+
return true if TCellAgent::Agent.parent_process?
|
224
202
|
@metrics_event_thread && @metrics_event_thread.alive?
|
225
203
|
end
|
226
204
|
|
227
205
|
def stop_metrics_event_thread
|
228
|
-
TCellAgent.logger.debug(
|
229
|
-
if @metrics_event_thread && @metrics_event_thread.alive?
|
230
|
-
@metrics_event_thread.exit
|
231
|
-
end
|
206
|
+
TCellAgent.logger.debug('Stopping metrics event thread')
|
207
|
+
@metrics_event_thread.exit if @metrics_event_thread && @metrics_event_thread.alive?
|
232
208
|
end
|
233
209
|
|
234
210
|
def start_metrics_event_thread
|
@@ -247,54 +223,50 @@ module TCellAgent
|
|
247
223
|
end
|
248
224
|
|
249
225
|
def _queue_metric(event)
|
250
|
-
return
|
226
|
+
return unless TCellAgent.configuration.should_consume_event?
|
227
|
+
|
251
228
|
begin
|
252
|
-
|
253
|
-
if
|
254
|
-
TCellAgent.logger.debug(
|
229
|
+
ensure_metrics_event_thread_running
|
230
|
+
if @metrics_event_queue.length > 100
|
231
|
+
TCellAgent.logger.debug('Dropping (forked) metric because queue full')
|
255
232
|
return
|
256
233
|
end
|
257
234
|
@metrics_event_queue.push(event)
|
258
235
|
rescue StandardError => queue_exception
|
259
236
|
TCellAgent.logger.debug("Could not add (forked) metric #{queue_exception.message}")
|
237
|
+
TCellAgent.logger.debug(queue_exception.backtrace)
|
260
238
|
end
|
261
239
|
end
|
262
240
|
|
263
|
-
def
|
264
|
-
return
|
265
|
-
begin
|
266
|
-
if TCellAgent::Agent.is_parent_process? == false
|
267
|
-
self.queue_forked_event(event)
|
268
|
-
return
|
269
|
-
end
|
241
|
+
def queue_sensor_event(event)
|
242
|
+
return unless TCellAgent.configuration.should_consume_event?
|
270
243
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
}
|
244
|
+
if TCellAgent::Agent.parent_process? == false
|
245
|
+
queue_forked_event(event)
|
246
|
+
return
|
247
|
+
end
|
276
248
|
|
277
|
-
|
278
|
-
|
249
|
+
begin
|
250
|
+
ensure_event_processor_running
|
251
|
+
@event_queue_monitor.synchronize do
|
252
|
+
@event_queue.push(event, 10)
|
279
253
|
end
|
280
|
-
|
281
254
|
rescue StandardError => queue_exception
|
282
|
-
TCellAgent.logger.debug("
|
255
|
+
TCellAgent.logger.debug("Dropping event because queue full #{queue_exception.message}")
|
256
|
+
TCellAgent.logger.debug(queue_exception.backtrace)
|
283
257
|
end
|
284
258
|
end
|
285
259
|
|
286
260
|
def increment_session_info(hmac_session_id, user_id, ip_address, user_agent)
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
"user_agent" => user_agent
|
297
|
-
})
|
261
|
+
TCellAgent::Instrumentation.safe_block('Incrementing session info') do
|
262
|
+
if TCellAgent::Agent.parent_process? == false
|
263
|
+
TCellAgent.queue_metric(
|
264
|
+
'_type' => 'increment_session_info',
|
265
|
+
'hmac_session_id' => hmac_session_id,
|
266
|
+
'user_id' => user_id,
|
267
|
+
'ip_address' => ip_address,
|
268
|
+
'user_agent' => user_agent
|
269
|
+
)
|
298
270
|
return
|
299
271
|
end
|
300
272
|
|
@@ -309,29 +281,24 @@ module TCellAgent
|
|
309
281
|
end
|
310
282
|
|
311
283
|
def increment_route(route_id, response_time)
|
312
|
-
TCellAgent::Instrumentation.safe_block(
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
})
|
284
|
+
TCellAgent::Instrumentation.safe_block('Incrementing route') do
|
285
|
+
if TCellAgent::Agent.parent_process? == false
|
286
|
+
TCellAgent.queue_metric(
|
287
|
+
'_type' => 'increment_route',
|
288
|
+
'route_id' => route_id,
|
289
|
+
'response_time' => response_time
|
290
|
+
)
|
320
291
|
return
|
321
292
|
end
|
322
293
|
@mutex.synchronize do
|
323
|
-
if
|
324
|
-
|
325
|
-
|
326
|
-
@response_time_table[route_id] = @response_time_table.fetch(
|
327
|
-
@response_time_table[route_id][
|
328
|
-
@response_time_table[route_id][
|
329
|
-
@response_time_table[route_id]["mn"] = [@response_time_table[route_id].fetch("mn",response_time), response_time].min
|
330
|
-
@response_time_table[route_id]["t"] = ((@response_time_table[route_id].fetch("t",0)*(@response_time_table[route_id]["c"]-1)) + response_time) / @response_time_table[route_id]["c"]
|
294
|
+
route_id = '?' if route_id.nil? || route_id == ''
|
295
|
+
@response_time_table[route_id] = @response_time_table.fetch(route_id, {})
|
296
|
+
@response_time_table[route_id]['c'] = @response_time_table[route_id].fetch('c', 0) + 1
|
297
|
+
@response_time_table[route_id]['mx'] = [@response_time_table[route_id].fetch('mx', 0), response_time].max
|
298
|
+
@response_time_table[route_id]['mn'] = [@response_time_table[route_id].fetch('mn', response_time), response_time].min
|
299
|
+
@response_time_table[route_id]['t'] = ((@response_time_table[route_id].fetch('t', 0) * (@response_time_table[route_id]['c'] - 1)) + response_time) / @response_time_table[route_id]['c']
|
331
300
|
end
|
332
|
-
|
333
301
|
end
|
334
302
|
end
|
335
|
-
|
336
303
|
end
|
337
304
|
end
|