Module: Gruf::Prometheus::Configuration
- Included in:
- Gruf::Prometheus
- Defined in:
- lib/gruf/prometheus/configuration.rb
Overview
General configuration for gruf prometheus integration
Constant Summary collapse
- VALID_CONFIG_KEYS =
{ process_label: 'grpc', process_name: 'grpc', collection_frequency: 30, type_collectors: [], collectors: [], client_measure_latency: false, server_measure_latency: false }.freeze
Class Method Summary collapse
-
.extended(base) ⇒ Object
Whenever this is extended into a class, setup the defaults.
Instance Method Summary collapse
-
#configure {|_self| ... } ⇒ Gruf::Prometheus::Configuration
Yield self for ruby-style initialization.
-
#environment ⇒ String
Automatically determine environment.
-
#options ⇒ Hash
Return the current configuration options as a Hash.
-
#reset ⇒ Object
Set the default configuration onto the extended class.
Class Method Details
.extended(base) ⇒ Object
Whenever this is extended into a class, setup the defaults
39 40 41 |
# File 'lib/gruf/prometheus/configuration.rb', line 39 def self.extended(base) base.reset end |
Instance Method Details
#configure {|_self| ... } ⇒ Gruf::Prometheus::Configuration
Yield self for ruby-style initialization
49 50 51 52 53 54 |
# File 'lib/gruf/prometheus/configuration.rb', line 49 def configure reset unless @configured yield self @configured = true self end |
#environment ⇒ String
Automatically determine environment
88 89 90 91 92 93 94 |
# File 'lib/gruf/prometheus/configuration.rb', line 88 def environment if defined?(Rails) Rails.env.to_s else (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development').to_s end end |
#options ⇒ Hash
Return the current configuration options as a Hash
61 62 63 64 65 66 67 |
# File 'lib/gruf/prometheus/configuration.rb', line 61 def opts = {} VALID_CONFIG_KEYS.each_key do |k| opts.merge!(k => send(k)) end opts end |
#reset ⇒ Object
Set the default configuration onto the extended class
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gruf/prometheus/configuration.rb', line 72 def reset VALID_CONFIG_KEYS.each do |k, v| send("#{k}=".to_sym, v) end self.process_label = ENV.fetch('PROMETHEUS_PROCESS_LABEL', 'grpc').to_s self.process_name = ENV.fetch('PROMETHEUS_PROCESS_NAME', 'grpc').to_s self.collection_frequency = ENV.fetch('PROMETHEUS_COLLECTION_FREQUENCY', 30).to_i self.server_measure_latency = ENV.fetch('PROMETHEUS_SERVER_MEASURE_LATENCY', 0).to_i.positive? self.client_measure_latency = ENV.fetch('PROMETHEUS_CLIENT_MEASURE_LATENCY', 0).to_i.positive? end |