Module: Fluent::GcloudPubSub::Metrics

Defined in:
lib/fluent/plugin/gcloud_pubsub/metrics.rb

Overview

Utilities for interacting with Prometheus metrics

Class Method Summary collapse

Class Method Details

.measure_durationObject

Time the elapsed execution of the provided block, return the duration as the first element followed by the result of the block.



15
16
17
18
19
20
21
# File 'lib/fluent/plugin/gcloud_pubsub/metrics.rb', line 15

def self.measure_duration
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  result = yield
  finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)

  [finish - start, *result]
end

.register_or_existing(metric_name) ⇒ Object



7
8
9
10
11
# File 'lib/fluent/plugin/gcloud_pubsub/metrics.rb', line 7

def self.register_or_existing(metric_name)
  return ::Prometheus::Client.registry.get(metric_name) if ::Prometheus::Client.registry.exist?(metric_name)

  yield
end