Sha256: cbab84325890e4224cf18fb273ac7f9f983b34550af7c64ed1fbe3940d9b9d5b

Contents?: true

Size: 880 Bytes

Versions: 1

Compression:

Stored size: 880 Bytes

Contents


class Hash
  def hash_map
    self.inject({}) do |newhash, (k,v)|
      newhash[k] = yield(k, v)
      newhash
    end
  end
end

module Mongodb
  module Graphite
    module Agent
      class GraphiteWriter
        def initialize(host, port, verbose)
          @graphite = ::Graphite.new({:host => host, :port => port})
          @verbose = verbose
        end

        def write(metric_hash)
          puts "Sending data to graphite" if @verbose
          ap metric_hash if @verbose
          @metric_hash_with_hostname = metric_hash.map { |k, v| { "#{Socket.gethostname}.#{k}" => v } }.reduce Hash.new(), :merge
          @graphite.send_metrics @metric_hash_with_hostname
          #ap metric_hash.hash_map { |k, v| { "#{Socket.gethostname}.#{k}" => v }}

          #@graphite.send_metrics({"#{Socket.gethostname}.#{metric}" => value})
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongodb-graphite-agent-0.0.4 lib/mongodb/graphite/agent/graphite_writer.rb