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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3328 - (hide annotations) (download)
Tue Mar 30 09:03:58 2021 UTC (13 months, 2 weeks ago) by templon
File size: 3717 byte(s)
various commits


1 templon 2701 #!/usr/bin/env python
2     from torque_utils import pbsnodes
3    
4     import os
5 templon 3146 # 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 templon 2701 import sys
11     import subprocess
12    
13 templon 3328 GROUPS = ['atlb', 'atlaspil', 'ligo', 'datagrid', 'dune', 'virgo',
14     'pvier', 'lsgrid', 'pbbmri', 'atlsgm']
15 templon 3260 MCQUEUE = 'atlasmc7'
16 templon 3060 TORQUE = "korf.nikhef.nl"
17 templon 2702
18 templon 3060 import pickle
19    
20 templon 3147 # pkl_file = open('/data/tunnel/user/templon/wnodes-korf.pkl', 'rb')
21     # wnodes_k = pickle.load(pkl_file )
22     # pkl_file.close()
23 templon 3060
24 templon 3147 # wnodes = wnodes_k
25 templon 3060
26 templon 3147 wnodes = pbsnodes()
27    
28 templon 2701 mcnodes = list()
29    
30     for node in wnodes:
31     if \
32     'mc' in node.properties \
33 templon 3261 and 'el7' not in node.properties \
34 templon 2701 and node.state.count('offline') == 0:
35     mcnodes.append(node)
36    
37     mcslots = 0
38     mcfree = 0
39     mcrun = 0
40    
41 templon 2702 usedkeys = ['egroup', 'jobid', 'queue', 'job_state', 'euser', 'exec_host' ]
42 templon 2701
43 templon 2702 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 templon 3060 # 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 templon 2702 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 templon 2701 for n in mcnodes:
114     mcslots += n.numCpu
115     mcfree += n.freeCpu
116 templon 2702 if n.name in runjobdict:
117     for gd in runjobdict[n.name]:
118     nr[gd] += runjobdict[n.name][gd]
119 templon 2701
120 templon 2702 rtot = sum(nr.values())
121    
122 templon 2701 import rrdtool
123     DATADIR=os.environ['HOME'] + '/ndpfdata/'
124 templon 2702 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 templon 2701
128 templon 2702 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