2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/monus/backends/influxdb.rb', line 2
def prepare
@host = Monus.options.dig(:influxdb_options, :host) || 'localhost'
@measurement = Monus.options.dig(:influxdb_options, :measurement)
unless @measurement
raise Monus::ConfigurationError, 'when using InfluxDB backend you should provide `influxdb_options/measurement` configuration with measurement (table) name'
end
@mode = Monus.options.dig(:influxdb_options, :mode)
case @mode
when :udp
@udp_port = Monus.options.dig(:influxdb_options, :udp_port)
unless @udp_port
raise Monus::ConfigurationError, 'when using UDP mode you should provide `influxdb_options/udp_port` configuration with corresponding port number'
end
when :http
@http_port = Monus.options.dig(:influxdb_options, :http_port)
unless @http_port
raise Monus::ConfigurationError, 'when using HTTP mode you should provide `influxdb_options/http_port` configuration with corresponding port number'
end
@database = Monus.options.dig(:influxdb_options, :database)
unless @database
raise Monus::ConfigurationError, 'when using HTTP mode you should provide `influxdb_options/database` configuration with database name'
end
@http_connection = Monus.engine.make_http_connection @host, @http_port
@uri = "/write?db=#{@database}"
else
raise Monus::ConfigurationError, 'when using InfluxDB backend you should provide `influxdb_options/mode` configuration with `:udp` or `:http` value'
end
@global_tags = Monus.options.dig(:influxdb_options, :global_tags)&.map { |key, value| ",#{key}=#{value}" }&.join
end
|