Skip to content

Commit 71e11df

Browse files
committed
functions to parse tasks statistics
1 parent 29ce831 commit 71e11df

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

auxiliary_functions.sh

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,130 @@ function results_are_ok() {
386386
return 0
387387
}
388388

389+
## @fn aggregate_over_list
390+
## @brief Aggregates (summates) value of the specified list
391+
function aggregate_over_list() {
392+
local xml_file=$1
393+
local list_path=$2
394+
local item_name=$3
395+
local value_name=$4
396+
397+
if [ "$xml_file" = "" ]
398+
then
399+
echo "The XML file was not specified"
400+
return 1
401+
fi
402+
403+
if [ "$list_path" = "" ]
404+
then
405+
echo "The list path was not specified"
406+
return 1
407+
fi
408+
409+
if [ "$value_name" = "" ]
410+
then
411+
echo "The value name was not specified"
412+
return 1
413+
fi
414+
415+
local list_size=`xmllint --xpath "string($list_path/@size)" $xml_file`
416+
if [ "$list_size" = "" ]
417+
then
418+
list_size=0
419+
fi
420+
421+
local i_elem=1
422+
local aggr_value=0
423+
local curr_value=0
424+
local value_path=
425+
while [ $i_elem -le $list_size ]
426+
do
427+
value_path="$list_path/$item_name[$i_elem]/$value_name"
428+
curr_value=`xmllint --xpath "string($value_path)" $xml_file`
429+
aggr_value=$(($curr_value + $aggr_value))
430+
i_elem=$(($i_elem + 1))
431+
done
432+
433+
echo $aggr_value
434+
}
435+
436+
## @fn query_task_stats
437+
## @brief gather task stats for a given OpenSDN module
438+
function query_task_stats() {
439+
local module_ip=$1
440+
local module_port=$2
441+
442+
if [ "$module_ip" = "" ]
443+
then
444+
echo "The IP to query was not specified"
445+
return 1
446+
fi
447+
448+
if [ "$module_port" = "" ]
449+
then
450+
echo "The port to query was not specified"
451+
return 1
452+
fi
453+
454+
curl -s -o t_task_state.xml http://$module_ip:$module_port/Snh_SandeshTaskSummaryRequest?
455+
#local n_tasks=`xmllint --xpath "string(//task_group_list[name='$vrf_name']/ucindex)" t_vrfs.xml`
456+
457+
local n_tasks=`xmllint --xpath "string(//task_group_list/list/@size)" t_task_state.xml`
458+
if [ "$n_tasks" = "" ]
459+
then
460+
n_tasks=0
461+
fi
462+
463+
local i_task=1 # indices are 1-based
464+
local tasks_created=
465+
local tasks_completed=
466+
local tasks_running=
467+
local waitq_size=
468+
local deferq_size=
469+
echo "i task tasks_created tasks_completed tasks_running waitq_size deferq_size"
470+
while [ $i_task -le $n_tasks ]
471+
do
472+
local task_name=`xmllint --xpath "string(//task_group_list/list/SandeshTaskGroup[$i_task]/name)" t_task_state.xml`
473+
tasks_created=`\
474+
aggregate_over_list \
475+
t_task_state.xml \
476+
"//task_group_list/list/SandeshTaskGroup[$i_task]/task_entry_list/list" \
477+
"SandeshTaskEntry" \
478+
"tasks_created"`
479+
480+
tasks_completed=`\
481+
aggregate_over_list \
482+
t_task_state.xml \
483+
"//task_group_list/list/SandeshTaskGroup[$i_task]/task_entry_list/list" \
484+
"SandeshTaskEntry" \
485+
"tasks_completed"`
486+
487+
tasks_running=`\
488+
aggregate_over_list \
489+
t_task_state.xml \
490+
"//task_group_list/list/SandeshTaskGroup[$i_task]/task_entry_list/list" \
491+
"SandeshTaskEntry" \
492+
"tasks_running"`
493+
494+
waitq_size=`\
495+
aggregate_over_list \
496+
t_task_state.xml \
497+
"//task_group_list/list/SandeshTaskGroup[$i_task]/task_entry_list/list" \
498+
"SandeshTaskEntry" \
499+
"waitq_size"`
500+
501+
deferq_size=`\
502+
aggregate_over_list \
503+
t_task_state.xml \
504+
"//task_group_list/list/SandeshTaskGroup[$i_task]/task_entry_list/list" \
505+
"SandeshTaskEntry" \
506+
"deferq_size"`
507+
508+
echo "$i_task $task_name $tasks_created $tasks_completed $tasks_running $waitq_size $deferq_size"
509+
i_task=$(($i_task + 1))
510+
done
511+
}
512+
389513
export AUXILIARY_FUNCTIONS=
390514

391515
#

0 commit comments

Comments
 (0)