lib/fluent/diagtool/diagutils.rb in fluent-diagtool-0.1.7 vs lib/fluent/diagtool/diagutils.rb in fluent-diagtool-0.1.8
- old
+ new
@@ -25,30 +25,16 @@
class DiagUtils
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[: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[:basedir]}")
- #diaglogger_info(" Option : Mask = #{@conf[:mask]}")
- #diaglogger_info(" Option : Word list = #{@conf[:words]}")
- #diaglogger_info(" Option : Hash Seed = #{@conf[:seed]}")
+ @cmd_list = [
+ "ps -eo pid,ppid,stime,time,%mem,%cpu,cmd",
+ "cat /proc/meminfo",
+ "netstat -plan",
+ "netstat -s",
+ ]
end
def run_precheck()
prechecklog = Logger.new(STDOUT, formatter: proc {|severity, datetime, progname, msg|
"#{datetime}: [Diagtool] [#{severity}] #{msg}\n"
@@ -128,43 +114,39 @@
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] 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")
+ ntp = c.collect_cmd_output(command="chronyc sources")
+ diaglogger_info("[Collect] date/time information is stored in #{ntp}")
elsif system('which ntpq > /dev/null 2>&1')
- ntp = c.collect_ntp(command="ntp")
+ ntp = c.collect_ntp(command="ntpq -p")
+ diaglogger_info("[Collect] date/time information is stored in #{ntp}")
else
diaglogger_warn("[Collect] chrony/ntp does not exist. skip collectig date/time information")
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_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
- diaglogger_info("[Collect] netstat information is stored in #{netstat_n} and #{netstat_s}")
- else
- diaglogger_warn("[Collect] netstat does not exist. skip collectig netstat")
- end
+ ###
+ # Correct OS information
+ ###
+ @cmd_list.each { |cmd|
+ diaglogger_info("[Collect] Collecting command output : command = #{cmd}")
+ out = c.collect_cmd_output(cmd)
+ if @conf[:mask] == 'yes'
+ diaglogger_info("[Mask] Masking netstat file : #{out}...")
+ out = m.mask_tdlog(out, clean = true)
+ end
+ diaglogger_info("[Collect] Collecting command output #{cmd.split[0]} stored in #{out}")
+ }
+
+ ###
+ # Correct information to be validated
+ ###
diaglogger_info("[Collect] Collecting systctl information...")
- sysctl = c.collect_sysctl()
+ sysctl = c.collect_cmd_output("sysctl -a")
diaglogger_info("[Collect] sysctl information is stored in #{sysctl}")
diaglogger_info("[Valid] Validating systctl information...")
ret, sysctl = v.valid_sysctl(sysctl)
list = sysctl.keys
@@ -174,24 +156,20 @@
elsif sysctl[k]['result'] == 'incorrect'
diaglogger_warn("[Valid] Sysctl: #{k} => #{sysctl[k]['value']} is incorrect (recommendation is #{sysctl[k]['recommend']})")
end
end
- if system("sh -c 'ulimit -n'")
- diaglogger_info("[Collect] Collecting ulimit information...")
- ulimit = c.collect_ulimit()
- diaglogger_info("[Collect] ulimit information is stored in #{ulimit}")
+ diaglogger_info("[Collect] Collecting ulimit information...")
+ ulimit = c.collect_cmd_output(cmd="sh -c 'ulimit -n'")
+ diaglogger_info("[Collect] ulimit information is stored in #{ulimit}")
- diaglogger_info("[Valid] Validating ulimit information...")
- ret, rec, val = v.valid_ulimit(ulimit)
- if ret == true
- diaglogger_info("[Valid] ulimit => #{val} is correct (recommendation is >#{rec})")
- else
- diaglogger_warn("[Valid] ulimit => #{val} is incorrect (recommendation is >#{rec})")
- end
+ diaglogger_info("[Valid] Validating ulimit information...")
+ ret, rec, val = v.valid_ulimit(ulimit)
+ if ret == true
+ diaglogger_info("[Valid] ulimit => #{val} is correct (recommendation is >#{rec})")
else
- diaglogger_warn("[Collect] ulimit command does not exist. skip collectig ulimit")
+ diaglogger_warn("[Valid] ulimit => #{val} is incorrect (recommendation is >#{rec})")
end
if @conf[:mask] == 'yes'
tdconf.each { | file |
diaglogger_info("[Mask] Masking td-agent config file : #{file}...")
@@ -210,10 +188,10 @@
if @conf[:mask] == 'yes'
diaglogger_info("[Mask] Export mask log file : #{@masklog}")
m.export_masklog(@masklog)
end
-
+
tar_file = c.compress_output()
diaglogger_info("[Collect] Generate tar file #{tar_file}")
end
def parse_diagconf(params)