Class: Datadog::Statsd::Telemetry

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/statsd/telemetry.rb

Constant Summary collapse

MAX_TELEMETRY_MESSAGE_SIZE_WT_TAGS =

Rough estimation of maximum telemetry message size without tags

50

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flush_interval, global_tags: [], transport_type: :udp) ⇒ Telemetry

bytes



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/datadog/statsd/telemetry.rb', line 22

def initialize(flush_interval, global_tags: [], transport_type: :udp)
  @flush_interval = flush_interval
  @global_tags = 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(global_tags)
end

Instance Attribute Details

#bytes_droppedObject (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_dropped_queueObject (readonly)

Returns the value of attribute bytes_dropped_queue.



12
13
14
# File 'lib/datadog/statsd/telemetry.rb', line 12

def bytes_dropped_queue
  @bytes_dropped_queue
end

#bytes_dropped_writerObject (readonly)

Returns the value of attribute bytes_dropped_writer.



13
14
15
# File 'lib/datadog/statsd/telemetry.rb', line 13

def bytes_dropped_writer
  @bytes_dropped_writer
end

#bytes_sentObject (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

#eventsObject (readonly)

Returns the value of attribute events.



8
9
10
# File 'lib/datadog/statsd/telemetry.rb', line 8

def events
  @events
end

#metricsObject (readonly)

Returns the value of attribute metrics.



7
8
9
# File 'lib/datadog/statsd/telemetry.rb', line 7

def metrics
  @metrics
end

#packets_droppedObject (readonly)

Returns the value of attribute packets_dropped.



15
16
17
# File 'lib/datadog/statsd/telemetry.rb', line 15

def packets_dropped
  @packets_dropped
end

#packets_dropped_queueObject (readonly)

Returns the value of attribute packets_dropped_queue.



16
17
18
# File 'lib/datadog/statsd/telemetry.rb', line 16

def packets_dropped_queue
  @packets_dropped_queue
end

#packets_dropped_writerObject (readonly)

Returns the value of attribute packets_dropped_writer.



17
18
19
# File 'lib/datadog/statsd/telemetry.rb', line 17

def packets_dropped_writer
  @packets_dropped_writer
end

#packets_sentObject (readonly)

Returns the value of attribute packets_sent.



14
15
16
# File 'lib/datadog/statsd/telemetry.rb', line 14

def packets_sent
  @packets_sent
end

#service_checksObject (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_queue(bytes: 0, packets: 0) ⇒ Object



65
66
67
68
69
70
# File 'lib/datadog/statsd/telemetry.rb', line 65

def dropped_queue(bytes: 0, packets: 0)
  @bytes_dropped += bytes
  @bytes_dropped_queue += bytes
  @packets_dropped += packets
  @packets_dropped_queue += packets
end

#dropped_writer(bytes: 0, packets: 0) ⇒ Object



72
73
74
75
76
77
# File 'lib/datadog/statsd/telemetry.rb', line 72

def dropped_writer(bytes: 0, packets: 0)
  @bytes_dropped += bytes
  @bytes_dropped_writer += bytes
  @packets_dropped += packets
  @packets_dropped_writer += packets
end

#flushObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/datadog/statsd/telemetry.rb', line 83

def flush
  [
    sprintf(pattern, 'metrics', @metrics),
    sprintf(pattern, 'events', @events),
    sprintf(pattern, 'service_checks', @service_checks),
    sprintf(pattern, 'bytes_sent', @bytes_sent),
    sprintf(pattern, 'bytes_dropped', @bytes_dropped),
    sprintf(pattern, 'bytes_dropped_queue', @bytes_dropped_queue),
    sprintf(pattern, 'bytes_dropped_writer', @bytes_dropped_writer),
    sprintf(pattern, 'packets_sent', @packets_sent),
    sprintf(pattern, 'packets_dropped', @packets_dropped),
    sprintf(pattern, 'packets_dropped_queue', @packets_dropped_queue),
    sprintf(pattern, 'packets_dropped_writer', @packets_dropped_writer),
  ]
end

#resetObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/datadog/statsd/telemetry.rb', line 41

def reset
  @metrics = 0
  @events = 0
  @service_checks = 0
  @bytes_sent = 0
  @bytes_dropped = 0
  @bytes_dropped_queue = 0
  @bytes_dropped_writer = 0
  @packets_sent = 0
  @packets_dropped = 0
  @packets_dropped_queue = 0
  @packets_dropped_writer = 0
  @next_flush_time = now_in_s + @flush_interval
end

#sent(metrics: 0, events: 0, service_checks: 0, bytes: 0, packets: 0) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/datadog/statsd/telemetry.rb', line 56

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

#should_flush?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/datadog/statsd/telemetry.rb', line 79

def should_flush?
  @next_flush_time < now_in_s
end

#would_fit_in?(max_buffer_payload_size) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/datadog/statsd/telemetry.rb', line 37

def would_fit_in?(max_buffer_payload_size)
  MAX_TELEMETRY_MESSAGE_SIZE_WT_TAGS + serialized_tags.size < max_buffer_payload_size
end