Class: RailsLokiExporter::LokiHttpClient
- Inherits:
-
Object
- Object
- RailsLokiExporter::LokiHttpClient
- Defined in:
- lib/rails_loki_exporter/loki_http_client.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ LokiHttpClient
constructor
A new instance of LokiHttpClient.
- #send_log(log_message) ⇒ Object
Constructor Details
#initialize(config) ⇒ LokiHttpClient
Returns a new instance of LokiHttpClient.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rails_loki_exporter/loki_http_client.rb', line 11 def initialize(config) uri = URI.parse(config['base_url']) @base_url = uri @log_file_path = config['log_file_path'] @logs_type = config['logs_type'] @intercept_logs = config['intercept_logs'] @job_name = config['job_name'] || "#{$0}_#{Process.pid}" @host_name = config['host_name'] || Socket.gethostname @user_name = config['user_name'] @password = config['password'] @auth_enabled = config['auth_enabled'] @log_buffer = [] @last_interaction_time = nil @interaction_interval = (config['interaction_interval'] || '5').to_i # in seconds, adjust as needed @max_buffer_size = (config['max_buffer_size'] || '100').to_i # set the maximum number of logs to buffer http = Net::HTTP.new(@base_url.to_s, @base_url.port) http.use_ssl = @base_url.scheme == 'https' http.read_timeout = 30 http.open_timeout = 30 http end |
Instance Method Details
#send_log(log_message) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rails_loki_exporter/loki_http_client.rb', line 34 def send_log() = Time.now.to_f * 1_000_000_000 @log_buffer << [.to_i.to_s, .chomp] if @log_buffer.size >= @max_buffer_size || can_send_log? send_buffered_logs @last_interaction_time = Time.now else # @logger.info('Log buffered. Waiting for more logs or interaction interval.') end end |