Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / sge / sge_queue_xml_ @ 17f78427

Historique | Voir | Annoter | Télécharger (4,37 ko)

1
#!/bin/bash
2
#
3
# Wildcard-plugin to monitor Grid Engine queue state.
4
# To monitor a queue, link sge_queue_xml_<queue> to this file. E.g.
5
#
6
#   ln -s /usr/share/munin/plugins/sge_queue_xml_ /etc/munin/plugins/sge_queue_xml_all.q
7
#
8
# inspired by the sge_queue_ plugin committed by steveschnepp
9
#
10
# Runs 'qstat -g c -xml' for the specified queue and gets the number of
11
# used, reserved, unavailable, available and total queue slots.
12
# Unavailable slots have queue states Disabled/Suspended/Error/Ambiguous config/Unknown
13
#
14
# Parameters understood:
15
#
16
#   config   (required)
17
#   autoconf (optional - used by munin-config)
18
#   suggest  (optional - used by munin-config)
19
#
20
# Configurable variables:
21
#
22
#   env.sge_settings - Path to SGE settings.sh script, defaults to /opt/sge/default/common/settings.sh
23
#   env.title        - Graph title, overrides "SGE Queue state".
24
#   env.options      - Additional command line options to qstat.
25
#   env.queues       - list of queues to summarize
26
#
27
# Revisions:
28
#   v1.0 2013-10-14
29
#
30
# Magic markers
31
#%# family=contrib
32
#%# capabilities=autoconf suggest
33

    
34
# env.sge_settings -- alternatively you can just modify the path below
35
SGE_SETTINGS=${sge_settings:-/opt/sge/default/common/settings.sh}
36

    
37

    
38
# queues to monitor
39
# priority 1: queue name in symlink
40
QUEUE=${0##*_}
41
# priority 2: queue names from environment
42
QUEUE=${QUEUE:-$queues}
43
# priority 3: summary of all GridEngine Queues
44
QUEUE=${QUEUE:-"Summary"}
45

    
46
# env.title
47
GRAPHTITLE=${title:-"GridEngine Queue state (${QUEUE})"}
48

    
49
# env.options
50
OPTIONS="-g c -xml $options"
51

    
52
if [ "$1" = "config" ]; then
53
    echo "graph_title "$GRAPHTITLE""
54
    echo "graph_order total used reserved unavailable available"
55
    echo "graph_args --lower-limit 0 "
56
    echo "graph_vlabel Queue slots"
57
    echo "graph_scale no"
58
    echo "graph_info Shows global Grid Engine queue state."
59
    echo "graph_category htc"
60
    echo "graph_period minute"
61
    echo "used.label Used"
62
    echo "used.draw AREA"
63
    echo "used.type GAUGE"
64
    echo "used.info Currently used slots."
65
    echo "unavailable.label Unavailable"
66
    echo "unavailable.draw LINE1"
67
    echo "unavailable.type GAUGE"
68
    echo "unavailable.info Queue state Disabled/Suspended/Error/Ambiguous config/Unknown."
69
    echo "reserved.label Reserved"
70
    echo "reserved.draw LINE1"
71
    echo "reserved.type GAUGE"
72
    echo "reserved.info Reserved slots."
73
    echo "available.label Available"
74
    echo "available.draw LINE1"
75
    echo "available.type GAUGE"
76
    echo "available.info Available slots."
77
    echo "total.label Total"
78
    echo "total.draw AREA"
79
    echo "total.type GAUGE"
80
    echo "total.info Total slots."
81
    exit 0
82
fi
83

    
84
# source settings script, needed for qstat
85
if [ -f "$SGE_SETTINGS" ]; then
86
    source "$SGE_SETTINGS"
87
fi
88
QSTAT=$( which qstat )
89
XMLSTARLET=$( which xmlstarlet )
90

    
91
if [ "$1" = "autoconf" ]; then
92
    if [ -n "$QSTAT" -a -n "$XMLSTARLET" ]; then
93
        echo "yes"
94
        exit 0
95
    else
96
        echo "no"
97
        exit 1
98
    fi
99
fi
100

    
101
# check requirements
102
[ -z "$QSTAT" ] && { echo "qstat not found" 1>&2 ; exit 1; }
103
[ -z "$XMLSTARLET" ] && { echo "xmlstarlet not found" 1>&2  ; exit 1; }
104

    
105
ALL_QUEUES=$( $QSTAT -g c -xml | $XMLSTARLET sel -T -t -m "//cluster_queue_summary/name" -v "node()" -o "," )
106
[ "$QUEUE" == "Summary" ] && QUEUE="$ALL_QUEUES"
107

    
108
if [ "$1" = "suggest" ]; then
109
    /bin/echo -en "${ALL_QUEUES//,/\n}"
110
    exit 0
111
fi
112

    
113
xmldemangle() {
114
# _SGE_XML hash array to store values
115
# _SGE_OUT xml output of qstat
116
# _SGE_ENTITY entity to read values from (optional)
117

    
118
	[ -z "$_SGE_OUT" ] && return 1
119

    
120
	local ENTITY=${_SGE_ENTITY:-"cluster_queue_summary"}
121

    
122
	local IFSBAK=$IFS;IFS=$
123
	for node in $( echo "$_SGE_OUT" | $XMLSTARLET sel -T -t -m "//${ENTITY}/*" -o "_SGE_XML[" -v "name()" -o ']=' -v "node()"  -n )
124
	do
125
		eval $node
126
	done
127
	IFS=$IFSBAK
128
}
129

    
130
printvalues() {
131
	local IFSBAK=$IFS; unset IFS
132
	for i in ${!_SGE_QUEUE_KEYS[@]}
133
	do
134
		echo "${_SGE_QUEUE_KEYS[$i]}.value ${_SGE_QUEUE_VALUES[$i]}"
135
	done
136
	IFS=$IFSBAK
137
}
138

    
139
declare -A _SGE_XML
140
declare -A _SGE_QUEUE_VALUES
141
declare -A _SGE_QUEUE_KEYS
142
_SGE_QUEUE_KEYS=(
143
[used]="used"
144
[resv]="reserved"
145
[manual_intervention]="unavailable"
146
[available]="available"
147
[total]="total"
148
)
149

    
150
for qu in $( /bin/echo -e "${QUEUE//,/\n}" )
151
do
152
	_SGE_OUT=$( "$QSTAT" $OPTIONS -q $qu )
153
	xmldemangle || echo "Error on QUEUE: $qu" 1>&2
154

    
155
	for i in ${!_SGE_QUEUE_KEYS[@]}
156
	do
157
		_SGE_QUEUE_VALUES[$i]=${_SGE_QUEUE_VALUES[$i]:-0}
158
		let "_SGE_QUEUE_VALUES[$i] += ${_SGE_XML[$i]:-0}"
159
	done
160
done
161

    
162
printvalues
163

    
164
exit 0