lib/fluent/diagtool/diagutils.rb in fluent-diagtool-0.1.2 vs lib/fluent/diagtool/diagutils.rb in fluent-diagtool-0.1.3

- old
+ new

@@ -26,26 +26,31 @@ def initialize(params) time = Time.new @time_format = time.strftime("%Y%m%d%0k%M%0S") @conf = parse_diagconf(params) @conf[:time] = @time_format - @conf[:workdir] = @conf[:output_dir] + '/' + @time_format + @conf[:workdir] = @conf[:basedir] + '/' + @time_format + @conf[:outdir] = @conf[:workdir] + '/output' + FileUtils.mkdir_p(@conf[:workdir]) + FileUtils.mkdir_p(@conf[:outdir]) + diaglog = @conf[:workdir] + '/diagtool.output' @masklog = './mask_' + @time_format + '.json' @logger = Logger.new(STDOUT, formatter: proc {|severity, datetime, progname, msg| "#{datetime}: [Diagtool] [#{severity}] #{msg}\n" }) @logger_file = Logger.new(diaglog, formatter: proc {|severity, datetime, progname, msg| "#{datetime}: [Diagtool] [#{severity}] #{msg}\n" }) diaglogger_info("Parsing command options...") - diaglogger_info(" Option : Output directory = #{@conf[:output_dir]}") + diaglogger_info(" Option : Output directory = #{@conf[:basedir]}") diaglogger_info(" Option : Mask = #{@conf[:mask]}") diaglogger_info(" Option : Word list = #{@conf[:words]}") diaglogger_info(" Option : Hash Seed = #{@conf[:seed]}") end + def diagtool() loglevel = 'WARN' diaglogger_info("Initializing parameters...") c = CollectUtils.new(@conf, loglevel) c_env = c.export_env() @@ -76,14 +81,18 @@ if @conf[:mask] == 'yes' diaglogger_info("[Mask] Masking OS log file : #{oslog}...") oslog = m.mask_tdlog(oslog, clean = true) end diaglogger_info("[Collect] config file is stored in #{oslog}") - + + diaglogger_info("[Collect] Collecting process information...") + meminfo = c.collect_ps_eo() + diaglogger_info("[Collect] process informationis stored in #{meminfo}") + diaglogger_info("[Collect] Collecting OS memory information...") meminfo = c.collect_meminfo() - diaglogger_info("[Collect] config file is stored in #{meminfo}") + diaglogger_info("[Collect] OS memory information is stored in #{meminfo}") diaglogger_info("[Collect] Collecting date/time information...") if system('which chronyc > /dev/null 2>&1') ntp = c.collect_ntp(command="chrony") elsif system('which ntpq > /dev/null 2>&1') @@ -93,11 +102,11 @@ end diaglogger_info("[Collect] date/time information is stored in #{ntp}") diaglogger_info("[Collect] Collecting netstat information...") if system('which netstat > /dev/null 2>&1') - netstat_n = c.collect_netstat_n() + netstat_n = c.collect_netstat_plan() netstat_s = c.collect_netstat_s() if @conf[:mask] == 'yes' diaglogger_info("[Mask] Masking netstat file : #{netstat_n}...") netstat_n = m.mask_tdlog(netstat_n, clean = true) end @@ -156,21 +165,17 @@ diaglogger_info("[Collect] Generate tar file #{tar_file}") end def parse_diagconf(params) options = { - :output_dir => '', - :mask => 'no', - :words => [], - :wfile => '', - :seed => '' + :basedir => '', :mask => '', :words => [], :wfile => '', :seed => '' } if params[:output] != nil if Dir.exist?(params[:output]) - options[:output_dir] = params[:output] + options[:basedir] = params[:output] else - raise "output directory '#{output_dir}' does not exist" + raise "output directory '#{basedir}' does not exist" end else raise "output directory '-o' must be specified" end if params[:mask] == nil @@ -195,21 +200,25 @@ end options[:words] = options[:words].uniq options[:seed] = params[:"hash-seed"] if params[:"hash-seed"] != nil return options end + def diaglogger_debug(str) @logger.debug(str) @logger_file.debug(str) end + def diaglogger_info(str) @logger.info(str) @logger_file.info(str) end + def diaglogger_warn(str) @logger.warn(str) @logger_file.warn(str) end + def diaglogger_error(str) @logger.error(str) @logger_file.error(str) end end