本文整理汇总了Python中psutil.Process.get_connections方法的典型用法代码示例。如果您正苦于以下问题:Python Process.get_connections方法的具体用法?Python Process.get_connections怎么用?Python Process.get_connections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil.Process
的用法示例。
在下文中一共展示了Process.get_connections方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: status
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import get_connections [as 别名]
def status(self):
"""Check by socket if the openoffice work."""
pid = self.pid()
if pid is None or not pid_exists(pid):
return False
process = Process(pid)
try:
for connection in process.get_connections():
if connection.status == 'LISTEN' and \
connection.local_address[1] == self.port:
return True
except AccessDenied:
return False
return False
示例2: _on_server
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import get_connections [as 别名]
def _on_server(self, args):
os.chdir(self.original_dir)
abs_args_path = os.path.abspath(args.path)
component_details = open(os.path.join(abs_args_path, ZATO_INFO_FILE)).read()
out = {
'component_details': component_details,
'component_full_path': abs_args_path,
'component_host': current_host(),
'component_running': False,
'current_time': datetime.now().isoformat(),
'current_time_utc': datetime.utcnow().isoformat(),
'master_proc_connections': None,
'master_proc_pid': None,
'master_proc_name': None,
'master_proc_create_time': None,
'master_proc_create_time_utc': None,
'master_proc_username': None,
'master_proc_workers_no': None,
'master_proc_workers_pids': None,
}
master_proc_pid = self._zdaemon_command('status')
master_proc_pid = master_proc_pid.values()
if master_proc_pid and master_proc_pid[0]:
out['component_running'] = True
master_proc_pid = int(master_proc_pid[0])
master_proc = Process(master_proc_pid)
workers_pids = sorted(elem.pid for elem in master_proc.get_children())
out['master_proc_connections'] = master_proc.get_connections()
out['master_proc_pid'] = master_proc.pid
out['master_proc_create_time'] = datetime.fromtimestamp(master_proc.create_time).isoformat()
out['master_proc_create_time_utc'] = datetime.fromtimestamp(master_proc.create_time, UTC).isoformat()
out['master_proc_username'] = master_proc.username
out['master_proc_name'] = master_proc.name
out['master_proc_workers_no'] = len(workers_pids)
out['master_proc_workers_pids'] = workers_pids
for pid in workers_pids:
worker = Process(pid)
out['worker_{}_create_time'.format(pid)] = datetime.fromtimestamp(worker.create_time).isoformat()
out['worker_{}_create_time_utc'.format(pid)] = datetime.fromtimestamp(worker.create_time, UTC).isoformat()
out['worker_{}_connections'.format(pid)] = worker.get_connections()
if getattr(args, 'json', False):
out['component_details'] = loads(out['component_details'])
self.logger.info(dumps(out))
else:
cols_width = args.cols_width if args.cols_width else DEFAULT_COLS_WIDTH
cols_width = (elem.strip() for elem in cols_width.split(','))
cols_width = [int(elem) for elem in cols_width]
table = Texttable()
table.set_cols_width(cols_width)
# Use text ('t') instead of auto so that boolean values don't get converted into ints
table.set_cols_dtype(['t', 't'])
rows = [['Key', 'Value']]
rows.extend(sorted(out.items()))
table.add_rows(rows)
self.logger.info(table.draw())
示例3: _on_server
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import get_connections [as 别名]
def _on_server(self, args):
os.chdir(self.original_dir)
abs_args_path = os.path.abspath(args.path)
component_details = open(os.path.join(abs_args_path, ZATO_INFO_FILE)).read()
out = {
"component_details": component_details,
"component_full_path": abs_args_path,
"component_host": current_host(),
"component_running": False,
"current_time": datetime.now().isoformat(),
"current_time_utc": datetime.utcnow().isoformat(),
"master_proc_connections": None,
"master_proc_pid": None,
"master_proc_name": None,
"master_proc_create_time": None,
"master_proc_create_time_utc": None,
"master_proc_username": None,
"master_proc_workers_no": None,
"master_proc_workers_pids": None,
}
master_proc_pid = self._zdaemon_command("status")
master_proc_pid = master_proc_pid.values()
if master_proc_pid and master_proc_pid[0]:
out["component_running"] = True
master_proc_pid = int(master_proc_pid[0])
master_proc = Process(master_proc_pid)
workers_pids = sorted(elem.pid for elem in master_proc.get_children())
out["master_proc_connections"] = master_proc.get_connections()
out["master_proc_pid"] = master_proc.pid
out["master_proc_create_time"] = datetime.fromtimestamp(master_proc.create_time).isoformat()
out["master_proc_create_time_utc"] = datetime.fromtimestamp(master_proc.create_time, UTC).isoformat()
out["master_proc_username"] = master_proc.username
out["master_proc_name"] = master_proc.name
out["master_proc_workers_no"] = len(workers_pids)
out["master_proc_workers_pids"] = workers_pids
for pid in workers_pids:
worker = Process(pid)
worker_memory_percent = worker.get_memory_percent()
out["worker_{}_create_time".format(pid)] = datetime.fromtimestamp(worker.create_time).isoformat()
out["worker_{}_create_time_utc".format(pid)] = datetime.fromtimestamp(
worker.create_time, UTC
).isoformat()
out["worker_{}_connections".format(pid)] = worker.get_connections()
if getattr(args, "json", False):
out["component_details"] = loads(out["component_details"])
self.logger.info(dumps(out))
else:
cols_width = args.cols_width if args.cols_width else DEFAULT_COLS_WIDTH
cols_width = (elem.strip() for elem in cols_width.split(","))
cols_width = [int(elem) for elem in cols_width]
table = Texttable()
table.set_cols_width(cols_width)
# Use text ('t') instead of auto so that boolean values don't get converted into ints
table.set_cols_dtype(["t", "t"])
rows = [["Key", "Value"]]
rows.extend(sorted(out.items()))
table.add_rows(rows)
self.logger.info(table.draw())