source: trunk/examples/rack_pbsmon.py @ 329

Last change on this file since 329 was 134, checked in by bas, 18 years ago

examples/pbsmon.py, examples/rack_pbsmon.py, examples/set_property.py:

Replaced:

pbs.pbs_geterrmsg(con)

by:

errno, text = pbs.error()
print errno, text

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