Class: PMetric::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pmetric/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pmetric/configuration.rb', line 19

def initialize
  @host = ENV.fetch('INFLUXDB_HOST', 'influxdb.500friends.com'.freeze)
  @port = ENV.fetch('INFLUXDB_PORT', 8086)
  @username = ENV.fetch('INFLUXDB_USERNAME', nil)
  @password = ENV.fetch('INFLUXDB_PASSWORD', nil)
  @database = ENV.fetch('INFLUXDB_DATABASE', 'prism'.freeze)
  @time_precision = 'ns'.freeze
  @retry = 10
  @use_ssl = false

  # Logging is off by default
  @logger = false

  # PMetric must be intentionally enabled
  @collector = :noop

  # Async options
  @async = {
    # InfluxDB async writer uses a custom ruby Queue to keep track of
    # pending points, and this specifies the max number of items the queue
    # will allow. Anything greater will just drop off.
    max_queue_size: 10_000,

    # Number of post points to write at once. For a full queue with a max
    # size of 10_000, and a max post points of 1_000, it will take 10 batch
    # calls to post all the data.
    max_post_points: 1_000,

    # Number of Threads emptying the async queue. This will be per-process,
    # as the collector is shared globally.
    num_worker_threads: 2,

    # Time each thread waits to check for new points. The InfluxDB client
    # will actually sleep at `rand(sleep_interval)`, fyi.
    sleep_interval: 5
  }

  # Default to no udp_port. Setting udp_port && udp_host enables UDP on.
  @udp_host = ENV.fetch('INFLUXDB_UDP_HOST', @host)
  @udp_port = ENV.fetch('INFLUXDB_UDP_PORT', nil)

  # Default Event Tags
  @default_tags = nil
end

Instance Attribute Details

#asyncObject

Returns the value of attribute async.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def async
  @async
end

#collectorObject

Returns the value of attribute collector.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def collector
  @collector
end

#databaseObject

Returns the value of attribute database.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def database
  @database
end

#default_tagsObject

Returns the value of attribute default_tags.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def default_tags
  @default_tags
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def logger
  @logger
end

#passwordObject

Returns the value of attribute password.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def password
  @password
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def port
  @port
end

#retryObject

Returns the value of attribute retry.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def retry
  @retry
end

#time_precisionObject

Returns the value of attribute time_precision.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def time_precision
  @time_precision
end

#udp_hostObject

Returns the value of attribute udp_host.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def udp_host
  @udp_host
end

#udp_portObject

Returns the value of attribute udp_port.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def udp_port
  @udp_port
end

#use_sslObject

Returns the value of attribute use_ssl.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def use_ssl
  @use_ssl
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/pmetric/configuration.rb', line 3

def username
  @username
end

Instance Method Details

#client_optsHash

Builds client options for the PMetric::Collector::Influx collector.

Returns:

  • (Hash)

    Influx client options.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/pmetric/configuration.rb', line 68

def client_opts
  opts = {
    host: @host,
    port: @port,
    database: @database,
    time_precision: @time_precision,
    retry: @retry
  }

  opts[:username] = @username if @username
  opts[:password] = @password if @password

  if @use_ssl
    opts[:use_ssl] = true
    opts[:verify_ssl] = true
  end

  if @udp_host && @udp_port
    opts[:udp] = { host: @udp_host, port: @udp_port }
    opts[:async] = false
  else
    opts[:async] = @async || false
  end

  opts
end