Sha256: 97abcc18f3ba4aaf4a3b396346389e7672c471633aec1e11f79c4710e758a090

Contents?: true

Size: 1.67 KB

Versions: 63

Compression:

Stored size: 1.67 KB

Contents

# Copyright 2017 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module Monitoring
  # Base class for the monitoring registry.
  class BaseMonitoringRegistry
    def counter(_name, _desc)
      _undefined
    end
  end

  # Prometheus implementation of the monitoring registry, that uses the default
  # registry in the official Prometheus client library.
  class PrometheusMonitoringRegistry < BaseMonitoringRegistry
    def self.name
      'prometheus'
    end

    def initialize
      require 'prometheus/client'
      @registry = Prometheus::Client.registry
    end

    # Exception-driven behavior to avoid synchronization errors.
    def counter(name, desc)
      return @registry.counter(name, desc)
    rescue Prometheus::Client::Registry::AlreadyRegisteredError
      return @registry.get(name)
    end
  end

  # Factory that is used to create a monitoring registry based on
  # the monitoring solution name.
  class MonitoringRegistryFactory
    @known_registry_types = {
      PrometheusMonitoringRegistry.name =>
        PrometheusMonitoringRegistry
    }

    def self.create(name)
      (@known_registry_types[name] || BaseMonitoringRegistry).new
    end
  end
end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
fluent-plugin-google-cloud-0.7.15 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.14 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.13 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.12 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.11 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.10 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.9 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.8 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.7 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.6 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.5 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.5.pre.multiworkers lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.4 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.3 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.2 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.0 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.0.pre.4 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.7.0.pre.3 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.6.25.1 lib/fluent/plugin/monitoring.rb
fluent-plugin-google-cloud-0.6.25.pre.4 lib/fluent/plugin/monitoring.rb