我正在开发一种工具来监控当前在集群上运行的作业(19 个节点,40 个核心)。有没有办法确定 slurm 队列中的每个作业正在使用哪个特定的 cpu?我正在使用“pidstat”、“mpstat”和“ps -eFj”获取数据,这些数据告诉我哪些进程正在特定核心上运行,但无法将这些进程 ID 与 Slurm 使用的作业 ID 相关联。'scontrol show job' 提供了很多信息,但没有具体的 cpu 分配。有没有办法做到这一点?
下面是收集数据的代码:
#!/usr/bin/env python
import subprocess
import threading
import time
def scan():
data = [[None, None, None] for i in range(19)]
def mpstat(node):
if(node == 1):
output = subprocess.check_output(['mpstat', '-P', 'ALL', '1', '1'])
else:
output = subprocess.check_output(['ssh', 'node' + str(node), 'mpstat', '-P', 'ALL', '1', '1'])
data[node - 1][0] = output
def pidstat(node):
if(node == 1):
output = subprocess.check_output(['pidstat', '1', '1'])
else:
output = subprocess.check_output(['ssh', 'node' + str(node), 'pidstat', '1', '1'])
data[node - 1][1] = output
def ps(node):
if(node == 1):
output = subprocess.check_output(['ps', '-eFj'])
else:
output = subprocess.check_output(['ssh', 'node' + str(node), 'ps', '-eFj'])
data[node - 1][2] = output
threads = [[None, None, None] for i in range(19)]
for node in range(1, 19 + 1):
threads[node - 1][0] = threading.Thread(target=mpstat, args=(node,))
threads[node - 1][0].start()
threads[node - 1][1] = threading.Thread(target=pidstat, args=(node,))
threads[node - 1][1].start()
threads[node - 1][2] = threading.Thread(target=ps, args=(node,))
threads[node - 1][2].start()
while True:
alive = [[not t.isAlive() for t in n] for n in threads]
alive = [t for n in alive for t in n]
if(all(alive)):
break
time.sleep(1.0)
return(data)