class Splash::Logs::LogScanner
Log scanner and notifier
Public Class Methods
new()
click to toggle source
LogScanner
Constructor : initialize prometheus metrics return [Splash::Logs::LogScanner]
# File lib/splash/logs.rb, line 94 def initialize @logs_target = Marshal.load(Marshal.dump(get_config.logs)) @config = get_config end
Public Instance Methods
analyse()
click to toggle source
start log analyse for log target in config @return [Hash] Exiter
case :quiet_exit
# File lib/splash/logs.rb, line 103 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 record[:count] = File.readlines(record[:log]).grep(/#{record[:pattern]}/).size record[:status] = :matched if record[:count] > 0 record[:lines] = `wc -l "#{record[:log]}"`.strip.split(/\s+/)[0].to_i unless record[:status] == :missing else record[:status] = :missing end end return {:case => :quiet_exit } end
notify(options = {})
click to toggle source
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
# File lib/splash/logs.rb, line 128 def notify(options = {}) log = get_logger unless verify_service url: @config.prometheus_pushgateway_url then return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." } end session = (options[:session]) ? options[:session] : log.get_session log.info "Sending metrics to Prometheus Pushgateway", session @logs_target.each do |item| logsrec = LogsRecords::new item[:label] errors = (item[:count])? item[:count] : 0 lines = (item[:lines])? item[:lines] : 0 missing = (item[:status] == :missing)? 1 : 0 file = item[:log] logsrec.purge(item[:retention]) logsrec.add_record :status => item[:status], :errors => errors, :lines => lines, :file => file logsmonitor = LogsNotifier::new({name: item[:label], missing: missing, file: file, errors: errors, lines: lines}) if logsmonitor.notify then log.ok "Sending metrics for log #{file} to Prometheus Pushgateway", session else log.ko "Failed to send metrics for log #{file} to Prometheus Pushgateway", session end end return {:case => :quiet_exit } end
output()
click to toggle source
pseudo-accessor on @logs_target @return [Hash] the logs structure
# File lib/splash/logs.rb, line 120 def output return @logs_target end