Class: Couchbase::Metrics::LoggingMeter
- Defined in:
- lib/couchbase/metrics/logging_meter.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/metrics/logging_meter.rb
Instance Method Summary collapse
- #close ⇒ Object
- #create_report ⇒ Object
-
#initialize(emit_interval: nil) ⇒ LoggingMeter
constructor
milliseconds.
- #value_recorder(name, tags) ⇒ Object
Constructor Details
#initialize(emit_interval: nil) ⇒ LoggingMeter
milliseconds
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/couchbase/metrics/logging_meter.rb', line 33 def initialize(emit_interval: nil) super() @emit_interval = emit_interval || DEFAULT_EMIT_INTERVAL @value_recorders = { Observability::ATTR_VALUE_SERVICE_KV => Concurrent::Map.new, Observability::ATTR_VALUE_SERVICE_QUERY => Concurrent::Map.new, Observability::ATTR_VALUE_SERVICE_VIEWS => Concurrent::Map.new, Observability::ATTR_VALUE_SERVICE_SEARCH => Concurrent::Map.new, Observability::ATTR_VALUE_SERVICE_ANALYTICS => Concurrent::Map.new, Observability::ATTR_VALUE_SERVICE_MANAGEMENT => Concurrent::Map.new, } # TODO(DC): Find better solution for logging @logger = Couchbase.logger || Logger.new($stdout, Utils::StdlibLoggerAdapter.map_spdlog_level(Couchbase.log_level)) @task = Concurrent::TimerTask.new(execution_interval: @emit_interval / 1_000.0) do report = create_report return if report.empty? @logger.info("Metrics: #{report.to_json}") rescue StandardError => e @logger.debug("Failed to log metrics: #{e.}") end end |
Instance Method Details
#close ⇒ Object
100 101 102 103 104 105 |
# File 'lib/couchbase/metrics/logging_meter.rb', line 100 def close @task.shutdown @value_recorders.each_value do |operation_map| operation_map.each_value(&:close) end end |
#create_report ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/couchbase/metrics/logging_meter.rb', line 76 def create_report operations = {} @value_recorders.each do |service, recorders| recorders.each_key do |operation_name| recorder = recorders[operation_name] operation_report = recorder.report_and_reset if operation_report operations[service] ||= {} operations[service][operation_name] = operation_report end end end if operations.empty? {} else { meta: { emit_interval_ms: @emit_interval, }, operations: operations, } end end |
#value_recorder(name, tags) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/couchbase/metrics/logging_meter.rb', line 57 def value_recorder(name, ) return NoopMeter::VALUE_RECORDER_INSTANCE unless name == Observability::METER_NAME_OPERATION_DURATION operation_name = [Observability::ATTR_OPERATION_NAME] service = [Observability::ATTR_SERVICE] return NoopMeter::VALUE_RECORDER_INSTANCE if operation_name.nil? || service.nil? @value_recorders[service].put_if_absent( operation_name, LoggingValueRecorder.new( operation_name: operation_name, service: service, ), ) @value_recorders[service][operation_name] end |