Skip to content

Commit fee2f28

Browse files
Fix previously created nodes deleted to soon
1 parent 4c2e1b2 commit fee2f28

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

autoscaling/crontab/autoscale_slurm.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ def getClusters():
2424
out = subprocess.Popen(['sinfo','-r','-o','\"%T %E %D %N\"'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
2525
stdout,stderr = out.communicate()
2626
return stdout.split("\n")[1:]
27+
28+
def getIdleTime(node):
29+
out = subprocess.Popen(["sacct -X -n -S 01/01/01 -N "+node+" -o End | tail -n 1"],stdout=subprocess.PIPE, stderr=subprocess.STDOUT,shell=True)
30+
stdout,stderr = out.communicate()
31+
last_end_time = None
32+
try:
33+
last_end_time = datetime.datetime.strptime(stdout.strip(),"%Y-%m-%dT%H:%M:%S")
34+
except:
35+
pass
36+
out = subprocess.Popen(["scontrol show node "+node+" | grep SlurmdStartTime | awk '{print $2}'"],stdout=subprocess.PIPE, stderr=subprocess.STDOUT,shell=True)
37+
stdout,stderr = out.communicate()
38+
cluster_start_time=datetime.datetime.strptime(stdout.split("\n")[0].split("=")[1],"%Y-%m-%dT%H:%M:%S")
39+
if last_end_time is None:
40+
right_time=cluster_start_time
41+
else:
42+
right_time=max([cluster_start_time,last_end_time])
43+
return ( datetime.datetime.now() - right_time ).total_seconds()
2744

2845
def getIdleTime(node):
2946
out = subprocess.Popen(["sacct -X -n -S 01/01/01 -N "+node+" -o End | tail -n 1"],stdout=subprocess.PIPE, stderr=subprocess.STDOUT,shell=True)

0 commit comments

Comments
 (0)