rrd_graph_all.sh 10.4 KB
Newer Older
's avatar
 
committed
1
#!/bin/bash
's avatar
committed
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
#
# Copyright (c) 2006, CESNET
# All rights reserved.
#
# LICENSE TERMS
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of the company nor the names of its contributors 
#       may be used to endorse or promote products derived from this 
#       software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
# THE COMPANY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# 
# $Id$
#
's avatar
 
committed
33
34
35
36

ABW_DIR=/usr/local/abw
RRD_DIR=/usr/local/abw/rrd
GRAPH_DIR=/usr/local/abw/graph
37
38
39
ABW_INFO_COMMAND=${ABW_DIR}/bin/abw_info
ABW_CONF=${ABW_DIR}/etc/abw.cfg

's avatar
committed
40
41
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

42
43
44
45
46
47
usage() {
	echo "Usage: $0 [ -r ] \\"
	echo "   --protocols={l4|apps} \\"
	echo "   --subject_id=<subject_id>\\"
	echo "	--label=<label>\\"
	echo "   --parameters_id=<parameters_id>\\"
48
	echo "   --time=\"resolution1 resolution2 length hhmm YYYYMMDD\""
49
50
51
52
53
54
55
56
	echo "   -r            - remove old graphs before generating new graphs"
	echo "   l4            - generate graphs for L4 protocols"
	echo "   apps          - generate graphs for application protocols"
	echo "   subject_id    - id in [subject] section in abw configuration file"
	echo "   label         - label in [subject] secion in abw configuration file"
	echo "   parameters_id - id in [parameters] section in abw configuration file"
	echo "   resolution1 resolution2	- plot averages over these periods"
	echo "   length        - start time is end time minus this length"
57
	echo "   hh:mm YYYYMMDD - end time"
58
59
60
61
	echo ""
	echo "Example: $0 -r \\"
	echo "   --protocols=l4 \\"
	echo "   --subject_id=1 --label=PoP_Prague --parameters_id=1 --parameters_id=2\\"
62
	echo "   --time=\"1 60 10min 14:20 20060617\" --time=\"10 600 5h 09:20 20060617\""
63
}
64
# end of usage()
's avatar
 
committed
65

66
if [ $# -lt 1 ]; then
67
	usage
68
69
70
71
72
73
74
75
76
	exit -1
fi

if [ $1 = "-r" ]; then
	REMOVE_OLD=1
	shift
else
	REMOVE_OLD=0
fi
's avatar
 
committed
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
######################
### Read arguments ###
######################

SUBJECT_LABEL_NO=0
PARAMETERS_NO=0
TIME_NO=0

while [ $# -gt 0 ]; do

	if [ "${1:0:12}" = "--protocols=" ]; then
		if [ "x$GRAPH_TYPE" != "x" ]; then
			echo "--protocols can be specified only once"
			usage
			exit -1
		fi
		GRAPH_TYPE=${1:12}

	elif [ "${1:0:13}" = "--subject_id=" ]; then
		SUBJECT_ID[$SUBJECT_LABEL]=${1:13}
		LABEL[$SUBJECT_LABEL]=""
		SUBJECT_LABEL_NO=`expr $SUBJECT_LABEL_NO + 1`

	elif [ "${1:0:8}" = "--label=" ]; then
		SUBJECT_ID[$SUBJECT_LABEL]=0
		LABEL[$SUBJECT_LABEL]=${1:8}
		SUBJECT_LABEL_NO=`expr $SUBJECT_LABEL_NO + 1`

	elif [ "${1:0:16}" = "--parameters_id=" ]; then
		PARAMETERS_ID[$PARAMETERS_NO]=${1:16}
		PARAMETERS_NO=`expr $PARAMETERS_NO + 1`

	elif [ "${1:0:7}" = "--time=" ]; then
		TIME[$TIME_NO]=${1:7}
		TIME_NO=`expr $TIME_NO + 1`

	else
		echo "Unknown argument $1"
		usage
		exit -1
	fi
	shift
done

#######################
### Check arguments ###
#######################

if [ "x$GRAPH_TYPE" = "x" ]; then
	echo "You must specify --protocols argument"
	exit -1
fi
's avatar
 
committed
130

131
132
if [ $GRAPH_TYPE != "l4" -a $GRAPH_TYPE != "apps" ]; then
   echo "Unknown graph type (only l4 and apps are supported)"
133
	usage
134
135
   exit -1
fi
's avatar
 
committed
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

if [ $PARAMETERS_NO -gt 0 ]; then
	if [ $SUBJECT_LABEL_NO -ne $PARAMETERS_NO ]; then
		echo "The number of --subject_id and --label arguments must be the same as the number of --parameters_id arguments"
		exit -1
	fi
fi

if [ $SUBJECT_LABEL_NO -eq 0 ]; then
	echo "You must specify at least one --subject or label argument and one --parameters argument"
	exit -1
fi

if [ $TIME_NO -eq 0 ]; then
	echo "You must specify at least one --time argument"
	exit -1
fi

#############################################################
### Determine what script will be used to generate graphs ###
#############################################################

159
160
GRAPH_SCRIPT=${ABW_DIR}/bin/rrd_graph_${GRAPH_TYPE}.sh

161
162
163
######################################
### Print arguments just for check ###
######################################
164

165
166
167
168
169
for (( I=0 ; $I<$SUBJECT_LABEL_NO ; I++ )) ; do
	echo "SUBJECT_ID[$I]: ${SUBJECT_ID[$I]}"
	echo "LABEL[$I]: ${LABEL[$I]}"
	echo "PARAMETERS_ID[$I]: ${PARAMETERS_ID[$I]}"
done
's avatar
 
committed
170

171
172
173
174
175
176
177
for (( I=0 ; $I<$TIME_NO ; I++ )) ; do
	echo "TIME[$I]: ${TIME[$I]}"
done

#########################
### Remove old graphs ###
#########################
178
179
180
181
182

if [ $REMOVE_OLD -gt 0 ]; then
	rm -f $GRAPH_DIR/graph*
fi

183
184
185
186
187
188
189
190
#####################################################
### Go over all --subject_id or --label arguments ###
#####################################################

for (( I=0 ; $I<$SUBJECT_LABEL_NO ; I++ )) ; do
	echo -n "Generating graphs for subject_id/label"
	echo " ${SUBJECT_ID[$I]}/${LABEL[$I]} and parameters_id ${PARAMETERS_ID[$I]}"

's avatar
committed
191
192
193
194
   ############################################################################
	### If --subject_id was specified (not --label), then a single graph for ###
	### one direction of traffic will be generated                           ###
   ############################################################################
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231

	if [ ${SUBJECT_ID[$I]} -gt 0 ]; then

		COMMAND="${ABW_INFO_COMMAND} -f $ABW_CONF --subject_id ${SUBJECT_ID[$I]}"
		if [ ${PARAMETERS_NO} -gt 0 ]; then
			COMMAND="$COMMAND --parameters_id=${PARAMETERS_ID[$I]}"
		fi
		MEASUREMENT_ARRAY=(`$COMMAND`)

		if [ ${MEASUREMENT_ARRAY[0]} = "unknown" ]; then
			echo "Unknown subject_id or parameters_id"
			exit -1
		fi

		HOSTNAME=${MEASUREMENT_ARRAY[0]}
		INTERFACE=${MEASUREMENT_ARRAY[1]}
		PREFIX=${MEASUREMENT_ARRAY[2]}
		LABEL=${MEASUREMENT_ARRAY[3]}

		DESCRIPTION=${MEASUREMENT_ARRAY[4]}
		J=5
		END=0
		while [ $J -lt ${#MEASUREMENT_ARRAY[*]} -a $END -eq 0 ]; do
			DESCRIPTION="$DESCRIPTION ${MEASUREMENT_ARRAY[$J]}"
			if [ "${MEASUREMENT_ARRAY[$J]: -1}" = "\"" ]; then
				END=1
			fi
			J=`expr $J + 1`
		done
		DESCRIPTION=${DESCRIPTION:1:${#DESCRIPTION}-2}

		echo "HOSTNAME: $HOSTNAME"
		echo "INTERFACE: $INTERFACE"
		echo "PREFIX: $PREFIX"
		echo "LABEL: $LABEL"
		echo "DESCRIPTION: $DESCRIPTION"

's avatar
committed
232
233
234
235
	##########################################################################
	### If --label was specified (not --subject_id), then a dual graph for ###
   ### both directions of traffic will be generated                       ###
	##########################################################################
236
237
238
239
240
241
242

	else

		COMMAND="${ABW_INFO_COMMAND} -f $ABW_CONF --label ${LABEL[$I]} --direction in"
		if [ ${PARAMETERS_NO} -gt 0 ]; then
			COMMAND="$COMMAND --parameters_id=${PARAMETERS_ID[$I]}"
		fi
243
		echo "command: $COMMAND"
244
245
246
247
248
249
		MEASUREMENT_ARRAY_IN=(`$COMMAND`)

		COMMAND="${ABW_INFO_COMMAND} -f $ABW_CONF --label ${LABEL[$I]} --direction out"
		if [ ${PARAMETERS_NO} -gt 0 ]; then
			COMMAND="$COMMAND --parameters_id=${PARAMETERS_ID[$I]}"
		fi
250
		echo "command: $COMMAND"
251
252
		MEASUREMENT_ARRAY_OUT=(`$COMMAND`)

's avatar
committed
253
		if [ ${MEASUREMENT_ARRAY_IN[0]} = "unknown" -a ${MEASUREMENT_ARRAY_OUT[0]} = "unknown" ]; then
254
255
256
257
			echo "Unknown label or parameters_id"
			exit -1
		fi

's avatar
committed
258
259
260
261
		HOSTNAME_IN=${MEASUREMENT_ARRAY_IN[0]}
		INTERFACE_IN=${MEASUREMENT_ARRAY_IN[1]}
		PREFIX_IN=${MEASUREMENT_ARRAY_IN[2]}
		LABEL_IN=${MEASUREMENT_ARRAY_IN[3]}
262

's avatar
committed
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
		HOSTNAME_OUT=${MEASUREMENT_ARRAY_OUT[0]}
		INTERFACE_OUT=${MEASUREMENT_ARRAY_OUT[1]}
		PREFIX_OUT=${MEASUREMENT_ARRAY_OUT[2]}
		LABEL_OUT=${MEASUREMENT_ARRAY_OUT[3]}

		DESCRIPTION_IN=${MEASUREMENT_ARRAY_IN[4]}
		J=5
		END=0
		while [ $J -lt ${#MEASUREMENT_ARRAY_IN[*]} -a $END -eq 0 ]; do
			DESCRIPTION_IN="$DESCRIPTION_IN ${MEASUREMENT_ARRAY_IN[$J]}"
			if [ "${MEASUREMENT_ARRAY_IN[$J]: -1}" = "\"" ]; then
            END=1
         fi
			J=`expr $J + 1`
		done
		DESCRIPTION_IN=${DESCRIPTION_IN:1:${#DESCRIPTION_IN}-2}

		DESCRIPTION_OUT=${MEASUREMENT_ARRAY_OUT[4]}
		J=5
		END=0
		while [ $J -lt ${#MEASUREMENT_ARRAY_OUT[*]} -a $END -eq 0 ]; do
			DESCRIPTION_OUT="$DESCRIPTION_OUT ${MEASUREMENT_ARRAY_OUT[$J]}"
			if [ "${MEASUREMENT_ARRAY_OUT[$J]: -1}" = "\"" ]; then
         	END=1
         fi
			J=`expr $J + 1`
		done
		DESCRIPTION_OUT=${DESCRIPTION_OUT:1:${#DESCRIPTION_OUT}-2}

		echo "HOSTNAME_IN: $HOSTNAME_IN"
		echo "INTERFACE_IN: $INTERFACE_IN"
		echo "PREFIX_IN: $PREFIX_IN"
		echo "LABEL_IN: $LABEL_IN"
		echo "DESCRIPTION_IN: $DESCRIPTION_IN"

		echo "HOSTNAME_OUT: $HOSTNAME_OUT"
		echo "INTERFACE_OUT: $INTERFACE_OUT"
		echo "PREFIX_OUT: $PREFIX_OUT"
		echo "LABEL_OUT: $LABEL_OUT"
		echo "DESCRIPTION_OUT: $DESCRIPTION_OUT"
303

304
	fi
305

306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
	####################################
	### Go over all --time arguments ###
	####################################

	for (( J=0 ; $J<$TIME_NO ; J++ )) ; do
		TIME_ARRAY=(${TIME[$J]})

		R1=${TIME_ARRAY[0]}
		R2=${TIME_ARRAY[1]}
		TIME_LENGTH=${TIME_ARRAY[2]}

		END_TIME=${TIME_ARRAY[3]}
		K=4;
		while [ $K -lt ${#TIME_ARRAY[*]} ]; do
			END_TIME="$END_TIME ${TIME_ARRAY[$K]}"
			K=`expr $K + 1`
		done

		echo "TIME[$J]: ${TIME[$J]}"	
		echo "R1: $R1"
		echo "R2: $R2"
		echo "TIME_LENGTH: $TIME_LENGTH"
		echo "END_TIME: $END_TIME"

330
		COMMAND="${GRAPH_SCRIPT}"
331
332
333
		if [ ${SUBJECT_ID[$I]} -gt 0 ]; then
			COMMAND="$COMMAND ${PREFIX[$I]} \"\""
		else
's avatar
committed
334
			COMMAND="$COMMAND ${PREFIX_IN[$I]} ${PREFIX_OUT[$I]}"
335
		fi
336
		COMMAND="$COMMAND ${GRAPH_DIR}/graph_${LABEL[$I]}_${GRAPH_TYPE}_${R1}s_${R2}s_${TIME_LENGTH}.png end-${TIME_LENGTH} \"${END_TIME}\" ${R1} ${R2}"
337
338
339
		if [ ${SUBJECT_ID[$I]} -gt 0 ]; then
			COMMAND="$COMMAND \"${DESCRIPTION}\""
		else
's avatar
committed
340
			COMMAND="$COMMAND \"${DESCRIPTION_IN}\""
341
342
343
344
345
346
347
348
349
		fi

		echo "COMMAND: $COMMAND"

		###################################
		### Finally, generate one graph ###
		###################################

		eval $COMMAND
350
351

	done
352
353
354
355
	# Go to next --time

done
# Go to next --subject_id or --label