Sha256: 624afbba89a36d3837ecd00cef494d0d163c4c739753f139ba0bb9acc6040969

Contents?: true

Size: 1.29 KB

Versions: 22

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require 'rubygems' unless defined?(Gem)

module Vmpooler
  class Metrics
    class Graphite < Metrics
      attr_reader :server, :port, :prefix

      # rubocop:disable Lint/MissingSuper
      def initialize(logger, params = {})
        raise ArgumentError, "Graphite server is required. Config: #{params.inspect}" if params['server'].nil? || params['server'].empty?

        @server = params['server']
        @port   = params['port'] || 2003
        @prefix = params['prefix'] || 'vmpooler'
        @logger = logger
      end
      # rubocop:enable Lint/MissingSuper

      def increment(label)
        log label, 1
      end

      def gauge(label, value)
        log label, value
      end

      def timing(label, duration)
        log label, duration
      end

      def log(path, value)
        Thread.new do
          socket = TCPSocket.new(server, port)
          begin
            socket.puts "#{prefix}.#{path} #{value} #{Time.now.to_i}"
          ensure
            socket.close
          end
        end
      rescue Errno::EADDRNOTAVAIL => e
        warn "Could not assign address to graphite server #{server}: #{e}"
      rescue StandardError => e
        @logger.log('s', "[!] Failure logging #{path} to graphite 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/graphite.rb
vmpooler-3.5.1 lib/vmpooler/metrics/graphite.rb
vmpooler-3.5.0 lib/vmpooler/metrics/graphite.rb
vmpooler-3.4.0 lib/vmpooler/metrics/graphite.rb
vmpooler-3.3.0 lib/vmpooler/metrics/graphite.rb
vmpooler-3.2.0 lib/vmpooler/metrics/graphite.rb
vmpooler-3.1.0 lib/vmpooler/metrics/graphite.rb
vmpooler-3.0.0 lib/vmpooler/metrics/graphite.rb
vmpooler-2.5.0 lib/vmpooler/metrics/graphite.rb
vmpooler-2.4.0 lib/vmpooler/metrics/graphite.rb
vmpooler-2.3.0 lib/vmpooler/metrics/graphite.rb
vmpooler-2.2.0 lib/vmpooler/metrics/graphite.rb
vmpooler-2.1.0 lib/vmpooler/metrics/graphite.rb
vmpooler-2.0.0 lib/vmpooler/metrics/graphite.rb
vmpooler-1.3.0 lib/vmpooler/metrics/graphite.rb
vmpooler-1.2.0 lib/vmpooler/metrics/graphite.rb
vmpooler-1.1.2 lib/vmpooler/metrics/graphite.rb
vmpooler-1.1.1 lib/vmpooler/metrics/graphite.rb
vmpooler-1.1.0 lib/vmpooler/metrics/graphite.rb
vmpooler-1.0.0 lib/vmpooler/metrics/graphite.rb