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