inst_statsd 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52813306c6a3409e9abe7f114c58a471afe310eadd722bf555d0bd058144ce06
4
- data.tar.gz: a899e4395f5cf3340040e500ad7ccdf4ac3f7c0fbcccbb52bb738f35e9f353a1
3
+ metadata.gz: d30f765062a97af9d2fb24f537f909d280ff5c4e3f73e88f26a295672beceb70
4
+ data.tar.gz: ec16ef1cf597f17562545f61919d554eea88cca7c7c41d490018ce554fa052ea
5
5
  SHA512:
6
- metadata.gz: e81e6b93a69826837fd5d952db4e9d784d3ae9230e72e9a62c6abb21dba6deb248a9baf89690e4d4bad4b0710bfd0dd72d93e5d8463f60c8265dbfbc42ea152c
7
- data.tar.gz: 718e935a24b5e899c1bd67ea5669bcb0fada8e78a71c6e2b93b43f57b3744354fe732ebe702f2e06fb28ad8a325dbc3a319d99e58916aef593445a5d172607fb
6
+ metadata.gz: 7abdd65611b4a20abdbbf84041365269fd78dec587cdaa82a34445ed79f48b884bca0fe36fba5771723b9130354e0eb6e77110686d5418997a2d86fd2036b7ad
7
+ data.tar.gz: 861b9d44c819dcae0d776c0e180b5b26000023bc8ce2d73a32009ed7533fa6840e00faad63c56be6991004ccc84b3ff9735adbbaa2931e790a7155831e81409b
@@ -2,13 +2,9 @@
2
2
 
3
3
  module InstStatsd
4
4
  class BlockStat
5
+ attr_accessor :stats, :common_key, :short_stat, :tags
5
6
 
6
- attr_accessor :stats
7
- attr_accessor :common_key
8
- attr_accessor :short_stat
9
- attr_accessor :tags
10
-
11
- def initialize(common_key, statsd=InstStatsd::Statsd, tags: {}, short_stat: nil)
7
+ def initialize(common_key, statsd = InstStatsd::Statsd, tags: {}, short_stat: nil)
12
8
  self.common_key = common_key
13
9
  @tags = tags
14
10
  @short_stat = short_stat
@@ -27,17 +23,21 @@ module InstStatsd
27
23
 
28
24
  def exclusive_stats
29
25
  return nil unless @exclusives
30
- stats.map { |key, value| [key, value - (@exclusives[key] || 0.0)] }.to_h
26
+
27
+ stats.to_h { |key, value| [key, value - (@exclusives[key] || 0.0)] }
31
28
  end
32
29
 
33
30
  def report
34
- if common_key
35
- stats.each do |(key, value)|
36
- @statsd.timing("#{common_key}.#{key}", value, tags: @tags, short_stat: "#{@short_stat}.#{key}")
37
- end
38
- exclusive_stats&.each do |(key, value)|
39
- @statsd.timing("#{common_key}.exclusive.#{key}", value, tags: @tags, short_stat: "#{@short_stat}.exclusive.#{key}")
40
- end
31
+ return unless common_key
32
+
33
+ stats.each do |(key, value)|
34
+ @statsd.timing("#{common_key}.#{key}", value, tags: @tags, short_stat: "#{@short_stat}.#{key}")
35
+ end
36
+ exclusive_stats&.each do |(key, value)|
37
+ @statsd.timing("#{common_key}.exclusive.#{key}",
38
+ value,
39
+ tags: @tags,
40
+ short_stat: "#{@short_stat}.exclusive.#{key}")
41
41
  end
42
42
  end
43
43
  end
@@ -1,21 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'benchmark'
3
+ require "benchmark"
4
4
 
5
5
  module InstStatsd
6
6
  class BlockTracking
7
7
  class << self
8
8
  attr_accessor :logger
9
9
 
10
- [:mask, :negative_mask].each do |method|
10
+ %i[mask negative_mask].each do |method|
11
11
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
12
- def #{method}
13
- InstStatsd.settings[:#{method}]
14
- end
15
-
16
- def #{method}=(value)
17
- InstStatsd.settings[:#{method}] = value
18
- end
12
+ def #{method} # def mask
13
+ InstStatsd.settings[:#{method}] # InstStatsd.settings[:mask]
14
+ end # end
15
+ #
16
+ def #{method}=(value) # def mask=(value)
17
+ InstStatsd.settings[:#{method}] = value # InstStatsd.settings[:mask] = value
18
+ end # end
19
19
  RUBY
20
20
  end
21
21
 
@@ -38,12 +38,12 @@ module InstStatsd
38
38
  # to be consistent with ActionPack, measure in milliseconds
39
39
  elapsed *= 1000
40
40
 
41
- block_stat.stats = cookies.map { |(name, cookie)| [name, Counter.counters[name].finalize_count(cookie)] }.to_h
42
- block_stat.stats['total'] = elapsed
41
+ block_stat.stats = cookies.to_h { |(name, cookie)| [name, Counter.counters[name].finalize_count(cookie)] }
42
+ block_stat.stats["total"] = elapsed
43
43
  # we need to make sure to report exclusive timings, even if nobody called us re-entrantly
44
44
  block_stat.subtract_exclusives({}) if category
45
45
  block_stat.report
46
- logger.log(block_stat, "STATSD #{key}") if logger
46
+ logger&.log(block_stat, "STATSD #{key}")
47
47
  # -1 is ourselves; we want to subtract from the block above us
48
48
  stack(category)[-2].subtract_exclusives(block_stat.stats) if category && stack(category)[-2]
49
49
 
@@ -59,6 +59,5 @@ module InstStatsd
59
59
  Thread.current[:stats_block_stack][category] ||= []
60
60
  end
61
61
  end
62
-
63
62
  end
64
63
  end
@@ -12,10 +12,9 @@ module InstStatsd
12
12
  end
13
13
  end
14
14
 
15
- attr_reader :key
16
- attr_reader :blocked_names
15
+ attr_reader :key, :blocked_names
17
16
 
18
- def initialize(key, blocked_names=[], tags: {}, short_stat: nil)
17
+ def initialize(key, blocked_names = [], tags: {}, short_stat: nil)
19
18
  @blocked_names = blocked_names
20
19
  @key = key
21
20
  @tls_key = "statsd.#{key}"
@@ -41,6 +40,5 @@ module InstStatsd
41
40
  def accepted_name?(name)
42
41
  !blocked_names.include?(name)
43
42
  end
44
-
45
43
  end
46
44
  end
@@ -4,41 +4,44 @@ require "active_support"
4
4
 
5
5
  module InstStatsd
6
6
  class DefaultTracking
7
- def self.track_sql
8
- return if @sql_tracker
9
- @sql_tracker = InstStatsd::SqlTracker.new(blocked_names: ['SCHEMA'])
10
- ActiveSupport::Notifications.subscribe(/sql\.active_record/) {|*args| update_sql_count(*args)}
11
- end
7
+ class << self
8
+ def track_sql
9
+ return if @sql_tracker
12
10
 
13
- def self.track_active_record
14
- return if @ar_counter
15
- require 'aroi'
11
+ @sql_tracker = InstStatsd::SqlTracker.new(blocked_names: ["SCHEMA"])
12
+ ActiveSupport::Notifications.subscribe(/sql\.active_record/) { |*args| update_sql_count(*args) }
13
+ end
16
14
 
17
- ::Aroi::Instrumentation.instrument_creation!
18
- @ar_counter = InstStatsd::Counter.new('active_record')
19
- ActiveSupport::Notifications.subscribe(/instance\.active_record/) {|*args| update_active_record_count(*args)}
20
- end
15
+ def track_active_record
16
+ return if @ar_counter
21
17
 
22
- def self.track_cache
23
- return if @cache_read_counter
18
+ require "aroi"
24
19
 
25
- @cache_read_counter = InstStatsd::Counter.new('cache.read')
26
- ActiveSupport::Notifications.subscribe(/cache_read\.active_support/) {|*args| update_cache_read_count(*args)}
27
- end
20
+ ::Aroi::Instrumentation.instrument_creation!
21
+ @ar_counter = InstStatsd::Counter.new("active_record")
22
+ ActiveSupport::Notifications.subscribe(/instance\.active_record/) { |*args| update_active_record_count(*args) }
23
+ end
28
24
 
29
- private
25
+ def track_cache
26
+ return if @cache_read_counter
30
27
 
31
- def self.update_sql_count(_name, _start, _finish, _id, payload)
32
- @sql_tracker.track payload.fetch(:name), payload.fetch(:sql)
33
- end
28
+ @cache_read_counter = InstStatsd::Counter.new("cache.read")
29
+ ActiveSupport::Notifications.subscribe(/cache_read\.active_support/) { |*args| update_cache_read_count(*args) }
30
+ end
34
31
 
35
- def self.update_active_record_count(_name, _start, _finish, _id, payload)
36
- @ar_counter.track payload.fetch(:name, '')
37
- end
32
+ private
38
33
 
39
- def self.update_cache_read_count(_name, _start, _finish, _id, _payload)
40
- @cache_read_counter.track "read"
41
- end
34
+ def update_sql_count(_name, _start, _finish, _id, payload)
35
+ @sql_tracker.track payload.fetch(:name), payload.fetch(:sql)
36
+ end
42
37
 
38
+ def update_active_record_count(_name, _start, _finish, _id, payload)
39
+ @ar_counter.track payload.fetch(:name, "")
40
+ end
41
+
42
+ def update_cache_read_count(_name, _start, _finish, _id, _payload)
43
+ @cache_read_counter.track "read"
44
+ end
45
+ end
43
46
  end
44
47
  end
@@ -44,7 +44,7 @@ module InstStatsd
44
44
  instance.event(
45
45
  title,
46
46
  text,
47
- {
47
+ **{
48
48
  alert_type: alert_type,
49
49
  priority: priority,
50
50
  date_happened: date_happened,
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
3
+ require "logger"
4
4
 
5
5
  module InstStatsd
6
6
  class NullLogger < Logger
7
- def initialize(*args)
7
+ def initialize(*) # rubocop:disable Lint/MissingSuper
8
8
  end
9
9
 
10
- def add(*args, &block)
11
- end
10
+ def add(*); end
12
11
  end
13
12
  end
@@ -2,26 +2,24 @@
2
2
 
3
3
  module InstStatsd
4
4
  class RequestLogger
5
-
6
5
  def initialize(logger)
7
6
  @logger = logger || InstStatsd::NullLogger.new
8
7
  end
9
8
 
10
- def log(request_stat, header=nil)
9
+ def log(request_stat, header = nil)
11
10
  @logger.info(build_log_message(request_stat, header))
12
11
  end
13
12
 
14
- def build_log_message(request_stat, header=nil)
13
+ def build_log_message(request_stat, header = nil)
15
14
  header ||= "STATSD"
16
15
  message = "[#{header}]"
17
16
  request_stat.stats.each do |(name, value)|
18
- message += " (#{name.to_s.gsub('.', '_')}: #{"%.2f" % value})"
17
+ message += " (#{name.to_s.tr(".", "_")}: #{format("%.2f", value)})"
19
18
  end
20
19
  request_stat.exclusive_stats&.each do |(name, value)|
21
- message += " (exclusive_#{name.to_s.gsub('.', '_')}: #{"%.2f" % value})"
20
+ message += " (exclusive_#{name.to_s.tr(".", "_")}: #{format("%.2f", value)})"
22
21
  end
23
22
  message
24
23
  end
25
-
26
24
  end
27
25
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module InstStatsd
4
4
  class RequestStat < BlockStat
5
- def initialize(name, start, finish, id, payload, statsd=InstStatsd::Statsd)
5
+ def initialize(name, start, finish, id, payload, statsd = InstStatsd::Statsd)
6
6
  super(nil, statsd)
7
7
  @name = name
8
8
  @start = start
@@ -15,21 +15,22 @@ module InstStatsd
15
15
  def common_key
16
16
  common_key = super
17
17
  return common_key if common_key
18
+
18
19
  if @statsd.data_dog?
19
20
  self.common_key = "request"
20
21
  self.short_stat = "request"
21
- self.tags[:controller] = controller if controller
22
- self.tags[:action] = action if action
23
- self.tags[:status] = status if status
24
- else
25
- self.common_key = "request.#{controller}.#{action}" if controller && action
22
+ tags[:controller] = controller if controller
23
+ tags[:action] = action if action
24
+ tags[:status] = status if status
25
+ elsif controller && action
26
+ self.common_key = "request.#{controller}.#{action}"
26
27
  end
27
28
  end
28
29
 
29
30
  def report
30
- stats['total'] = total
31
- stats['view'] = view_runtime if view_runtime
32
- stats['db'] = db_runtime if db_runtime
31
+ stats["total"] = total
32
+ stats["view"] = view_runtime if view_runtime
33
+ stats["db"] = db_runtime if db_runtime
33
34
  super
34
35
  end
35
36
 
@@ -42,30 +43,29 @@ module InstStatsd
42
43
  end
43
44
 
44
45
  def controller
45
- @payload.fetch(:params, {})['controller']
46
+ @payload.fetch(:params, {})["controller"]
46
47
  end
47
48
 
48
49
  def action
49
- @payload.fetch(:params, {})['action']
50
+ @payload.fetch(:params, {})["action"]
50
51
  end
51
52
 
52
53
  def status
53
54
  status = @payload.fetch(:status, 0)
54
55
  # Only return status group to reduce the number of indexed custom metrics (and cost) of datadog
55
- return '1XX' if status >= 100 and status < 200
56
- return '2XX' if status >= 200 and status < 300
57
- return '3XX' if status >= 300 and status < 400
58
- return '4XX' if status >= 400 and status < 500
59
- return '5XX' if status >= 500 and status < 600
56
+ return "1XX" if (status >= 100) && (status < 200)
57
+ return "2XX" if (status >= 200) && (status < 300)
58
+ return "3XX" if (status >= 300) && (status < 400)
59
+ return "4XX" if (status >= 400) && (status < 500)
60
+ return "5XX" if (status >= 500) && (status < 600)
61
+
60
62
  nil
61
63
  end
62
64
 
63
65
  def total
64
- if (!@finish || !@start)
65
- return 0
66
- end
66
+ return 0 if !@finish || !@start
67
+
67
68
  (@finish - @start) * 1000
68
69
  end
69
-
70
70
  end
71
71
  end
@@ -2,28 +2,29 @@
2
2
 
3
3
  module InstStatsd
4
4
  class RequestTracking
5
+ class << self
6
+ def enable(logger: nil)
7
+ @logger = RequestLogger.new(logger)
8
+ track_timing
9
+ end
5
10
 
6
- def self.enable(logger: nil)
7
- @logger = RequestLogger.new(logger)
8
- track_timing
9
- end
10
-
11
- private
11
+ private
12
12
 
13
- def self.track_timing
14
- ActiveSupport::Notifications.subscribe(/start_processing\.action_controller/, &method(:start_processing))
15
- ActiveSupport::Notifications.subscribe(/process_action\.action_controller/, &method(:finalize_processing))
16
- end
13
+ def track_timing
14
+ ActiveSupport::Notifications.subscribe(/start_processing\.action_controller/, &method(:start_processing))
15
+ ActiveSupport::Notifications.subscribe(/process_action\.action_controller/, &method(:finalize_processing))
16
+ end
17
17
 
18
- def self.start_processing(*_args)
19
- @cookies = Counter.counters.map { |(name, counter)| [name, counter.start] }
20
- end
18
+ def start_processing(*_args)
19
+ @cookies = Counter.counters.map { |(name, counter)| [name, counter.start] }
20
+ end
21
21
 
22
- def self.finalize_processing *args
23
- request_stat = InstStatsd::RequestStat.new(*args)
24
- request_stat.stats = @cookies.map { |(name, cookie)| [name, Counter.counters[name].finalize_count(cookie)] }.to_h
25
- request_stat.report
26
- @logger.log(request_stat)
22
+ def finalize_processing *args
23
+ request_stat = InstStatsd::RequestStat.new(*args)
24
+ request_stat.stats = @cookies.to_h { |(name, cookie)| [name, Counter.counters[name].finalize_count(cookie)] }
25
+ request_stat.report
26
+ @logger.log(request_stat)
27
+ end
27
28
  end
28
29
  end
29
30
  end
@@ -2,27 +2,26 @@
2
2
 
3
3
  module InstStatsd
4
4
  class SqlTracker
5
-
6
5
  attr_reader :blocked_names, :read_counts, :write_counts, :cache_counts
7
6
 
8
- def initialize(opts=nil)
7
+ def initialize(opts = nil)
9
8
  opts ||= {}
10
9
  @blocked_names = opts.fetch(:blocked_names, [])
11
- @read_counts = opts.fetch(:read_counter, InstStatsd::Counter.new('sql.read'))
12
- @write_counts = opts.fetch(:write_counter, InstStatsd::Counter.new('sql.write'))
13
- @cache_counts = opts.fetch(:cache_counter, InstStatsd::Counter.new('sql.cache'))
10
+ @read_counts = opts.fetch(:read_counter, InstStatsd::Counter.new("sql.read"))
11
+ @write_counts = opts.fetch(:write_counter, InstStatsd::Counter.new("sql.write"))
12
+ @cache_counts = opts.fetch(:cache_counter, InstStatsd::Counter.new("sql.cache"))
14
13
  end
15
14
 
16
15
  def start
17
16
  [read_counts, write_counts, cache_counts].map(&:start)
18
17
  end
19
18
 
20
- def track name, sql
19
+ def track(name, sql)
21
20
  return unless sql && accepted_name?(name)
22
21
 
23
- if name.match(/CACHE/)
22
+ if name.include?("CACHE")
24
23
  cache_counts.track name
25
- elsif truncate(sql).match(/SELECT/) || name.match(/LOAD/)
24
+ elsif truncate(sql).include?("SELECT") || name.include?("LOAD")
26
25
  read_counts.track(sql)
27
26
  else
28
27
  write_counts.track(sql)
@@ -43,10 +42,9 @@ module InstStatsd
43
42
  !!(name && !blocked_names.include?(name))
44
43
  end
45
44
 
46
- def truncate(sql, length=15)
47
- sql ||= ''
45
+ def truncate(sql, length = 15)
46
+ sql ||= ""
48
47
  sql.strip[0..length]
49
48
  end
50
-
51
49
  end
52
50
  end
@@ -10,29 +10,33 @@
10
10
  # InstStatsd::Statsd.timing("my_stat", ms)
11
11
  #
12
12
  # Configured in config/statsd.yml, see config/statsd.yml.example
13
- # At least a host needs to be defined for the environment, all other config is optional
13
+ # At least a host needs to be defined for the environment, all other config is
14
+ # optional
14
15
  #
15
16
  # If a namespace is defined in statsd.yml, it'll be prepended to the stat name.
16
- # The hostname of the server will be appended to the stat name, unless `append_hostname: false` is specified in the config.
17
- # So if the namespace is "canvas" and the hostname is "app01", the final stat name of "my_stat" would be "stats.canvas.my_stat.app01"
18
- # (assuming the default statsd/graphite configuration)
17
+ # The hostname of the server will be appended to the stat name, unless
18
+ # `append_hostname: false` is specified in the config.
19
+ # So if the namespace is "canvas" and the hostname is "app01", the final stat
20
+ # name of "my_stat" would be "stats.canvas.my_stat.app01" (assuming the default
21
+ # statsd/graphite configuration)
19
22
  #
20
23
  # If dog_tags is set in statsd.yml, it'll use the tags param and will use
21
24
  # Data Dog instead of Statsd
22
25
  #
23
- # If statsd isn't configured and enabled, then calls to InstStatsd::Statsd.* will do nothing and return nil
26
+ # If statsd isn't configured and enabled, then calls to InstStatsd::Statsd.*
27
+ # will do nothing and return nil
24
28
 
25
29
  module InstStatsd
26
30
  module Statsd
27
31
  extend InstStatsd::Event
28
32
 
29
33
  # replace "." in key names with another character to avoid creating spurious sub-folders in graphite
30
- def self.escape(str, replacement = '_')
31
- str.respond_to?(:gsub) ? str.gsub('.', replacement) : str
34
+ def self.escape(str, replacement = "_")
35
+ str.respond_to?(:gsub) ? str.gsub(".", replacement) : str
32
36
  end
33
37
 
34
38
  def self.hostname
35
- @hostname ||= Socket.gethostname.split('.').first
39
+ @hostname ||= Socket.gethostname.split(".").first
36
40
  end
37
41
 
38
42
  def self.dog_tags
@@ -41,50 +45,49 @@ module InstStatsd
41
45
 
42
46
  %w[increment decrement count gauge timing].each do |method|
43
47
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
44
- def self.#{method}(stat, *args, tags: {}, short_stat: nil)
45
- if self.instance
46
- if Array === stat
47
- stat.each do |st|
48
- self.#{method}(st, *args, tags: tags, short_stat: nil)
49
- end
50
- return
51
- end
52
-
53
- if self.append_hostname?
54
- stat_name = "\#{stat}.\#{hostname}"
55
- else
56
- stat_name = stat.to_s
57
- end
58
-
59
- if data_dog?
60
- tags ||= {}
61
- tags.merge!(dog_tags) if tags.is_a? Hash
62
- tags = convert_tags(tags)
63
- tags << 'host:' unless self.append_hostname?
64
- short_stat ||= stat_name
65
- opts = { tags: tags }
66
- opts[:sample_rate] = args.pop if args.length == 2
67
- args << opts
68
- self.instance.#{method}(short_stat, *args)
69
- else
70
- self.instance.#{method}(stat_name, *args)
71
- end
72
- else
73
- nil
74
- end
75
- end
48
+ def self.#{method}(stat, *args, tags: {}, short_stat: nil) # def self.increment(stat, *args, tags: {}, short_stat: nil)
49
+ if self.instance # if self.instance
50
+ if Array === stat # if Array === stat
51
+ stat.each do |st| # stat.each do |st|
52
+ self.#{method}(st, *args, tags: tags, short_stat: nil) # self.increment(st, *args, tags: tags, short_stat: nil)
53
+ end # end
54
+ return # return
55
+ end # end
56
+ #
57
+ if self.append_hostname? # if self.append_hostname?
58
+ stat_name = "\#{stat}.\#{hostname}" # stat_name = "\#{stat}.\#{hostname}"
59
+ else # else
60
+ stat_name = stat.to_s # stat_name = stat.to_s
61
+ end # end
62
+ #
63
+ if data_dog? # if data_dog?
64
+ tags = tags ? tags.dup : {} # tags ||= {}
65
+ tags.merge!(dog_tags) if tags.is_a? Hash # tags.merge!(dog_tags) if tags.is_a? Hash
66
+ tags = convert_tags(tags) # tags = convert_tags(tags)
67
+ tags << 'host:' unless self.append_hostname? # tags << 'host:' unless self.append_hostname?
68
+ short_stat ||= stat_name # short_stat ||= stat_name
69
+ opts = { tags: tags } # opts = { tags: tags }
70
+ opts[:sample_rate] = args.pop if args.length == 2 # opts[:sample_rate] = args.pop if args.length == 2
71
+ args << opts # args << opts
72
+ self.instance.#{method}(short_stat, *args) # self.instance.increment(short_stat, *args)
73
+ else # else
74
+ self.instance.#{method}(stat_name, *args) # self.instance.increment(stat_name, *args)
75
+ end # end
76
+ else # else
77
+ nil # nil
78
+ end # end
79
+ end # end
76
80
  RUBY
77
81
  end
78
82
 
79
83
  def self.convert_tags(tags)
80
84
  new_tags = []
81
- if tags.is_a? Hash
82
- tags.each do |tag, v|
83
- new_tags << "#{tag}:#{v}"
84
- end
85
- else
86
- return tags
85
+ return tags unless tags.is_a? Hash
86
+
87
+ tags.each do |tag, v|
88
+ new_tags << "#{tag}:#{v}"
87
89
  end
90
+
88
91
  new_tags
89
92
  end
90
93
 
@@ -97,6 +100,7 @@ module InstStatsd
97
100
 
98
101
  def self.batch
99
102
  return yield unless (old_instance = instance)
103
+
100
104
  old_instance.batch do |batch|
101
105
  Thread.current[:inst_statsd] = batch
102
106
  yield
@@ -113,19 +117,24 @@ module InstStatsd
113
117
  statsd_settings = InstStatsd.settings
114
118
  if statsd_settings.key?(:dog_tags)
115
119
  @data_dog = true
116
- host = statsd_settings[:host] || 'localhost'
120
+ host = statsd_settings[:host] || "localhost"
117
121
  port = statsd_settings[:port] || 8125
118
- require 'datadog/statsd'
119
- @statsd = ::Datadog::Statsd.new(host, port, namespace: statsd_settings[:namespace])
120
- self.dog_tags.replace(statsd_settings[:dog_tags] || {})
121
- @append_hostname = !statsd_settings.key?(:append_hostname) || !!statsd_settings[:append_hostname]
122
+ socket_path = statsd_settings[:socket_path]
123
+ require "datadog/statsd"
124
+ @statsd = if socket_path
125
+ Datadog::Statsd.new(socket_path: socket_path, namespace: statsd_settings[:namespace])
126
+ else
127
+ Datadog::Statsd.new(host, port, namespace: statsd_settings[:namespace])
128
+ end
129
+ dog_tags.replace(statsd_settings[:dog_tags] || {})
130
+ @append_hostname = statsd_settings[:append_hostname]
122
131
  elsif statsd_settings && statsd_settings[:host]
123
132
  @statsd = ::Statsd.new(statsd_settings[:host])
124
133
  @statsd.port = statsd_settings[:port] if statsd_settings[:port]
125
134
  @statsd.namespace = statsd_settings[:namespace] if statsd_settings[:namespace]
126
135
  @statsd.batch_size = statsd_settings[:batch_size] if statsd_settings.key?(:batch_size)
127
136
  @statsd.batch_byte_size = statsd_settings[:batch_byte_size] if statsd_settings.key?(:batch_byte_size)
128
- @append_hostname = !statsd_settings.key?(:append_hostname) || !!statsd_settings[:append_hostname]
137
+ @append_hostname = statsd_settings[:append_hostname]
129
138
  else
130
139
  @statsd = nil
131
140
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InstStatsd
4
- VERSION = "3.0.2"
4
+ VERSION = "3.0.3"
5
5
  end