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, options = {}) ⇒ 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] @socket = get_socket([:agent_host], [:agent_port]) end |
Instance Method Details
#write(metric_value, metric_name = @metric_name, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/wavefront/writer.rb', line 42 def write(metric_value, metric_name = @metric_name, = {}) [:host_name] ||= @host_name [:point_tags] ||= [:timestamp] ||= Time.now if metric_name.empty? raise Wavefront::Exception::EmptyMetricName end if [:point_tags].empty? append = "host=#{options[:host_name]}" else = [:point_tags].map { |k, v| "#{k}=\"#{v}\"" }.join(' ') append = "host=#{options[:host_name]} #{tags}" end @socket.puts [metric_name, metric_value, [:timestamp].to_i, append].join(' ') end |