Class: Puma::Plugin::Telemetry::Config
- Inherits:
-
Object
- Object
- Puma::Plugin::Telemetry::Config
- Defined in:
- lib/puma/plugin/telemetry/config.rb
Overview
Configuration object for plugin
Constant Summary collapse
- DEFAULT_PUMA_TELEMETRY =
[ # Total booted workers. 'workers.booted', # Total number of workers configured. 'workers.total', # Current number of threads spawned. 'workers.spawned_threads', # Maximum number of threads that can run . 'workers.max_threads', # Number of requests performed so far. 'workers.requests_count', # Number of requests waiting to be processed. 'queue.backlog', # Free capacity that could be utilized, i.e. if backlog # is growing, and we still have capacity available, it # could mean that load balancing is not performing well. 'queue.capacity' ].freeze
- TARGETS =
{ dogstatsd: Telemetry::Targets::DatadogStatsdTarget, io: Telemetry::Targets::IOTarget, open_telemetry: Telemetry::Targets::OpenTelemetryTarget }.freeze
Instance Attribute Summary collapse
-
#enabled ⇒ Object
Whenever telemetry should run with puma - default: false.
-
#frequency ⇒ Object
Seconds between publishing telemetry - default: 5.
-
#initial_delay ⇒ Object
Number of seconds to delay first telemetry - default: 5.
-
#puma_telemetry ⇒ Object
Which metrics to publish from puma stats.
-
#socket_parser ⇒ Object
Symbol representing method to parse the
Socket::Option, or the whole implementation as a lambda. -
#socket_telemetry ⇒ Object
Whenever to publish socket telemetry.
-
#targets ⇒ Object
List of targets which are meant to publish telemetry.
Instance Method Summary collapse
- #add_target(name_or_target, **args) ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #socket_telemetry! ⇒ Object
- #socket_telemetry? ⇒ Boolean
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
82 83 84 85 86 87 88 89 90 |
# File 'lib/puma/plugin/telemetry/config.rb', line 82 def initialize @enabled = false @initial_delay = 5 @frequency = 5 @targets = [] @puma_telemetry = DEFAULT_PUMA_TELEMETRY @socket_telemetry = false @socket_parser = :unpack end |
Instance Attribute Details
#enabled ⇒ Object
Whenever telemetry should run with puma
- default: false
43 44 45 |
# File 'lib/puma/plugin/telemetry/config.rb', line 43 def enabled @enabled end |
#frequency ⇒ Object
Seconds between publishing telemetry
- default: 5
51 52 53 |
# File 'lib/puma/plugin/telemetry/config.rb', line 51 def frequency @frequency end |
#initial_delay ⇒ Object
Number of seconds to delay first telemetry
- default: 5
47 48 49 |
# File 'lib/puma/plugin/telemetry/config.rb', line 47 def initial_delay @initial_delay end |
#puma_telemetry ⇒ Object
Which metrics to publish from puma stats. You can select a subset from default ones that interest you the most.
- default: DEFAULT_PUMA_TELEMETRY
62 63 64 |
# File 'lib/puma/plugin/telemetry/config.rb', line 62 def puma_telemetry @puma_telemetry end |
#socket_parser ⇒ Object
Symbol representing method to parse the Socket::Option, or
the whole implementation as a lambda. Available options:
:inspect, based on theSocket::Option#inspectmethod, it's the safest and slowest way to extract the info.inspectoutput might not be available, i.e. on AWS Fargate:unpack, parse binary data given bySocket::Option. Fastest way (12x compared toinspect) but depends on kernel headers and fields ordering within the struct. It should almost always match though. DEFAULT- proc/lambda,
Socket::Optionwill be given as an argument, it should return the value ofunackedfield as an integer.
80 81 82 |
# File 'lib/puma/plugin/telemetry/config.rb', line 80 def socket_parser @socket_parser end |
#socket_telemetry ⇒ Object
Whenever to publish socket telemetry.
- default: false
66 67 68 |
# File 'lib/puma/plugin/telemetry/config.rb', line 66 def socket_telemetry @socket_telemetry end |
#targets ⇒ Object
List of targets which are meant to publish telemetry.
Target should implement #call method accepting
a single argument - so it can be even a simple proc.
- default: []
57 58 59 |
# File 'lib/puma/plugin/telemetry/config.rb', line 57 def targets @targets end |
Instance Method Details
#add_target(name_or_target, **args) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/puma/plugin/telemetry/config.rb', line 112 def add_target(name_or_target, **args) return @targets.push(name_or_target) unless name_or_target.is_a?(Symbol) target = TARGETS.fetch(name_or_target) do raise Telemetry::Error, "Unknown Target: #{name_or_target.inspect}, #{args.inspect}" end @targets.push(target.new(**args)) end |
#enabled? ⇒ Boolean
92 93 94 |
# File 'lib/puma/plugin/telemetry/config.rb', line 92 def enabled? !!@enabled end |
#socket_telemetry! ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/puma/plugin/telemetry/config.rb', line 96 def socket_telemetry! # These structs are platform specific, and not available on macOS, # for example. If they're undefined, then we cannot capture socket # telemetry. We'll warn in that case. if defined?(Socket::SOL_TCP) && defined?(Socket::TCP_INFO) @socket_telemetry = true else @socket_telemetry = false warn("Cannot capture socket telemetry on this platform (#{RUBY_PLATFORM}); socket_telemetry is disabled.") end end |
#socket_telemetry? ⇒ Boolean
108 109 110 |
# File 'lib/puma/plugin/telemetry/config.rb', line 108 def socket_telemetry? @socket_telemetry end |