xjf6b commited on
Commit
5afc051
·
verified ·
1 Parent(s): 622dc75

Update vps_monitor.py

Browse files
Files changed (1) hide show
  1. vps_monitor.py +23 -3
vps_monitor.py CHANGED
@@ -56,6 +56,26 @@ def get_vps_configs():
56
  index += 1
57
  return configs
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  def check_and_run_script(config):
60
  logger.info(f"Checking VPS {config['index']}: {config['hostname']} - {config['script_path']}")
61
  client = None
@@ -90,10 +110,10 @@ def check_and_run_script(config):
90
  parts = output.split()
91
  if last_pid:
92
  pid = last_pid
93
- runtime = parts[1] if len(parts) > 1 else "Unknown"
94
  else:
95
  pid = parts[1] if len(parts) > 1 else "Unknown"
96
- runtime = parts[9] if len(parts) > 9 else "Unknown"
97
  status = "Running"
98
  logger.info(f"Script {script_name} is running. PID: {pid}, Runtime: {runtime}")
99
  else:
@@ -104,7 +124,7 @@ def check_and_run_script(config):
104
 
105
  if new_pid.isdigit():
106
  pid = new_pid
107
- runtime = "00:00"
108
  status = "Restarted"
109
  logger.info(f"Script {script_name} restarted. New PID: {pid}")
110
  else:
 
56
  index += 1
57
  return configs
58
 
59
+ def parse_runtime(etime):
60
+ parts = etime.split('-')
61
+ if len(parts) > 1:
62
+ days = int(parts[0])
63
+ time_parts = parts[1].split(':')
64
+ else:
65
+ days = 0
66
+ time_parts = parts[0].split(':')
67
+
68
+ if len(time_parts) == 3:
69
+ hours, minutes, seconds = map(int, time_parts)
70
+ elif len(time_parts) == 2:
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']}")
81
  client = None
 
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:
 
124
 
125
  if new_pid.isdigit():
126
  pid = new_pid
127
+ runtime = "0:00:00"
128
  status = "Restarted"
129
  logger.info(f"Script {script_name} restarted. New PID: {pid}")
130
  else: