/[pdpsoft]/nl.nikhef.ndpf.groupviews/trunk/mcpeil
ViewVC logotype

Contents of /nl.nikhef.ndpf.groupviews/trunk/mcpeil

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3340 - (show annotations) (download)
Fri May 6 14:18:44 2022 UTC (4 months, 3 weeks ago) by templon
File size: 3724 byte(s)
various changes


1 #!/usr/bin/env python
2 from torque_utils import pbsnodes
3
4 import os
5 # line below is needed since we have torque2 utils also in PATH ...
6 # this for korf (torque4), put right dir up front.
7
8 os.environ['PATH']='/opt/torque4/bin:' + os.environ['PATH']
9
10 import sys
11 import subprocess
12
13 GROUPS = ['atlb', 'atlaspil', 'ligo', 'datagrid', 'dune', 'ilc', 'virgo',
14 'pvier', 'lsgrid', 'pbbmri', 'atlsgm']
15 MCQUEUE = 'atlasmc7'
16 TORQUE = "korf.nikhef.nl"
17
18 import pickle
19
20 # pkl_file = open('/data/tunnel/user/templon/wnodes-korf.pkl', 'rb')
21 # wnodes_k = pickle.load(pkl_file )
22 # pkl_file.close()
23
24 # wnodes = wnodes_k
25
26 wnodes = pbsnodes()
27
28 mcnodes = list()
29
30 for node in wnodes:
31 if \
32 'mc' in node.properties \
33 and 'el7' not in node.properties \
34 and node.state.count('offline') == 0:
35 mcnodes.append(node)
36
37 mcslots = 0
38 mcfree = 0
39 mcrun = 0
40
41 usedkeys = ['egroup', 'jobid', 'queue', 'job_state', 'euser', 'exec_host' ]
42
43 import torqueJobs
44 import torqueAttMappers as tam
45
46 import tempfile
47 qsfname = tempfile.mktemp(".txt","qsmf",os.environ['HOME']+"/tmp")
48
49 import time
50 # os.system('/usr/bin/qstat -f %s@%s' %(MCQUEUE, TORQUE) + ' > ' + qsfname)
51 os.system('/opt/torque4/bin/qstat-torque -f %s@%s' \
52 % ( MCQUEUE,'korf.nikhef.nl') + ' > ' + qsfname)
53 now = time.mktime(time.localtime())
54
55 jlist = torqueJobs.qs_parsefile(qsfname)
56
57 os.system('mv ' + qsfname + ' ' + os.environ['HOME'] + '/tmp/qstat.last.mcpool.txt')
58
59 def mapatts(indict,inkeys):
60 sdict = tam.sub_dict(indict,inkeys)
61 odict = dict()
62 for k in sdict.keys():
63 if k in tam.tfl and sdict[k]:
64 secs = tam.hms(sdict[k])
65 sdict[k] = secs/3600.
66 if k in tam.mfl and sdict[k]:
67 mebi = tam.memconvert(sdict[k])
68 sdict[k] = mebi
69 if k in tam.tfl2 and sdict[k]:
70 secs = tam.tconv(sdict[k])
71 sdict[k] = secs
72 elif k == 'job_state':
73 statelett = sdict[k]
74 if statelett in ['Q','W']:
75 sdict[k] = 'queued'
76 elif statelett in ['R','E']:
77 sdict[k] = 'running'
78 elif k == 'exec_host' and sdict[k]:
79 termpos = sdict[k].find('/')
80 wnstring = sdict[k][:termpos]
81 odict['wn'] = wnstring
82 if sdict[k]:
83 odict[k] = sdict[k]
84 return odict
85
86 mcjobdict = dict()
87 for j in jlist:
88 mcjobdict[j['jobid']] = mapatts(j,usedkeys)
89
90 # {'queue': 'atlasmc', 'euser': 'templon', 'job_state': 'queued', \
91 # 'egroup': 'datagrid', 'jobid': '43609804.stro.nikhef.nl'}
92
93 runjobdict = dict() # runjobdict[wn][group] = num running procs
94
95 nq = dict()
96 nr = dict()
97
98 for g in GROUPS:
99 nq[g] = 0
100 nr[g] = 0
101
102 for jid in mcjobdict :
103 thisj = mcjobdict[jid]
104 if thisj['job_state'] == 'queued':
105 nq[thisj['egroup']] += 1
106 elif thisj['job_state'] == 'running':
107 if thisj['wn'] not in runjobdict.keys():
108 runjobdict[thisj['wn']] = dict()
109 if thisj['egroup'] not in runjobdict[thisj['wn']].keys():
110 runjobdict[thisj['wn']][thisj['egroup']] = 0
111 runjobdict[thisj['wn']][thisj['egroup']] += thisj['exec_host'].count('+') + 1
112
113 for n in mcnodes:
114 mcslots += n.numCpu
115 mcfree += n.freeCpu
116 if n.name in runjobdict:
117 for gd in runjobdict[n.name]:
118 nr[gd] += runjobdict[n.name][gd]
119
120 rtot = sum(nr.values())
121
122 import rrdtool
123 DATADIR=os.environ['HOME'] + '/ndpfdata/'
124 rrdtool.update(DATADIR+'capacity.mcpool.rrd', 'N:%d' % (mcslots))
125 rrdtool.update(DATADIR+'unused.mcpool.rrd', 'N:%d' % (mcfree))
126 rrdtool.update(DATADIR+'nonmc.running.mcpool.rrd', 'N:%d' % (mcslots - mcfree - rtot))
127
128 for g in nr:
129 rrdtool.update(DATADIR+'%s.running.mcpool.rrd' % g, 'N:%d' % (nr[g]))
130 rrdtool.update(DATADIR+'%s.queued.mcpool.rrd' % g, 'N:%d' % (nq[g]))

Properties

Name Value
svn:executable *

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28