Class: Datadog::Statsd::Telemetry
- Inherits:
-
Object
- Object
- Datadog::Statsd::Telemetry
- Defined in:
- lib/datadog/statsd/telemetry.rb
Instance Attribute Summary collapse
-
#bytes_dropped ⇒ Object
readonly
Returns the value of attribute bytes_dropped.
-
#bytes_sent ⇒ Object
readonly
Returns the value of attribute bytes_sent.
-
#estimate_max_size ⇒ Object
readonly
Returns the value of attribute estimate_max_size.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
-
#packets_dropped ⇒ Object
readonly
Returns the value of attribute packets_dropped.
-
#packets_sent ⇒ Object
readonly
Returns the value of attribute packets_sent.
-
#service_checks ⇒ Object
readonly
Returns the value of attribute service_checks.
Instance Method Summary collapse
- #dropped(bytes: 0, packets: 0) ⇒ Object
- #flush ⇒ Object
- #flush? ⇒ Boolean
-
#initialize(disabled, flush_interval, global_tags: [], transport_type: :udp) ⇒ Telemetry
constructor
A new instance of Telemetry.
- #reset ⇒ Object
- #sent(metrics: 0, events: 0, service_checks: 0, bytes: 0, packets: 0) ⇒ Object
Constructor Details
#initialize(disabled, flush_interval, global_tags: [], transport_type: :udp) ⇒ Telemetry
Returns a new instance of Telemetry.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/datadog/statsd/telemetry.rb', line 16 def initialize(disabled, flush_interval, global_tags: [], transport_type: :udp) @disabled = disabled @flush_interval = flush_interval @global_tags = @transport_type = transport_type reset # TODO: Karim: I don't know why but telemetry tags are serialized # before global tags so by refactoring this, I am keeping the same behavior @serialized_tags = Serialization::TagSerializer.new( client: 'ruby', client_version: VERSION, client_transport: transport_type, ).format() # estimate_max_size is an estimation or the maximum size of the # telemetry payload. Since we don't want our packet to go over # 'max_buffer_bytes', we have to adjust with the size of the telemetry # (and any tags used). The telemetry payload size will change depending # on the actual value of metrics: metrics received, packet dropped, # etc. This is why we add a 63bytes margin: 9 bytes for each of the 7 # telemetry metrics. @estimate_max_size = disabled ? 0 : flush.length + 9 * 7 end |
Instance Attribute Details
#bytes_dropped ⇒ Object (readonly)
Returns the value of attribute bytes_dropped.
11 12 13 |
# File 'lib/datadog/statsd/telemetry.rb', line 11 def bytes_dropped @bytes_dropped end |
#bytes_sent ⇒ Object (readonly)
Returns the value of attribute bytes_sent.
10 11 12 |
# File 'lib/datadog/statsd/telemetry.rb', line 10 def bytes_sent @bytes_sent end |
#estimate_max_size ⇒ Object (readonly)
Returns the value of attribute estimate_max_size.
14 15 16 |
# File 'lib/datadog/statsd/telemetry.rb', line 14 def estimate_max_size @estimate_max_size end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
8 9 10 |
# File 'lib/datadog/statsd/telemetry.rb', line 8 def events @events end |
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
7 8 9 |
# File 'lib/datadog/statsd/telemetry.rb', line 7 def metrics @metrics end |
#packets_dropped ⇒ Object (readonly)
Returns the value of attribute packets_dropped.
13 14 15 |
# File 'lib/datadog/statsd/telemetry.rb', line 13 def packets_dropped @packets_dropped end |
#packets_sent ⇒ Object (readonly)
Returns the value of attribute packets_sent.
12 13 14 |
# File 'lib/datadog/statsd/telemetry.rb', line 12 def packets_sent @packets_sent end |
#service_checks ⇒ Object (readonly)
Returns the value of attribute service_checks.
9 10 11 |
# File 'lib/datadog/statsd/telemetry.rb', line 9 def service_checks @service_checks end |
Instance Method Details
#dropped(bytes: 0, packets: 0) ⇒ Object
61 62 63 64 |
# File 'lib/datadog/statsd/telemetry.rb', line 61 def dropped(bytes: 0, packets: 0) @bytes_dropped += bytes @packets_dropped += packets end |
#flush ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/datadog/statsd/telemetry.rb', line 70 def flush return '' if @disabled # using shorthand syntax to reduce the garbage collection %Q( datadog.dogstatsd.client.metrics:#{@metrics}|#{COUNTER_TYPE}|##{} datadog.dogstatsd.client.events:#{@events}|#{COUNTER_TYPE}|##{} datadog.dogstatsd.client.service_checks:#{@service_checks}|#{COUNTER_TYPE}|##{} datadog.dogstatsd.client.bytes_sent:#{@bytes_sent}|#{COUNTER_TYPE}|##{} datadog.dogstatsd.client.bytes_dropped:#{@bytes_dropped}|#{COUNTER_TYPE}|##{} datadog.dogstatsd.client.packets_sent:#{@packets_sent}|#{COUNTER_TYPE}|##{} datadog.dogstatsd.client.packets_dropped:#{@packets_dropped}|#{COUNTER_TYPE}|##{}) end |
#flush? ⇒ Boolean
66 67 68 |
# File 'lib/datadog/statsd/telemetry.rb', line 66 def flush? @next_flush_time < now_in_s end |
#reset ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/datadog/statsd/telemetry.rb', line 41 def reset @metrics = 0 @events = 0 @service_checks = 0 @bytes_sent = 0 @bytes_dropped = 0 @packets_sent = 0 @packets_dropped = 0 @next_flush_time = now_in_s + @flush_interval end |
#sent(metrics: 0, events: 0, service_checks: 0, bytes: 0, packets: 0) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/datadog/statsd/telemetry.rb', line 52 def sent(metrics: 0, events: 0, service_checks: 0, bytes: 0, packets: 0) @metrics += metrics @events += events @service_checks += service_checks @bytes_sent += bytes @packets_sent += packets end |