Class: Sensu::Extension::StatsD

Inherits:
Check
  • Object
show all
Defined in:
lib/sensu/extensions/statsd.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Method Summary collapse

Instance Method Details

#definitionObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sensu/extensions/statsd.rb', line 46

def definition
  {
    type: 'metric',
    name: name,
    interval: options[:send_interval],
    standalone: true,
    output_format: 'graphite_plaintext',
    handler: options[:handler],
    truncate_output: options[:truncate_output]
  }
end

#descriptionObject



18
19
20
# File 'lib/sensu/extensions/statsd.rb', line 18

def description
  'a statsd implementation'
end

#nameObject



14
15
16
# File 'lib/sensu/extensions/statsd.rb', line 14

def name
  'statsd'
end

#optionsObject

rubocop:disable Metrics/MethodLength



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sensu/extensions/statsd.rb', line 22

def options # rubocop:disable Metrics/MethodLength
  return @options if @options
  @options = {
    bind: '127.0.0.1',
    port: 8125,
    flush_interval: 10,
    send_interval: 30,
    percentile: 90,
    delete_gauges: false,
    delete_counters: false,
    delete_timers: false,
    reset_gauges: false,
    reset_counters: true,
    reset_timers: true,
    add_client_prefix: true,
    path_prefix: 'statsd',
    add_path_prefix: true,
    handler: 'graphite',
    truncate_output: true
  }
  @options.merge!(@settings[:statsd]) if @settings[:statsd].is_a?(Hash)
  @options
end

#post_initObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sensu/extensions/statsd.rb', line 58

def post_init
  @flush_timers = []
  @data = EM::Queue.new
  @gauges = Hash.new { |h, k| h[k] = 0 }
  @counters = Hash.new { |h, k| h[k] = 0 }
  @timers = Hash.new { |h, k| h[k] = [] }
  @metrics = []
  setup_flush_timers
  setup_parser
  setup_statsd_socket
end

#run {|output, 0| ... } ⇒ Object

Yields:

  • (output, 0)


70
71
72
73
74
75
76
77
78
# File 'lib/sensu/extensions/statsd.rb', line 70

def run
  output = ''
  if @metrics
    output << @metrics.join("\n") + "\n" unless @metrics.empty?
    @logger.info('statsd collected metrics', count: @metrics.count)
    @metrics = []
  end
  yield output, 0
end