tingyun_rpm 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +14 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +3 -0
- data/Guardfile +25 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/cert/cacert.pem +0 -0
- data/lib/ting_yun/agent/agent.rb +128 -0
- data/lib/ting_yun/agent/class_methods.rb +21 -0
- data/lib/ting_yun/agent/collector/base_sampler.rb +2 -0
- data/lib/ting_yun/agent/collector/error_collector/error_trace_array.rb +88 -0
- data/lib/ting_yun/agent/collector/error_collector/noticed_error.rb +129 -0
- data/lib/ting_yun/agent/collector/error_collector.rb +165 -0
- data/lib/ting_yun/agent/collector/middle_ware_collector/cpu_sampler.rb +68 -0
- data/lib/ting_yun/agent/collector/middle_ware_collector/memory_sampler.rb +139 -0
- data/lib/ting_yun/agent/collector/middle_ware_collector/middle_ware.rb +13 -0
- data/lib/ting_yun/agent/collector/middle_ware_collector/sampler.rb +59 -0
- data/lib/ting_yun/agent/collector/middle_ware_collector.rb +80 -0
- data/lib/ting_yun/agent/collector/sql_sampler.rb +299 -0
- data/lib/ting_yun/agent/collector/stats_engine/metric_stats.rb +170 -0
- data/lib/ting_yun/agent/collector/stats_engine/stats_hash.rb +172 -0
- data/lib/ting_yun/agent/collector/stats_engine.rb +28 -0
- data/lib/ting_yun/agent/collector/transaction_sampler/slowest_sample_buffer.rb +25 -0
- data/lib/ting_yun/agent/collector/transaction_sampler/transaction_sample_buffer_base.rb +96 -0
- data/lib/ting_yun/agent/collector/transaction_sampler.rb +226 -0
- data/lib/ting_yun/agent/container_data_manager.rb +94 -0
- data/lib/ting_yun/agent/cross_app/cross_app_monitor.rb +131 -0
- data/lib/ting_yun/agent/cross_app/cross_app_tracing.rb +202 -0
- data/lib/ting_yun/agent/cross_app/inbound_request_monitor.rb +22 -0
- data/lib/ting_yun/agent/database.rb +410 -0
- data/lib/ting_yun/agent/datastore/metric_helper.rb +82 -0
- data/lib/ting_yun/agent/datastore/mongo.rb +44 -0
- data/lib/ting_yun/agent/datastore.rb +33 -0
- data/lib/ting_yun/agent/dispatcher.rb +39 -0
- data/lib/ting_yun/agent/event/event_listener.rb +47 -0
- data/lib/ting_yun/agent/event/event_loop.rb +194 -0
- data/lib/ting_yun/agent/instance_methods/connect.rb +164 -0
- data/lib/ting_yun/agent/instance_methods/container_data_manager.rb +137 -0
- data/lib/ting_yun/agent/instance_methods/handle_errors.rb +71 -0
- data/lib/ting_yun/agent/instance_methods/start.rb +219 -0
- data/lib/ting_yun/agent/instance_methods/start_worker_thread.rb +51 -0
- data/lib/ting_yun/agent/instance_methods.rb +39 -0
- data/lib/ting_yun/agent/method_tracer.rb +256 -0
- data/lib/ting_yun/agent/method_tracer_helpers.rb +85 -0
- data/lib/ting_yun/agent/threading/agent_thread.rb +49 -0
- data/lib/ting_yun/agent/transaction/attributes.rb +22 -0
- data/lib/ting_yun/agent/transaction/request_attributes.rb +126 -0
- data/lib/ting_yun/agent/transaction/trace.rb +125 -0
- data/lib/ting_yun/agent/transaction/trace_node.rb +110 -0
- data/lib/ting_yun/agent/transaction/traced_method_stack.rb +80 -0
- data/lib/ting_yun/agent/transaction/transaction_metrics.rb +51 -0
- data/lib/ting_yun/agent/transaction/transaction_sample_builder.rb +63 -0
- data/lib/ting_yun/agent/transaction/transaction_state.rb +112 -0
- data/lib/ting_yun/agent/transaction.rb +522 -0
- data/lib/ting_yun/agent.rb +207 -0
- data/lib/ting_yun/configuration/default_source.rb +638 -0
- data/lib/ting_yun/configuration/dotted_hash.rb +46 -0
- data/lib/ting_yun/configuration/environment_source.rb +116 -0
- data/lib/ting_yun/configuration/manager.rb +232 -0
- data/lib/ting_yun/configuration/manual_source.rb +14 -0
- data/lib/ting_yun/configuration/server_source.rb +88 -0
- data/lib/ting_yun/configuration/yaml_source.rb +136 -0
- data/lib/ting_yun/configuration.rb +9 -0
- data/lib/ting_yun/environment_report.rb +123 -0
- data/lib/ting_yun/frameworks/class_methods.rb +47 -0
- data/lib/ting_yun/frameworks/external.rb +15 -0
- data/lib/ting_yun/frameworks/instance_methods.rb +120 -0
- data/lib/ting_yun/frameworks/instrumentation.rb +67 -0
- data/lib/ting_yun/frameworks/rails.rb +63 -0
- data/lib/ting_yun/frameworks/rails3.rb +26 -0
- data/lib/ting_yun/frameworks/rails4.rb +14 -0
- data/lib/ting_yun/frameworks/ruby.rb +17 -0
- data/lib/ting_yun/frameworks/sinatra.rb +10 -0
- data/lib/ting_yun/frameworks.rb +34 -0
- data/lib/ting_yun/http/generic_request.rb +8 -0
- data/lib/ting_yun/http/net_http_request.rb +46 -0
- data/lib/ting_yun/instrumentation/active_record.rb +103 -0
- data/lib/ting_yun/instrumentation/middleware_proxy.rb +77 -0
- data/lib/ting_yun/instrumentation/middleware_tracing.rb +84 -0
- data/lib/ting_yun/instrumentation/mongo.rb +103 -0
- data/lib/ting_yun/instrumentation/mongo2.rb +37 -0
- data/lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb +97 -0
- data/lib/ting_yun/instrumentation/moped.rb +95 -0
- data/lib/ting_yun/instrumentation/net.rb +59 -0
- data/lib/ting_yun/instrumentation/rack.rb +109 -0
- data/lib/ting_yun/instrumentation/rails3/action_controller.rb +63 -0
- data/lib/ting_yun/instrumentation/rails3/action_view.rb +115 -0
- data/lib/ting_yun/instrumentation/rails4/action_controller_subscriber.rb +124 -0
- data/lib/ting_yun/instrumentation/rails4/action_view_subscriber.rb +118 -0
- data/lib/ting_yun/instrumentation/rails4/active_record_subscriber.rb +124 -0
- data/lib/ting_yun/instrumentation/rails_middleware.rb +38 -0
- data/lib/ting_yun/instrumentation/redis.rb +70 -0
- data/lib/ting_yun/instrumentation/support/active_record_helper.rb +178 -0
- data/lib/ting_yun/instrumentation/support/controller_instrumentation.rb +54 -0
- data/lib/ting_yun/instrumentation/support/database.rb +38 -0
- data/lib/ting_yun/instrumentation/support/event_formatter.rb +19 -0
- data/lib/ting_yun/instrumentation/support/evented_subscriber.rb +97 -0
- data/lib/ting_yun/instrumentation/support/external_error.rb +52 -0
- data/lib/ting_yun/instrumentation/support/metric_translator.rb +84 -0
- data/lib/ting_yun/instrumentation/support/mongo_formatter.rb +49 -0
- data/lib/ting_yun/instrumentation/support/parameter_filtering.rb +21 -0
- data/lib/ting_yun/instrumentation/support/queue_time.rb +76 -0
- data/lib/ting_yun/instrumentation/support/transaction_namer.rb +68 -0
- data/lib/ting_yun/instrumentation/thrift.rb +329 -0
- data/lib/ting_yun/logger/agent_logger.rb +196 -0
- data/lib/ting_yun/logger/log_once.rb +38 -0
- data/lib/ting_yun/logger/memory_logger.rb +56 -0
- data/lib/ting_yun/logger/null_logger.rb +31 -0
- data/lib/ting_yun/logger/startup_logger.rb +13 -0
- data/lib/ting_yun/logger.rb +8 -0
- data/lib/ting_yun/metrics/metric_data.rb +86 -0
- data/lib/ting_yun/metrics/metric_spec.rb +89 -0
- data/lib/ting_yun/metrics/stats.rb +158 -0
- data/lib/ting_yun/metrics.rb +12 -0
- data/lib/ting_yun/support/coerce.rb +86 -0
- data/lib/ting_yun/support/collector.rb +29 -0
- data/lib/ting_yun/support/exception.rb +79 -0
- data/lib/ting_yun/support/hash_extensions.rb +25 -0
- data/lib/ting_yun/support/helper.rb +54 -0
- data/lib/ting_yun/support/hostname.rb +13 -0
- data/lib/ting_yun/support/http_clients/uri_util.rb +49 -0
- data/lib/ting_yun/support/language_support.rb +155 -0
- data/lib/ting_yun/support/library_detection.rb +129 -0
- data/lib/ting_yun/support/local_environment.rb +185 -0
- data/lib/ting_yun/support/path.rb +13 -0
- data/lib/ting_yun/support/serialize/encodes.rb +61 -0
- data/lib/ting_yun/support/serialize/encoding_normalizer.rb +84 -0
- data/lib/ting_yun/support/serialize/json_marshaller.rb +73 -0
- data/lib/ting_yun/support/serialize/json_wrapper.rb +78 -0
- data/lib/ting_yun/support/serialize/marshaller.rb +69 -0
- data/lib/ting_yun/support/serialize/ok_json.rb +651 -0
- data/lib/ting_yun/support/system_info.rb +206 -0
- data/lib/ting_yun/support/timer_lib.rb +29 -0
- data/lib/ting_yun/support/version_number.rb +70 -0
- data/lib/ting_yun/ting_yun_service/connection.rb +118 -0
- data/lib/ting_yun/ting_yun_service/http.rb +41 -0
- data/lib/ting_yun/ting_yun_service/request.rb +90 -0
- data/lib/ting_yun/ting_yun_service/ssl.rb +45 -0
- data/lib/ting_yun/ting_yun_service/upload_service.rb +149 -0
- data/lib/ting_yun/ting_yun_service.rb +124 -0
- data/lib/ting_yun/version.rb +17 -0
- data/lib/tingyun_rpm.rb +47 -0
- data/tingyun_rpm.gemspec +60 -0
- metadata +415 -0
@@ -0,0 +1,207 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under Ting Yun's license terms.
|
3
|
+
require 'ting_yun/configuration/manager'
|
4
|
+
require 'ting_yun/logger/startup_logger'
|
5
|
+
require 'ting_yun/frameworks'
|
6
|
+
require 'ting_yun/agent/transaction/transaction_state'
|
7
|
+
require 'ting_yun/agent/transaction'
|
8
|
+
require 'ting_yun/agent/collector/middle_ware_collector/middle_ware'
|
9
|
+
|
10
|
+
|
11
|
+
module TingYun
|
12
|
+
module Agent
|
13
|
+
extend self
|
14
|
+
|
15
|
+
@agent = nil
|
16
|
+
@logger = nil
|
17
|
+
@config = ::TingYun::Configuration::Manager.new
|
18
|
+
|
19
|
+
attr_reader :config
|
20
|
+
|
21
|
+
UNKNOWN_METRIC = '(unknown)'.freeze
|
22
|
+
|
23
|
+
def agent
|
24
|
+
return @agent if @agent
|
25
|
+
TingYun::Agent.logger.warn("Agent unavailable as it hasn't been started.")
|
26
|
+
TingYun::Agent.logger.warn(caller.join("\n"))
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
alias instance agent
|
31
|
+
|
32
|
+
def agent=(new_instance)
|
33
|
+
@agent = new_instance
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def logger
|
38
|
+
@logger || ::TingYun::Logger::StartupLogger.instance
|
39
|
+
end
|
40
|
+
|
41
|
+
def logger=(log)
|
42
|
+
@logger = log
|
43
|
+
end
|
44
|
+
|
45
|
+
def reset_config
|
46
|
+
@config.reset_to_defaults
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# Record a value for the given metric name.
|
51
|
+
#
|
52
|
+
# This method should be used to record event-based metrics such as method
|
53
|
+
# calls that are associated with a specific duration or magnitude.
|
54
|
+
#
|
55
|
+
# +metric_name+ should follow a slash separated path convention. Application
|
56
|
+
# specific metrics should begin with "Custom/".
|
57
|
+
#
|
58
|
+
# +value+ should be either a single Numeric value representing the duration/
|
59
|
+
# magnitude of the event being recorded, or a Hash containing :count,
|
60
|
+
# :total, :min, :max, and :sum_of_squares keys. The latter form is useful
|
61
|
+
# for recording pre-aggregated metrics collected externally.
|
62
|
+
#
|
63
|
+
# This method is safe to use from any thread.
|
64
|
+
#
|
65
|
+
# @api public
|
66
|
+
def record_metric(metric_name, value) #THREAD_LOCAL_ACCESS
|
67
|
+
return unless agent
|
68
|
+
stats = TingYun::Metrics::Stats.create_from_hash(value) if value.is_a?(Hash)
|
69
|
+
agent.stats_engine.tl_record_unscoped_metrics(metric_name, stats || value)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Manual agent configuration and startup/shutdown
|
73
|
+
|
74
|
+
# Call this to manually start the Agent in situations where the Agent does
|
75
|
+
# not auto-start.
|
76
|
+
#
|
77
|
+
# When the app environment loads, so does the Agent. However, the
|
78
|
+
# Agent will only connect to the service if a web front-end is found. If
|
79
|
+
# you want to selectively monitor ruby processes that don't use
|
80
|
+
# web plugins, then call this method in your code and the Agent
|
81
|
+
# will fire up and start reporting to the service.
|
82
|
+
#
|
83
|
+
# Options are passed in as overrides for values in the
|
84
|
+
# tingyun.yml, such as app_name. In addition, the option +log+
|
85
|
+
# will take a logger that will be used instead of the standard
|
86
|
+
# file logger. The setting for the tingyun.yml section to use
|
87
|
+
# (ie, RAILS_ENV) can be overridden with an :env argument.
|
88
|
+
#
|
89
|
+
# @api public
|
90
|
+
#
|
91
|
+
def manual_start(options={})
|
92
|
+
raise "Options must be a hash" unless Hash === options
|
93
|
+
TingYun::Frameworks.init_start({ :'nbs.agent_enabled' => true, :sync_startup => true }.merge(options))
|
94
|
+
end
|
95
|
+
|
96
|
+
# Yield to a block that is run with a database metric name context. This means
|
97
|
+
# the Database instrumentation will use this for the metric name if it does not
|
98
|
+
# otherwise know about a model. This is re-entrant.
|
99
|
+
#
|
100
|
+
# @param [String,Class,#to_s] model the DB model class
|
101
|
+
#
|
102
|
+
# @param [String] method the name of the finder method or other method to
|
103
|
+
# identify the operation with.
|
104
|
+
#
|
105
|
+
def with_database_metric_name(model, method = nil, product = nil, &block) #THREAD_LOCAL_ACCESS
|
106
|
+
if txn = TingYun::Agent::TransactionState.tl_get.current_transaction
|
107
|
+
txn.with_database_metric_name(model, method, product, &block)
|
108
|
+
else
|
109
|
+
yield
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
# Notice the error with the given available options:
|
115
|
+
#
|
116
|
+
# * <tt>:uri</tt> => Request path, minus request params or query string
|
117
|
+
# * <tt>:metric</tt> => The metric name associated with the transaction
|
118
|
+
# * <tt>:custom_params</tt> => Custom parameters
|
119
|
+
#
|
120
|
+
# @api public
|
121
|
+
#
|
122
|
+
def notice_error(exception, options={})
|
123
|
+
TingYun::Agent::Transaction.notice_error(exception, options)
|
124
|
+
nil # don't return a noticed error datastructure. it can only hurt.
|
125
|
+
end
|
126
|
+
|
127
|
+
# Register this method as a callback for processes that fork
|
128
|
+
# jobs.
|
129
|
+
#
|
130
|
+
# If the master/parent connects to the agent prior to forking the
|
131
|
+
# agent in the forked process will use that agent_run. Otherwise
|
132
|
+
# the forked process will establish a new connection with the
|
133
|
+
# server.
|
134
|
+
#
|
135
|
+
# Use this especially when you fork the process to run background
|
136
|
+
# jobs or other work. If you are doing this with a web dispatcher
|
137
|
+
# that forks worker processes then you will need to force the
|
138
|
+
# agent to reconnect, which it won't do by default. Passenger and
|
139
|
+
# Rainbows and Unicorn are already handled, nothing special needed for them.
|
140
|
+
#
|
141
|
+
# Options:
|
142
|
+
# * <tt>:force_reconnect => true</tt> to force the spawned process to
|
143
|
+
# establish a new connection, such as when forking a long running process.
|
144
|
+
# The default is false--it will only connect to the server if the parent
|
145
|
+
# had not connected.
|
146
|
+
# * <tt>:keep_retrying => false</tt> if we try to initiate a new
|
147
|
+
# connection, this tells me to only try it once so this method returns
|
148
|
+
# quickly if there is some kind of latency with the server.
|
149
|
+
#
|
150
|
+
# @api public
|
151
|
+
#
|
152
|
+
def after_fork(options={})
|
153
|
+
agent.after_fork(options) if agent
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
# Yield to the block without collecting any metrics or traces in
|
158
|
+
# any of the subsequent calls. If executed recursively, will keep
|
159
|
+
# track of the first entry point and turn on tracing again after
|
160
|
+
# leaving that block. This uses the thread local TransactionState.
|
161
|
+
#
|
162
|
+
# @api public
|
163
|
+
#
|
164
|
+
def disable_all_tracing
|
165
|
+
return yield unless agent
|
166
|
+
begin
|
167
|
+
agent.push_trace_execution_flag(false)
|
168
|
+
yield
|
169
|
+
ensure
|
170
|
+
agent.pop_trace_execution_flag
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
# Register this method as a callback for processes that fork
|
177
|
+
# jobs.
|
178
|
+
#
|
179
|
+
# If the master/parent connects to the agent prior to forking the
|
180
|
+
# agent in the forked process will use that agent_run. Otherwise
|
181
|
+
# the forked process will establish a new connection with the
|
182
|
+
# server.
|
183
|
+
#
|
184
|
+
# Use this especially when you fork the process to run background
|
185
|
+
# jobs or other work. If you are doing this with a web dispatcher
|
186
|
+
# that forks worker processes then you will need to force the
|
187
|
+
# agent to reconnect, which it won't do by default. Passenger and
|
188
|
+
# Rainbows and Unicorn are already handled, nothing special needed for them.
|
189
|
+
#
|
190
|
+
# Options:
|
191
|
+
# * <tt>:force_reconnect => true</tt> to force the spawned process to
|
192
|
+
# establish a new connection, such as when forking a long running process.
|
193
|
+
# The default is false--it will only connect to the server if the parent
|
194
|
+
# had not connected.
|
195
|
+
# * <tt>:keep_retrying => false</tt> if we try to initiate a new
|
196
|
+
# connection, this tells me to only try it once so this method returns
|
197
|
+
# quickly if there is some kind of latency with the server.
|
198
|
+
#
|
199
|
+
# @api public
|
200
|
+
#
|
201
|
+
def after_fork(options={})
|
202
|
+
agent.after_fork(options) if agent
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
end
|
207
|
+
end
|