Class: TopologicalInventory::Providers::Common::Metrics
- Inherits:
-
Object
- Object
- TopologicalInventory::Providers::Common::Metrics
- Defined in:
- lib/topological_inventory/providers/common/metrics.rb
Constant Summary collapse
- ERROR_COUNTER_MESSAGE =
"total number of errors".freeze
- ERROR_TYPES =
%i[general].freeze
- OPERATIONS =
%w[].freeze
Instance Method Summary collapse
-
#initialize(port = 9394) ⇒ Metrics
constructor
A new instance of Metrics.
- #record_error(type = :general) ⇒ Object
-
#record_gauge(metric, opt, value: nil, labels: {}) ⇒ Object
Common method for gauge.
- #record_operation(name, labels = {}) ⇒ Object
- #record_operation_time(name, labels = {}, &block) ⇒ Object
- #record_refresh_timing(labels = {}, &block) ⇒ Object
-
#record_time(metric, labels = {}) ⇒ Object
Common method for histogram.
- #stop_server ⇒ Object
Methods included from TopologicalInventory::Providers::Common::Mixins::Statuses
Constructor Details
#initialize(port = 9394) ⇒ Metrics
Returns a new instance of Metrics.
18 19 20 21 22 23 24 25 |
# File 'lib/topological_inventory/providers/common/metrics.rb', line 18 def initialize(port = 9394) return if port == 0 configure_server(port) configure_metrics init_counters end |
Instance Method Details
#record_error(type = :general) ⇒ Object
31 32 33 |
# File 'lib/topological_inventory/providers/common/metrics.rb', line 31 def record_error(type = :general) @error_counter&.observe(1, :type => type.to_s) end |
#record_gauge(metric, opt, value: nil, labels: {}) ⇒ Object
Common method for gauge
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/topological_inventory/providers/common/metrics.rb', line 48 def record_gauge(metric, opt, value: nil, labels: {}) case opt when :set then metric&.observe(value.to_i, labels) when :add then metric&.increment(labels) when :remove then metric&.decrement(labels) end end |
#record_operation(name, labels = {}) ⇒ Object
39 40 41 |
# File 'lib/topological_inventory/providers/common/metrics.rb', line 39 def record_operation(name, labels = {}) @status_counter&.observe(1, (labels || {}).merge(:name => name)) end |
#record_operation_time(name, labels = {}, &block) ⇒ Object
43 44 45 |
# File 'lib/topological_inventory/providers/common/metrics.rb', line 43 def record_operation_time(name, labels = {}, &block) record_time(@duration_seconds, (labels || {}).merge(:name => name), &block) end |
#record_refresh_timing(labels = {}, &block) ⇒ Object
35 36 37 |
# File 'lib/topological_inventory/providers/common/metrics.rb', line 35 def record_refresh_timing(labels = {}, &block) record_time(@refresh_timer, labels, &block) end |
#record_time(metric, labels = {}) ⇒ Object
Common method for histogram
60 61 62 63 64 65 |
# File 'lib/topological_inventory/providers/common/metrics.rb', line 60 def record_time(metric, labels = {}) result = nil time = Benchmark.realtime { result = yield } metric&.observe(time, labels) result end |
#stop_server ⇒ Object
27 28 29 |
# File 'lib/topological_inventory/providers/common/metrics.rb', line 27 def stop_server @server&.stop end |