source: trunk/pbs_swig/distro/examples/rack_pbsmon.py @ 63

Last change on this file since 63 was 63, checked in by bas, 20 years ago

Deleted obsolete directories:

  • 2.1
  • dist
  • 1.5

Added:

  • Walters rack_pbsmon.py
  • Changed pbsmon.py
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1#! /usr/bin/env python
2#
3#       pbsmon  WJ104
4#
5#       Hint: set ts=4
6#
7# SVN INFO:
8#       $Id: rack_pbsmon.py 63 2004-10-21 12:11:30Z bas $
9
10import os
11import sys
12import string
13
14import pbs
15
16
17NODES_PER_RACK = 19
18N_RACKS = 15
19
20PBS_STATES = {
21        pbs.ND_free                             : '_',
22        pbs.ND_down                             : 'X',
23        pbs.ND_offline                  : '.',
24        pbs.ND_reserve                  : 'R',
25        pbs.ND_job_exclusive    : 'J',
26        pbs.ND_job_sharing              : 'S',
27        pbs.ND_busy                             : '*',
28        pbs.ND_state_unknown    : '?',
29        pbs.ND_timeshared               : 'T',
30        pbs.ND_cluster                  : 'C'
31}
32
33PBS_STATE_JOB_BUT_FREE = 'j'
34
35
36def pbsmon():
37        global NODES_PER_RACK, N_RACKS, PBS_STATES, PBS_STATE_JOB_BUT_FREE
38
39        if len(sys.argv) > 1:
40                pbs_server = sys.argv[1]
41        else:
42                pbs_server = pbs.pbs_default()
43                if not pbs_server:
44                        print 'No default pbs server, usage: %s [server]' % os.path.basename(sys.argv[0])
45                        sys.exit(1)
46
47        con = pbs.pbs_connect(pbs_server)
48        if con < 0:
49                print pbs.pbs_geterrmsg(con)
50                sys.exit(1)
51
52# get the state of the nodes
53        attrl = pbs.new_attrl(2)
54        attrl[0].name = 'state'
55        attrl[1].name = 'jobs'
56        nodes = pbs.pbs_statnode(con, '', attrl, 'NULL')
57
58        node_dict = {}
59
60        count_states = {}
61        for key in PBS_STATES.keys():
62                count_states[key] = 0
63
64        for node in nodes:
65                node_attr = node.attribs
66                temp = string.split(node_attr[0].value, ',')
67                state = temp[0]
68                state_char = PBS_STATES[state]
69                count_states[state] = count_states[state] + 1
70
71                if state == pbs.ND_free:
72                        if len(node_attr) > 1:
73#                               print 'TD: %s' % node.name, node_attr[1]
74                                state_char = PBS_STATE_JOB_BUT_FREE
75                                count_states[pbs.ND_free] = count_states[pbs.ND_free] - 1
76                                count_states[pbs.ND_job_exclusive] = count_states[pbs.ND_job_exclusive] + 1
77
78#               print 'TD: %s %s' % (node.name, state_char)
79                node_dict[node.name] = state_char
80
81        legend = PBS_STATES.keys()
82        legend.sort()
83
84# print nodes with gb-r%dn%d naming scheme
85        print '  ',
86        for rack in xrange(1, N_RACKS+1):
87                print '%2d' % rack,
88        print
89
90        for node_nr in xrange(1, NODES_PER_RACK+1):
91                print '%2d' % node_nr,
92
93                for rack in xrange(1, N_RACKS+1):
94                        node_name = 'gb-r%dn%d' % (rack, node_nr)
95
96                        if node_dict.has_key(node_name):
97                                print ' %s' % node_dict[node_name],
98
99                                del node_dict[node_name]
100                        else:
101                                print '  ',
102
103                if node_nr-1 < len(legend):
104                        state = legend[node_nr-1]
105                        print %s  %-13s : %d' % (PBS_STATES[state], state, count_states[state])
106                else:
107                        print
108
109        print
110
111# any other nodes?
112        arr = node_dict.keys()
113        if arr:
114                arr.sort()
115
116                for node in arr:
117                        print '%s %s' % (node, node_dict[node])
118
119                print
120
121#       n = 0
122#       for state in legend:
123#               print '%s  %-13s : %-3d     ' % (PBS_STATES[state], state, count_states[state]),
124#               n = n + 1
125#               if n > 1:
126#                       n = 0
127#                       print
128
129
130if __name__ == '__main__':
131        pbsmon()
132
133
134# EOB
135
Note: See TracBrowser for help on using the repository browser.