lib/fluent/diagtool/diagutils.rb in fluent-diagtool-1.0.1 vs lib/fluent/diagtool/diagutils.rb in fluent-diagtool-1.0.2
- old
+ new
@@ -31,10 +31,17 @@
"ps -eo pid,ppid,stime,time,%mem,%cpu,cmd",
"cat /proc/meminfo",
"netstat -plan",
"netstat -s",
]
+ if fluent_package?
+ @conf[:package_name] = "fluent-package"
+ @conf[:service_name] = "fluentd"
+ else
+ @conf[:package_name] = "td-agent"
+ @conf[:service_name] = "td-agent"
+ end
end
def run_precheck()
prechecklog = Logger.new(STDOUT, formatter: proc {|severity, datetime, progname, msg|
"#{datetime}: [Diagtool] [#{severity}] #{msg}\n"
@@ -44,20 +51,20 @@
c_env = c.export_env()
prechecklog.info("[Precheck] Fluentd Type = #{@conf[:type]}")
prechecklog.info("[Precheck] Check OS parameters...")
prechecklog.info("[Precheck] operating system = #{c_env[:os]}")
prechecklog.info("[Precheck] kernel version = #{c_env[:kernel]}")
- prechecklog.info("[Precheck] Check td-agent parameters...")
- prechecklog.info("[Precheck] td-agent conf path = #{c_env[:tdconf_path]}")
- prechecklog.info("[Precheck] td-agent conf file = #{c_env[:tdconf]}")
- prechecklog.info("[Precheck] td-agent log path = #{c_env[:tdlog_path]}")
- prechecklog.info("[Precheck] td-agent log = #{c_env[:tdlog]}")
+ prechecklog.info("[Precheck] Check #{@conf[:package_name]} parameters...")
+ prechecklog.info("[Precheck] #{@conf[:package_name]} conf path = #{c_env[:tdconf_path]}")
+ prechecklog.info("[Precheck] #{@conf[:package_name]} conf file = #{c_env[:tdconf]}")
+ prechecklog.info("[Precheck] #{@conf[:package_name]} log path = #{c_env[:tdlog_path]}")
+ prechecklog.info("[Precheck] #{@conf[:package_name]} log = #{c_env[:tdlog]}")
if c_env[:tdconf_path] == nil || c_env[:tdconf] == nil
- prechecklog.warn("[Precheck] can not find td-agent conf path: please run diagtool command with -c /path/to/<td-agent conf file>")
+ prechecklog.warn("[Precheck] can not find #{@conf[:package_name]} conf path: please run diagtool command with -c /path/to/<#{@conf[:package_name]} conf file>")
end
if c_env[:tdlog_path] == nil || c_env[:tdlog] == nil
- prechecklog.warn("[Precheck] can not find td-agent log path: please run diagtool command with -l /path/to/<td-agent log file>")
+ prechecklog.warn("[Precheck] can not find #{@conf[:package_name]} log path: please run diagtool command with -l /path/to/<#{@conf[:package_name]} log file>")
end
if c_env[:tdconf_path] != nil && c_env[:tdconf] != nil && c_env[:tdlog_path] != nil && c_env[:tdlog] != nil
prechecklog.info("[Precheck] Precheck completed. You can run diagtool command without -c and -l options")
end
end
@@ -88,39 +95,39 @@
c = CollectUtils.new(@conf, loglevel)
c_env = c.export_env()
diaglogger_info("[Collect] Loading the environment parameters...")
diaglogger_info("[Collect] operating system = #{c_env[:os]}")
diaglogger_info("[Collect] kernel version = #{c_env[:kernel]}")
- diaglogger_info("[Collect] td-agent conf path = #{c_env[:tdconf_path]}")
- diaglogger_info("[Collect] td-agent conf file = #{c_env[:tdconf]}")
- diaglogger_info("[Collect] td-agent log path = #{c_env[:tdlog_path]}")
- diaglogger_info("[Collect] td-agent log = #{c_env[:tdlog]}")
+ diaglogger_info("[Collect] #{@conf[:package_name]} conf path = #{c_env[:tdconf_path]}")
+ diaglogger_info("[Collect] #{@conf[:package_name]} conf file = #{c_env[:tdconf]}")
+ diaglogger_info("[Collect] #{@conf[:package_name]} log path = #{c_env[:tdlog_path]}")
+ diaglogger_info("[Collect] #{@conf[:package_name]} log = #{c_env[:tdlog]}")
m = MaskUtils.new(@conf, loglevel)
v = ValidUtils.new(loglevel)
- diaglogger_info("[Collect] Collecting log files of td-agent...")
+ diaglogger_info("[Collect] Collecting log files of #{@conf[:package_name]}...")
case @type
when 'fluentd'
tdlog = c.collect_tdlog()
- diaglogger_info("[Collect] log files of td-agent are stored in #{tdlog}")
+ diaglogger_info("[Collect] log files of #{@conf[:package_name]} are stored in #{tdlog}")
when 'fleuntbit'
if tdlog.empty?
diaglogger_info("FluentBit logs are redirected to the standard output interface ")
tdlog = ''
else
tdlog = c.collect_tdlog()
- diaglogger_info("[Collect] log files of td-agent are stored in #{tdlog}")
+ diaglogger_info("[Collect] log files of #{@conf[:package_name]} are stored in #{tdlog}")
end
end
- diaglogger_info("[Collect] Collecting config file of td-agent...")
+ diaglogger_info("[Collect] Collecting config file of #{@conf[:package_name]}...")
tdconf = c.collect_tdconf()
diaglogger_info("[Collect] config file is stored in #{tdconf}")
- diaglogger_info("[Collect] Collecting td-agent gem information...")
+ diaglogger_info("[Collect] Collecting #{@conf[:package_name]} gem information...")
tdgem = c.collect_tdgems()
- diaglogger_info("[Collect] td-agent gem information is stored in #{tdgem}")
+ diaglogger_info("[Collect] #{@conf[:package_name]} gem information is stored in #{tdgem}")
diaglogger_info("[Collect] Collecting config file of OS log...")
oslog = c.collect_oslog()
if @conf[:mask] == 'yes'
diaglogger_info("[Mask] Masking OS log file : #{oslog}...")
@@ -155,15 +162,15 @@
}
###
# Correct information to be validated
###
- diaglogger_info("[Collect] Collecting systctl information...")
+ diaglogger_info("[Collect] Collecting sysctl information...")
sysctl = c.collect_cmd_output("sysctl -a")
diaglogger_info("[Collect] sysctl information is stored in #{sysctl}")
- diaglogger_info("[Valid] Validating systctl information...")
+ diaglogger_info("[Valid] Validating sysctl information...")
ret, sysctl = v.valid_sysctl(sysctl)
list = sysctl.keys
list.each do |k|
if sysctl[k]['result'] == 'correct'
diaglogger_info("[Valid] Sysctl: #{k} => #{sysctl[k]['value']} is correct (recommendation is #{sysctl[k]['recommend']})")
@@ -184,19 +191,19 @@
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}...")
+ diaglogger_info("[Mask] Masking #{@conf[:package_name]} config file : #{file}...")
m.mask_tdlog(file, clean = true)
}
end
if @conf[:mask] == 'yes'
if tdlog != nil
tdlog.each { | file |
- diaglogger_info("[Mask] Masking td-agent log file : #{file}...")
+ diaglogger_info("[Mask] Masking #{@conf[:package_name]} log file : #{file}...")
filename = file.split("/")[-1]
if filename.include?(".gz")
m.mask_tdlog_gz(file, clean = true)
elsif
m.mask_tdlog(file, clean = true)
@@ -227,11 +234,11 @@
if options[:precheck] == false
if params[:output] != nil
if Dir.exist?(params[:output])
options[:basedir] = params[:output]
else
- raise "output directory '#{basedir}' does not exist"
+ raise "output directory '#{params[:output]}' does not exist"
end
else
raise "output directory '-o' must be specified"
end
end
@@ -310,8 +317,12 @@
end
def diaglogger_error(str)
@logger.error(str)
@logger_file.error(str)
+ end
+
+ def fluent_package?
+ File.exist?("/etc/fluent/fluentd.conf") || File.exist?("/opt/fluent/bin/fluentd")
end
end
end