def __init__(self, args): if args.alias: self.alias = args.alias else: self.alias = util.get_hostname() if args.output and util.is_abs_path(args.output): self.outdir = args.output self.full_outdir = fileopt.create_dir( os.path.join(self.outdir, self.alias)) else: if args.output: self.outdir = args.output self.full_outdir = fileopt.create_dir( os.path.join(self.cwd, self.outdir, self.alias)) logging.debug("Output directory is: %s" % self.full_outdir)
def run_blktrace(self, args): if args.subcmd_runtime != "blktrace": logging.debug("Ingoring collecting of blktrace data.") return if not args.target: return blktrace_outdir = fileopt.create_dir( os.path.join(self.full_outdir, "blktrace")) if not blktrace_outdir: return time = 60 if args.time: time = args.time util.run_cmd_for_a_while( ["blktrace", "-d", args.target, "-D", blktrace_outdir], time)
def collector(self, args): # call `collector` and store data to output dir base_dir = os.path.join(util.pwd(), "../") collector_exec = os.path.join(base_dir, "bin/collector") collector_outdir = fileopt.create_dir( os.path.join(self.full_outdir, "collector")) if args.pid: logging.debug("Collecting process infor only for PID %s" % args.pid) collector_exec = [collector_exec, '-proc', '-pid', '%s' % args.pid] elif args.port: protocol = 'UDP' if args.udp else 'TCP' pids = ','.join( str(_pid) for _pid in proc_meta.find_process_by_port( args.port, protocol)) logging.debug("Collecting process infor for PIDs %s" % pids) collector_exec = [collector_exec, '-proc', '-pid', '%s' % pids] # else call collector without any argument stdout, stderr = util.run_cmd(collector_exec) if stderr: logging.info("collector output:" % str(stderr)) try: self.collector_data = json.loads(stdout) except json.JSONDecodeError: logging.critical("Error collecting system info:\n%s" % stderr) return # save various info to seperate .json files for k, v in self.collector_data.items(): # This is a dirty hack to omit empty results, until Go fix that upstream, # see: https://github.com/golang/go/issues/11939 if (args.pid or args.port) and k in ['sysinfo', 'ntp']: continue if not v or len(v) < 1: logging.debug("Skipped empty result %s:%s" % (k, v)) continue fileopt.write_file(os.path.join(collector_outdir, "%s.json" % k), json.dumps(v, indent=2))
def collector(self): # TODO: warn on non-empty output dir # call `collector` and store data to output dir base_dir = os.path.join(util.pwd(), "../") collector_exec = os.path.join(base_dir, "bin/collector") collector_outdir = fileopt.create_dir( os.path.join(self.full_outdir, "collector")) stdout, stderr = util.run_cmd(collector_exec) if stderr: logging.info("collector output:" % str(stderr)) try: self.collector_data = json.loads(stdout) except json.JSONDecodeError: logging.critical("Error collecting system info:\n%s" % stderr) return # save various info to seperate .json files for k, v in self.collector_data.items(): fileopt.write_file(os.path.join(collector_outdir, "%s.json" % k), json.dumps(v, indent=2))
def run_vmtouch(self, args): if args.subcmd_runtime != "vmtouch": logging.debug("Ingoring collecting of vmtouch data.") return if not args.target: return base_dir = os.path.join(util.pwd(), "../") vmtouch_exec = os.path.join(base_dir, "bin/vmtouch") vmtouch_outdir = fileopt.create_dir( os.path.join(self.full_outdir, "vmtouch")) if not vmtouch_outdir: return stdout, stderr = util.run_cmd([vmtouch_exec, "-v", args.target]) if stderr: logging.info("vmtouch output: %s" % str(stderr)) return fileopt.write_file( os.path.join( vmtouch_outdir, "%s_%d.txt" % (args.target.replace("/", "_"), (time.time() * 1000))), str(stdout))