xjf6b commited on
Commit
7f5ebc7
·
verified ·
1 Parent(s): 5afc051

Update vps_monitor.py

Browse files
Files changed (1) hide show
  1. vps_monitor.py +10 -5
vps_monitor.py CHANGED
@@ -14,7 +14,7 @@ vps_status = {}
14
 
15
  # 设置日志
16
  logging.basicConfig(
17
- level=logging.INFO,
18
  format='%(asctime)s - %(levelname)s - %(message)s',
19
  handlers=[
20
  logging.StreamHandler(sys.stdout),
@@ -57,6 +57,7 @@ def get_vps_configs():
57
  return configs
58
 
59
  def parse_runtime(etime):
 
60
  parts = etime.split('-')
61
  if len(parts) > 1:
62
  days = int(parts[0])
@@ -71,10 +72,13 @@ def parse_runtime(etime):
71
  hours, minutes = map(int, time_parts)
72
  seconds = 0
73
  else:
74
- return "Unknown"
 
75
 
76
  total_seconds = days * 86400 + hours * 3600 + minutes * 60 + seconds
77
- return str(timedelta(seconds=total_seconds))
 
 
78
 
79
  def check_and_run_script(config):
80
  logger.info(f"Checking VPS {config['index']}: {config['hostname']} - {config['script_path']}")
@@ -105,15 +109,16 @@ def check_and_run_script(config):
105
 
106
  stdin, stdout, stderr = client.exec_command(check_command)
107
  output = stdout.read().decode('utf-8').strip()
 
108
 
109
  if output and (last_pid or script_path in output):
110
  parts = output.split()
111
  if last_pid:
112
  pid = last_pid
113
- runtime = parse_runtime(parts[1]) if len(parts) > 1 else "Unknown"
114
  else:
115
  pid = parts[1] if len(parts) > 1 else "Unknown"
116
- runtime = parse_runtime(parts[9]) if len(parts) > 9 else "Unknown"
117
  status = "Running"
118
  logger.info(f"Script {script_name} is running. PID: {pid}, Runtime: {runtime}")
119
  else:
 
14
 
15
  # 设置日志
16
  logging.basicConfig(
17
+ level=logging.DEBUG, # 将日志级别改为 DEBUG 以获取更多信息
18
  format='%(asctime)s - %(levelname)s - %(message)s',
19
  handlers=[
20
  logging.StreamHandler(sys.stdout),
 
57
  return configs
58
 
59
  def parse_runtime(etime):
60
+ logger.debug(f"Parsing runtime: {etime}")
61
  parts = etime.split('-')
62
  if len(parts) > 1:
63
  days = int(parts[0])
 
72
  hours, minutes = map(int, time_parts)
73
  seconds = 0
74
  else:
75
+ logger.warning(f"Unexpected time format: {etime}")
76
+ return "0:00:00"
77
 
78
  total_seconds = days * 86400 + hours * 3600 + minutes * 60 + seconds
79
+ runtime = str(timedelta(seconds=total_seconds))
80
+ logger.debug(f"Parsed runtime: {runtime}")
81
+ return runtime
82
 
83
  def check_and_run_script(config):
84
  logger.info(f"Checking VPS {config['index']}: {config['hostname']} - {config['script_path']}")
 
109
 
110
  stdin, stdout, stderr = client.exec_command(check_command)
111
  output = stdout.read().decode('utf-8').strip()
112
+ logger.debug(f"Raw output from ps command: {output}")
113
 
114
  if output and (last_pid or script_path in output):
115
  parts = output.split()
116
  if last_pid:
117
  pid = last_pid
118
+ runtime = parse_runtime(parts[1]) if len(parts) > 1 else "0:00:00"
119
  else:
120
  pid = parts[1] if len(parts) > 1 else "Unknown"
121
+ runtime = parse_runtime(parts[9]) if len(parts) > 9 else "0:00:00"
122
  status = "Running"
123
  logger.info(f"Script {script_name} is running. PID: {pid}, Runtime: {runtime}")
124
  else: