Sha256: 15b362853573bed022239829988e2b217a2cbc6a881d10ef31152f3aa2055ce4
Contents?: true
Size: 1.36 KB
Versions: 22
Compression:
Stored size: 1.36 KB
Contents
# frozen_string_literal: true require 'rubygems' unless defined?(Gem) require 'statsd' module Vmpooler class Metrics class Statsd < Metrics attr_reader :server, :port, :prefix # rubocop:disable Lint/MissingSuper def initialize(logger, params = {}) raise ArgumentError, "Statsd server is required. Config: #{params.inspect}" if params['server'].nil? || params['server'].empty? host = params['server'] @port = params['port'] || 8125 @prefix = params['prefix'] || 'vmpooler' @server = ::Statsd.new(host, @port) @logger = logger end # rubocop:enable Lint/MissingSuper def increment(label) server.increment("#{prefix}.#{label}") rescue StandardError => e @logger.log('s', "[!] Failure incrementing #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{e}") end def gauge(label, value) server.gauge("#{prefix}.#{label}", value) rescue StandardError => e @logger.log('s', "[!] Failure updating gauge #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{e}") end def timing(label, duration) server.timing("#{prefix}.#{label}", duration) rescue StandardError => e @logger.log('s', "[!] Failure updating timing #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{e}") end end end end
Version data entries
22 entries across 22 versions & 1 rubygems