gpt4 book ai didi

python 向变量添加额外值

转载 作者:太空宇宙 更新时间:2023-11-04 04:24:17 25 4
gpt4 key购买 nike

我正在运行一个在两台服务器上运行的 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()

服务器 1 的输出:(正常)

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”值,然后立即读取正确的值。

有什么想法为什么会发生这种情况吗?

最佳答案

任一进程是否接收信号?这可能会导致系统调用比预期提前终止。

关于python 向变量添加额外值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10401912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com