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

Version Path
vmpooler-3.6.0 lib/vmpooler/metrics/statsd.rb
vmpooler-3.5.1 lib/vmpooler/metrics/statsd.rb
vmpooler-3.5.0 lib/vmpooler/metrics/statsd.rb
vmpooler-3.4.0 lib/vmpooler/metrics/statsd.rb
vmpooler-3.3.0 lib/vmpooler/metrics/statsd.rb
vmpooler-3.2.0 lib/vmpooler/metrics/statsd.rb
vmpooler-3.1.0 lib/vmpooler/metrics/statsd.rb
vmpooler-3.0.0 lib/vmpooler/metrics/statsd.rb
vmpooler-2.5.0 lib/vmpooler/metrics/statsd.rb
vmpooler-2.4.0 lib/vmpooler/metrics/statsd.rb
vmpooler-2.3.0 lib/vmpooler/metrics/statsd.rb
vmpooler-2.2.0 lib/vmpooler/metrics/statsd.rb
vmpooler-2.1.0 lib/vmpooler/metrics/statsd.rb
vmpooler-2.0.0 lib/vmpooler/metrics/statsd.rb
vmpooler-1.3.0 lib/vmpooler/metrics/statsd.rb
vmpooler-1.2.0 lib/vmpooler/metrics/statsd.rb
vmpooler-1.1.2 lib/vmpooler/metrics/statsd.rb
vmpooler-1.1.1 lib/vmpooler/metrics/statsd.rb
vmpooler-1.1.0 lib/vmpooler/metrics/statsd.rb
vmpooler-1.0.0 lib/vmpooler/metrics/statsd.rb