Class: Wavefront::Writer
- Inherits:
-
Object
- Object
- Wavefront::Writer
- Includes:
- Constants
- Defined in:
- lib/wavefront/writer.rb
Constant Summary collapse
- DEFAULT_AGENT_HOST =
'localhost'
- DEFAULT_PORT =
2878
- DEFAULT_HOSTNAME =
%x{hostname -f}.chomp
Constants included from Constants
Constants::ALERT_FORMATS, Constants::DASH_FORMATS, Constants::DEFAULT_ALERT_FORMAT, Constants::DEFAULT_DASH_FORMAT, Constants::DEFAULT_FORMAT, Constants::DEFAULT_HOST, Constants::DEFAULT_INFILE_FORMAT, Constants::DEFAULT_OBSOLETE_METRICS, Constants::DEFAULT_OPTS, Constants::DEFAULT_PERIOD_SECONDS, Constants::DEFAULT_PREFIX_LENGTH, Constants::DEFAULT_PROXY, Constants::DEFAULT_PROXY_PORT, Constants::DEFAULT_SOURCE_FORMAT, Constants::DEFAULT_STRICT, Constants::EVENT_LEVELS, Constants::EVENT_STATE_DIR, Constants::FORMATS, Constants::GRANULARITIES, Constants::SOURCE_FORMATS
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.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wavefront/writer.rb', line 30 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, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/wavefront/writer.rb', line 44 def write(metric_value, metric_name = @metric_name, = {}) [:host_name] ||= @host_name [:point_tags] ||= @point_tags [:timestamp] ||= Time.now if metric_name.empty? raise Wavefront::Exception::EmptyMetricName end if [:point_tags].empty? append = "host=#{[:host_name]}" else = [:point_tags].map { |k, v| "#{k}=\"#{v}\"" }.join(' ') append = "host=#{[:host_name]} #{}" end str = [metric_name, metric_value, [:timestamp].to_i, append].join(' ') if [:noop] puts "metric to send: #{str}" else @socket.puts(str) end end |