Class: Wavefront::Writer
- Inherits:
-
Object
- Object
- Wavefront::Writer
- Defined in:
- lib/wavefront/writer.rb
Constant Summary collapse
- DEFAULT_AGENT_HOST =
'localhost'- DEFAULT_PORT =
2878- DEFAULT_HOSTNAME =
%x{hostname -f}.chomp
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Writer
constructor
A new instance of Writer.
- #write(metric_value, metric_name = @metric_name, host = @host_name, point_tags = @point_tags, timestamp = Time.now) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Writer
Returns a new instance of Writer.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wavefront/writer.rb', line 28 def initialize( = {}) [:agent_host] ||= DEFAULT_AGENT_HOST [:agent_port] ||= DEFAULT_PORT [:host_name] ||= DEFAULT_HOSTNAME [:metric_name] ||= '' [:point_tags] ||= {} @host_name = [:host_name] @metric_name = [:metric_name] @point_tags = [:point_tags] @socket = get_socket([:agent_host], [:agent_port]) end |
Instance Method Details
#write(metric_value, metric_name = @metric_name, host = @host_name, point_tags = @point_tags, timestamp = Time.now) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/wavefront/writer.rb', line 42 def write(metric_value, metric_name=@metric_name, host=@host_name, =@point_tags, =Time.now) raise Wavefront::Exception::EmptyMetricName if metric_name.empty? = .empty? ? '' : .map{|k,v| "#{k}=\"#{v}\""}.join(' ') append = .empty? ? "host=#{host}" : "host=#{host} #{}" @socket.puts "#{metric_name} #{metric_value} #{.to_i} #{append}" end |