我正在运行一个在两台服务器上运行的 python zabbix trapper 脚本,它在其中一台服务器上运行良好。它每 30 秒运行一次。这是从“ss”读取 time_wait 状态的代码部分
file_log = "/tmp/tcpstate.log"
proc = open(file_log,"a")
file = "/var/log/safesquid/safesquid/performance/performance.log"
time_wait_cmd = subprocess.Popen("ss -o state time-wait | grep webcache | wc -l",shell=True,stdout=subprocess.PIPE)
ssquid_time = time_wait_cmd.communicate()[0]
proc_string = datetime.datetime.now().strftime("%d-%m-%y %H:%M:%S") + " " + "Time_WAIT: " + ssquid_time + "\n"
proc.write(proc_string)
proc.close()
server1 的输出:(确定)
01-05-12 17:40:50 Time_WAIT: 286
01-05-12 17:41:20 Time_WAIT: 251
01-05-12 17:41:50 Time_WAIT: 366
01-05-12 17:42:20 Time_WAIT: 335
01-05-12 17:42:50 Time_WAIT: 287
01-05-12 17:43:20 Time_WAIT: 375
01-05-12 17:43:51 Time_WAIT: 386
01-05-12 17:44:21 Time_WAIT: 383
Server2 的输出:(问题)
01-05-12 17:44:03 Time_WAIT: 368
01-05-12 17:44:32 Time_WAIT: 388
01-05-12 17:45:01 Time_WAIT: 0
01-05-12 17:45:01 Time_WAIT: 339
01-05-12 17:45:31 Time_WAIT: 311
01-05-12 17:46:00 Time_WAIT: 400
01-05-12 17:46:01 Time_WAIT: 0
01-05-12 17:46:29 Time_WAIT: 411
01-05-12 17:46:58 Time_WAIT: 448
因为它每 30 秒被调用一次,我不知道为什么在 Server2 上它得到“0”值然后立即读取正确的值。
任何想法为什么会发生这种情况?