Skip to content

Commit 7c51c0e

Browse files
committed
Added metric tree functionality and fixed some issues around metric list/get
1 parent 9ba7f5d commit 7c51c0e

File tree

6 files changed

+169
-16
lines changed

6 files changed

+169
-16
lines changed

adc.sh

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,12 @@ Initialize the adc configuration file
184184
EOF
185185
function _help {
186186
if [ "$1" = "" ] ; then
187-
COMMAND_RESULT="Usage: $SCRIPTNAME [-H <controller-host>] [-C <controller-credentials>] [-D <output-verbosity>] [-P <plugin-directory>] <namespace> <command>\n"
187+
COMMAND_RESULT="Usage: $SCRIPTNAME [-H <controller-host>] [-C <controller-credentials>] [-D <output-verbosity>] [-P <plugin-directory>] [-A <application-name>] <namespace> <command>\n"
188188
COMMAND_RESULT="${COMMAND_RESULT}\nYou can use the following options on a global level:\n"
189189
COMMAND_RESULT="${COMMAND_RESULT}\t-H <controller-host>\t\t specify the host of the controller you want to connect to\n"
190190
COMMAND_RESULT="${COMMAND_RESULT}\t-C <controller-credentials>\t provide the credentials for the controller. Format: user@tenant:password\n"
191191
COMMAND_RESULT="${COMMAND_RESULT}\t-D <output-verbosity>\t\t Change the output verbosity. Provide a list of the following values: debug,error,warn,info,output\n"
192+
COMMAND_RESULT="${COMMAND_RESULT}\t-D <application-name>\t\t Provide a default application"
192193
COMMAND_RESULT="${COMMAND_RESULT}\nTo execute a action, provide a namespace and a command, e.g. \"metrics get\" to get a specific metric.\nFinally the following commands in the global namespace can be called directly:\n"
193194
local NAMESPACE=""
194195
local SORTED
@@ -424,12 +425,25 @@ describe application_list << EOF
424425
List all applications available on the controller. This command requires no further arguments.
425426
EOF
426427
function metric_list {
427-
local APPLICATION=$*
428-
controller_call /controller/rest/applications/${APPLICATION}/metrics
428+
local APPLICATION=${CONFIG_CONTROLLER_DEFAULT_APPLICATION}
429+
local METRIC_PATH=""
430+
while getopts "a:" opt "$@";
431+
do
432+
case "${opt}" in
433+
a)
434+
APPLICATION=${OPTARG}
435+
;;
436+
esac
437+
done;
438+
shiftOptInd
439+
shift $SHIFTS
440+
METRIC_PATH=`urlencode "$*"`
441+
debug "Will call /controller/rest/applications/${APPLICATION}/metrics?output=JSON\&metric-path=${METRIC_PATH}"
442+
controller_call /controller/rest/applications/${APPLICATION}/metrics?output=JSON\&metric-path=${METRIC_PATH}
429443
}
430-
register metric_list List all metrics available for one application
444+
register metric_list List metrics available for one application.
431445
describe metric_list << EOF
432-
List all metrics available for one application
446+
List all metrics available for one application (-a). Provide a metric path like "Overall Application Performance" to walk the metrics tree.
433447
EOF
434448
function metric_get {
435449
local APPLICATION=${CONFIG_CONTROLLER_DEFAULT_APPLICATION}
@@ -464,7 +478,64 @@ function metric_get {
464478
}
465479
register metric_get Get a specific metric
466480
describe metric_get << EOF
467-
Get a specific metric
481+
Get a specific metric by providing the metric path. Provide the application with option -a
482+
EOF
483+
RECURSIVE_COMMAND_RESULT=""
484+
function metric_tree {
485+
local APPLICATION=${CONFIG_CONTROLLER_DEFAULT_APPLICATION}
486+
local DEPTH=0
487+
declare -i DEPTH
488+
local METRIC_PATH
489+
local ROOT
490+
local TABS=""
491+
while getopts "a:d:t:" opt "$@";
492+
do
493+
case "${opt}" in
494+
a)
495+
APPLICATION=${OPTARG}
496+
;;
497+
d)
498+
DEPTH=${OPTARG}
499+
;;
500+
t)
501+
TABS=${OPTARG}
502+
;;
503+
esac
504+
done;
505+
shiftOptInd
506+
shift $SHIFTS
507+
METRIC_PATH="$*"
508+
metric_list -a $APPLICATION $METRIC_PATH
509+
debug $COMMAND_RESULT
510+
ROOT=$COMMAND_RESULT
511+
COMMAND_RESULT=""
512+
OLDIFS=$IFS
513+
IFS=$'\n,{'
514+
for I in $ROOT ; do
515+
case "$I" in
516+
*name*)
517+
name=${I##*:}
518+
;;
519+
*type*)
520+
type=${I##*:}
521+
;;
522+
*\}*)
523+
name=${name:2}
524+
RECURSIVE_COMMAND_RESULT="${RECURSIVE_COMMAND_RESULT}${TABS}${name%\"}\n"
525+
if [[ "$type" == *folder* ]] ; then
526+
local SUB_PATH="${METRIC_PATH}|${name%\"}"
527+
metric_tree -d ${DEPTH}+1 -t "${TABS} " -a $APPLICATION ${SUB_PATH#"|"}
528+
fi
529+
esac
530+
done;
531+
IFS=$OLDIFS
532+
if [ $DEPTH -eq 0 ] ; then
533+
echo -e $RECURSIVE_COMMAND_RESULT
534+
fi
535+
}
536+
register metric_tree Build and return a metrics tree for one application
537+
describe metric_tree << EOF
538+
Create a metric tree for the given application (-a). Note that this will create a lot of requests towards your controller.
468539
EOF
469540
function dbmon_create {
470541
local DB_USER=""
@@ -688,8 +759,8 @@ do
688759
debug "Set CONFIG_OUTPUT_VERBOSITY=${CONFIG_OUTPUT_VERBOSITY}"
689760
;;
690761
A)
691-
CONFIG_OUTPUT_VERBOSITY=${OPTARG}
692-
debug "Set CONFIG_OUTPUT_VERBOSITY=${CONFIG_OUTPUT_VERBOSITY}"
762+
CONFIG_CONTROLLER_DEFAULT_APPLICATION=${OPTARG}
763+
debug "Set CONFIG_CONTROLLER_DEFAULT_APPLICATION=${CONFIG_CONTROLLER_DEFAULT_APPLICATION}"
693764
;;
694765
P)
695766
CONFIG_USER_PLUGIN_DIRECTORY=${OPTARG}

commands/help.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
function _help {
44
if [ "$1" = "" ] ; then
5-
COMMAND_RESULT="Usage: $SCRIPTNAME [-H <controller-host>] [-C <controller-credentials>] [-D <output-verbosity>] [-P <plugin-directory>] <namespace> <command>\n"
5+
COMMAND_RESULT="Usage: $SCRIPTNAME [-H <controller-host>] [-C <controller-credentials>] [-D <output-verbosity>] [-P <plugin-directory>] [-A <application-name>] <namespace> <command>\n"
66
COMMAND_RESULT="${COMMAND_RESULT}\nYou can use the following options on a global level:\n"
77
COMMAND_RESULT="${COMMAND_RESULT}\t-H <controller-host>\t\t specify the host of the controller you want to connect to\n"
88
COMMAND_RESULT="${COMMAND_RESULT}\t-C <controller-credentials>\t provide the credentials for the controller. Format: user@tenant:password\n"
99
COMMAND_RESULT="${COMMAND_RESULT}\t-D <output-verbosity>\t\t Change the output verbosity. Provide a list of the following values: debug,error,warn,info,output\n"
10+
COMMAND_RESULT="${COMMAND_RESULT}\t-D <application-name>\t\t Provide a default application"
1011
COMMAND_RESULT="${COMMAND_RESULT}\nTo execute a action, provide a namespace and a command, e.g. \"metrics get\" to get a specific metric.\nFinally the following commands in the global namespace can be called directly:\n"
1112
local NAMESPACE=""
1213
local SORTED

commands/metric/get.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ function metric_get {
3434

3535
register metric_get Get a specific metric
3636
describe metric_get << EOF
37-
Get a specific metric
37+
Get a specific metric by providing the metric path. Provide the application with option -a
3838
EOF

commands/metric/list.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
#!/bin/bash
22

33
function metric_list {
4-
local APPLICATION=$*
5-
controller_call /controller/rest/applications/${APPLICATION}/metrics
4+
local APPLICATION=${CONFIG_CONTROLLER_DEFAULT_APPLICATION}
5+
local METRIC_PATH=""
6+
while getopts "a:" opt "$@";
7+
do
8+
case "${opt}" in
9+
a)
10+
APPLICATION=${OPTARG}
11+
;;
12+
esac
13+
done;
14+
shiftOptInd
15+
shift $SHIFTS
16+
METRIC_PATH=`urlencode "$*"`
17+
debug "Will call /controller/rest/applications/${APPLICATION}/metrics?output=JSON\&metric-path=${METRIC_PATH}"
18+
controller_call /controller/rest/applications/${APPLICATION}/metrics?output=JSON\&metric-path=${METRIC_PATH}
619
}
720

8-
register metric_list List all metrics available for one application
21+
register metric_list List metrics available for one application.
922
describe metric_list << EOF
10-
List all metrics available for one application
23+
List all metrics available for one application (-a). Provide a metric path like "Overall Application Performance" to walk the metrics tree.
1124
EOF

commands/metric/tree.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
RECURSIVE_COMMAND_RESULT=""
4+
5+
function metric_tree {
6+
local APPLICATION=${CONFIG_CONTROLLER_DEFAULT_APPLICATION}
7+
local DEPTH=0
8+
declare -i DEPTH
9+
local METRIC_PATH
10+
local ROOT
11+
local TABS=""
12+
while getopts "a:d:t:" opt "$@";
13+
do
14+
case "${opt}" in
15+
a)
16+
APPLICATION=${OPTARG}
17+
;;
18+
d)
19+
DEPTH=${OPTARG}
20+
;;
21+
t)
22+
TABS=${OPTARG}
23+
;;
24+
esac
25+
done;
26+
shiftOptInd
27+
shift $SHIFTS
28+
METRIC_PATH="$*"
29+
30+
metric_list -a $APPLICATION $METRIC_PATH
31+
32+
debug $COMMAND_RESULT
33+
34+
ROOT=$COMMAND_RESULT
35+
36+
COMMAND_RESULT=""
37+
38+
OLDIFS=$IFS
39+
IFS=$'\n,{'
40+
for I in $ROOT ; do
41+
case "$I" in
42+
*name*)
43+
name=${I##*:}
44+
;;
45+
*type*)
46+
type=${I##*:}
47+
;;
48+
*\}*)
49+
name=${name:2}
50+
RECURSIVE_COMMAND_RESULT="${RECURSIVE_COMMAND_RESULT}${TABS}${name%\"}\n"
51+
if [[ "$type" == *folder* ]] ; then
52+
local SUB_PATH="${METRIC_PATH}|${name%\"}"
53+
metric_tree -d ${DEPTH}+1 -t "${TABS} " -a $APPLICATION ${SUB_PATH#"|"}
54+
fi
55+
esac
56+
done;
57+
IFS=$OLDIFS
58+
59+
if [ $DEPTH -eq 0 ] ; then
60+
echo -e $RECURSIVE_COMMAND_RESULT
61+
fi
62+
}
63+
64+
register metric_tree Build and return a metrics tree for one application
65+
describe metric_tree << EOF
66+
Create a metric tree for the given application (-a). Note that this will create a lot of requests towards your controller.
67+
EOF

main.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ source ./commands/application/list.sh
5555

5656
source ./commands/metric/list.sh
5757
source ./commands/metric/get.sh
58+
source ./commands/metric/tree.sh
5859

5960
source ./commands/dbmon/create.sh
6061

@@ -104,8 +105,8 @@ do
104105
debug "Set CONFIG_OUTPUT_VERBOSITY=${CONFIG_OUTPUT_VERBOSITY}"
105106
;;
106107
A)
107-
CONFIG_OUTPUT_VERBOSITY=${OPTARG}
108-
debug "Set CONFIG_OUTPUT_VERBOSITY=${CONFIG_OUTPUT_VERBOSITY}"
108+
CONFIG_CONTROLLER_DEFAULT_APPLICATION=${OPTARG}
109+
debug "Set CONFIG_CONTROLLER_DEFAULT_APPLICATION=${CONFIG_CONTROLLER_DEFAULT_APPLICATION}"
109110
;;
110111
P)
111112
CONFIG_USER_PLUGIN_DIRECTORY=${OPTARG}

0 commit comments

Comments
 (0)