Class: TelegrafAgent
- Inherits:
-
Object
- Object
- TelegrafAgent
- Defined in:
- lib/telegraf_agent.rb
Constant Summary collapse
- ConnectionError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(url:, logger: nil) ⇒ TelegrafAgent
constructor
Initialize an agent.
-
#write(series, tags:, values:) ⇒ Object
Send data to telegraf.
Constructor Details
#initialize(url:, logger: nil) ⇒ TelegrafAgent
Initialize an agent
16 17 18 19 |
# File 'lib/telegraf_agent.rb', line 16 def initialize(url:, logger: nil) @uri = URI.parse(url) @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/telegraf_agent.rb', line 9 def logger @logger end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
9 10 11 |
# File 'lib/telegraf_agent.rb', line 9 def uri @uri end |
Instance Method Details
#write(series, tags:, values:) ⇒ Object
Send data to telegraf
27 28 29 30 31 32 33 |
# File 'lib/telegraf_agent.rb', line 27 def write(series, tags:, values:) data = ::InfluxDB::PointValue.new(series: series, tags: , values: values).dump logger&.debug("Sending data to #{uri}: #{data}") connection.write(data) rescue disconnect! end |