lib/splash/logs.rb in prometheus-splash-0.5.3 vs lib/splash/logs.rb in prometheus-splash-0.6.0

- old
+ new

@@ -1,17 +1,23 @@ # coding: utf-8 + +# base Splash module module Splash + + # Logs namespace module Logs + + # Log scanner and notifier class LogScanner include Splash::Constants include Splash::Config - # LogScanner Constructor - # return [LogScanner] + # LogScanner Constructor : initialize prometheus metrics + # return [Splash::Logs::LogScanner] def initialize - @logs_target = get_config.logs + @logs_target = Marshal.load(Marshal.dump(get_config.logs)) @config = get_config @registry = Prometheus::Client::Registry::new @metric_count = Prometheus::Client::Gauge.new(:logerrors, docstring: 'SPLASH metric log error', labels: [:log ]) @metric_missing = Prometheus::Client::Gauge.new(:logmissing, docstring: 'SPLASH metric log missing', labels: [:log ]) @metric_lines = Prometheus::Client::Gauge.new(:loglines, docstring: 'SPLASH metric log lines numbers', labels: [:log ]) @@ -20,10 +26,11 @@ @registry.register(@metric_lines) end # start log analyse for log target in config + # @return [Hash] Exiter case :quiet_exit def analyse @logs_target.each do |record| record[:count]=0 if record[:count].nil? record[:status] = :clean if record[:status].nil? if File.exist?(record[:log]) then @@ -36,15 +43,19 @@ end return {:case => :quiet_exit } end # pseudo-accessor on @logs_target + # @return [Hash] the logs structure def output return @logs_target end # start notification on prometheus for metric logerrors, logmissing; loglines + # @param [Hash] options + # @option options [String] :session a session number for log daemon + # @return [Hash] Exiter case :quiet_exit def notify(options = {}) log = get_logger unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." } end @@ -57,10 +68,10 @@ @metric_missing.set(missing, labels: { log: item[:log] }) lines = (item[:lines])? item[:lines] : 0 @metric_lines.set(lines, labels: { log: item[:log] }) end hostname = Socket.gethostname - url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}" + url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}/#{@config.prometheus_pushgateway_path}" Prometheus::Client::Push.new('Splash',hostname, url).add(@registry) log.ok "Sending to Prometheus PushGateway done.", session return {:case => :quiet_exit } end