Sha256: bf6bf28fa94406e3eeca85eafe54c7f00000cd08fcb24a201116109232112460
Contents?: true
Size: 1.46 KB
Versions: 190
Compression:
Stored size: 1.46 KB
Contents
# encoding: UTF-8 require 'thread' require 'prometheus/client/counter' require 'prometheus/client/summary' require 'prometheus/client/gauge' require 'prometheus/client/histogram' module Prometheus module Client # Registry class Registry class AlreadyRegisteredError < StandardError; end def initialize @metrics = {} @mutex = Mutex.new end def register(metric) name = metric.name @mutex.synchronize do if exist?(name.to_sym) raise AlreadyRegisteredError, "#{name} has already been registered" else @metrics[name.to_sym] = metric end end metric end def counter(name, docstring, base_labels = {}) register(Counter.new(name, docstring, base_labels)) end def summary(name, docstring, base_labels = {}) register(Summary.new(name, docstring, base_labels)) end def gauge(name, docstring, base_labels = {}, multiprocess_mode = :all) register(Gauge.new(name, docstring, base_labels, multiprocess_mode)) end def histogram(name, docstring, base_labels = {}, buckets = Histogram::DEFAULT_BUCKETS) register(Histogram.new(name, docstring, base_labels, buckets)) end def exist?(name) @metrics.key?(name) end def get(name) @metrics[name.to_sym] end def metrics @metrics.values end end end end
Version data entries
190 entries across 190 versions & 2 rubygems