Module: InstStatsd
- Defined in:
- lib/inst_statsd/statsd.rb,
lib/inst_statsd.rb,
lib/inst_statsd/event.rb,
lib/inst_statsd/counter.rb,
lib/inst_statsd/version.rb,
lib/inst_statsd/block_stat.rb,
lib/inst_statsd/null_logger.rb,
lib/inst_statsd/sql_tracker.rb,
lib/inst_statsd/request_stat.rb,
lib/inst_statsd/block_tracking.rb,
lib/inst_statsd/request_logger.rb,
lib/inst_statsd/default_tracking.rb,
lib/inst_statsd/request_tracking.rb
Overview
Proxy class to communicate messages to statsd Available statsd messages are described in:
https://github.com/etsy/statsd/blob/master/README.md
https://github.com/reinh/statsd/blob/master/lib/statsd.rb
So for instance:
ms = Benchmark.ms { ..code.. }
InstStatsd::Statsd.timing("my_stat", ms)
Configured in config/statsd.yml, see config/statsd.yml.example At least a host needs to be defined for the environment, all other config is optional
If a namespace is defined in statsd.yml, it'll be prepended to the stat name.
The hostname of the server will be appended to the stat name, unless append_hostname: false is specified in the config.
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"
(assuming the default statsd/graphite configuration)
If dog_tags is set in statsd.yml, it'll use the tags param and will use Data Dog instead of Statsd
If statsd isn't configured and enabled, then calls to InstStatsd::Statsd.* will do nothing and return nil
Defined Under Namespace
Modules: Event, Statsd Classes: BlockStat, BlockTracking, ConfigurationError, Counter, DefaultTracking, NullLogger, RequestLogger, RequestStat, RequestTracking, SqlTracker
Constant Summary collapse
- VALID_SETTINGS =
%i[host port namespace append_hostname mask negative_mask batch_size batch_byte_size dog_tags].freeze
- VERSION =
"2.4.0"
Class Method Summary collapse
- .convert_bool(hash, key) ⇒ Object
- .env_settings(env = ENV) ⇒ Object
- .settings ⇒ Object
- .settings=(value) ⇒ Object
- .validate_settings(value) ⇒ Object
Class Method Details
.convert_bool(hash, key) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/inst_statsd.rb', line 67 def convert_bool(hash, key) value = hash[key] return if value.nil? unless ['true', 'True', 'false', 'False', true, false].include?(value) = "#{key} must be a boolean, or the string representation of a boolean, got: #{value}" raise InstStatsd::ConfigurationError, end hash[key] = ['true', 'True', true].include?(value) end |
.env_settings(env = ENV) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/inst_statsd.rb', line 47 def env_settings(env = ENV) = JSON.parse(env['INST_DOG_TAGS']).to_h if env['INST_DOG_TAGS'] config = { host: env.fetch('INST_STATSD_HOST', nil), port: env.fetch('INST_STATSD_PORT', nil), namespace: env.fetch('INST_STATSD_NAMESPACE', nil), append_hostname: env.fetch('INST_STATSD_APPEND_HOSTNAME', nil), dog_tags: } config.delete_if { |_k, v| v.nil? } convert_bool(config, :append_hostname) if config[:host] config elsif config[:dog_tags] config else {} end end |
.settings ⇒ Object
24 25 26 |
# File 'lib/inst_statsd.rb', line 24 def settings @settings ||= env_settings end |
.settings=(value) ⇒ Object
28 29 30 |
# File 'lib/inst_statsd.rb', line 28 def settings=(value) @settings = validate_settings(value) end |
.validate_settings(value) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/inst_statsd.rb', line 32 def validate_settings(value) return nil if value.nil? validated = {} value.each do |k, v| unless VALID_SETTINGS.include?(k.to_sym) raise InstStatsd::ConfigurationError, "Invalid key: #{k}" end v = Regexp.new(v) if %i[mask negative_mask].include?(k.to_sym) && v.is_a?(String) validated[k.to_sym] = v end env_settings.merge(validated) end |