Class: Telegraf::Agent
- Inherits:
-
Object
- Object
- Telegraf::Agent
- Defined in:
- lib/telegraf/agent.rb
Constant Summary collapse
- DEFAULT_CONNECTION =
'udp://localhost:8094'
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(uri = nil, logger: nil, tags: {}) ⇒ Agent
constructor
A new instance of Agent.
- #write(*args, **kwargs) ⇒ Object
- #write!(data, series: nil, tags: nil, values: nil) ⇒ Object
Constructor Details
#initialize(uri = nil, logger: nil, tags: {}) ⇒ Agent
Returns a new instance of Agent.
9 10 11 12 13 |
# File 'lib/telegraf/agent.rb', line 9 def initialize(uri = nil, logger: nil, tags: {}) @uri = URI.parse(uri || DEFAULT_CONNECTION) @tags = @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/telegraf/agent.rb', line 7 def logger @logger end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
7 8 9 |
# File 'lib/telegraf/agent.rb', line 7 def @tags end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/telegraf/agent.rb', line 7 def uri @uri end |
Instance Method Details
#write(*args, **kwargs) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/telegraf/agent.rb', line 15 def write(*args, **kwargs) write!(*args, **kwargs) rescue StandardError => e logger&.error('telegraf') do e.to_s + e.backtrace.join("\n") end end |
#write!(data, series: nil, tags: nil, values: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/telegraf/agent.rb', line 23 def write!(data, series: nil, tags: nil, values: nil) = .merge(@tags) unless @tags.empty? if values data = [{series: series || data.to_s, tags: , values: values}] end socket = connect @uri socket.write dump data ensure socket&.close end |