@@ -85,7 +85,7 @@ case "$1" in
8585 ;;
8686 * )
8787 shift # remove first argument
88- options=( " $@ " )
88+ options=(" $@ " )
8989 # run flows command
9090 command=" flows"
9191 ;;
@@ -99,7 +99,7 @@ case "$1" in
9999 ;;
100100 * )
101101 shift # remove first argument
102- options=( " $@ " )
102+ options=(" $@ " )
103103 # run packets command
104104 command=" packets"
105105 ;;
@@ -113,9 +113,11 @@ case "$1" in
113113 ;;
114114 * )
115115 shift # remove first argument
116- options=( " $@ " )
116+ options=(" $@ " )
117117 # run metrics command
118118 command=" metrics"
119+ # override maxTime default to 1h for metrics only
120+ maxTime=" 1h"
119121 ;;
120122 esac
121123 ;;
@@ -181,15 +183,15 @@ trap cleanup EXIT
181183
182184setup
183185
184- if [[ " $command " == " flows" || " $command " == " packets" ]]; then
186+ if [[ " $command " == " flows" || " $command " == " packets" || " $command " == " metrics " ]]; then
185187 # convert options to string
186188 optionStr=" ${options// --/ } "
187189 optionStr=" ${optionStr// / |} "
188190
189191 # prepare commands & args
190192 runCommand=" sleep infinity"
191193 execCommand=" /network-observability-cli get-$command ${optionStr: +" --options" " ${optionStr} " } --loglevel $logLevel --maxtime $maxTime --maxbytes $maxBytes "
192- if [[ " $runBackground " == " true" || " $outputYAML " == " true" ]]; then
194+ if [[ " $runBackground " == " true" || " $outputYAML " == " true" || " $command " == " metrics " ]]; then
193195 runCommand=" bash -c \" $execCommand && $runCommand \" "
194196 execCommand=" "
195197 fi
@@ -199,18 +201,29 @@ if [[ "$command" == "flows" || "$command" == "packets" ]]; then
199201 --command -- $runCommand "
200202
201203 if [[ " $outputYAML " == " true" ]]; then
202- echo " Check the generated YAML file in output folder."
203- echo
204- echo " You can create $command agents by executing:"
205- echo " ${K8S_CLI_BIN} apply -f ./output/${command} _capture_${dateName} .yml"
206- echo
207- echo " Then create the collector using:"
208- echo -e " $cmd "
209- echo
210- echo " And follow its progression with:"
211- echo " ${K8S_CLI_BIN} logs collector -n $namespace -f"
212- echo
213- exit 0
204+ if [[ " $command " == " flows" || " $command " == " packets" ]]; then
205+ echo " Check the generated YAML file in output folder."
206+ echo
207+ echo " You can create $command agents by executing:"
208+ echo " ${K8S_CLI_BIN} apply -f ./output/${command} _capture_${dateName} .yml"
209+ echo
210+ echo " Then create the collector using:"
211+ echo -e " $cmd "
212+ echo
213+ echo " And follow its progression with:"
214+ echo " ${K8S_CLI_BIN} logs collector -n $namespace -f"
215+ echo
216+ exit 0
217+ else
218+ echo " Check the generated YAML file in output folder."
219+ echo
220+ echo " You can create metrics agents by executing:"
221+ echo " ${K8S_CLI_BIN} apply -f ./output/${command} _capture_${dateName} .yml"
222+ echo
223+ echo " Then open your OCP Console and search for netobserv-cli dashboard"
224+ echo
225+ exit 0
226+ fi
214227 fi
215228
216229 echo " Running network-observability-cli get-$cmd ... "
@@ -228,28 +241,22 @@ if [[ "$command" == "flows" || "$command" == "packets" ]]; then
228241 -n $namespace \
229242 collector \
230243 -- $execCommand
231- else
244+ elif [[ " $command " == " flows " || " $command " == " packets " ]] ; then
232245 echo " Background capture started. Use:"
233246 echo " - '${K8S_CLI_BIN} netobserv follow' to see the capture progress"
234247 echo " - '${K8S_CLI_BIN} netobserv copy' to copy the generated files locally"
235248 echo " - '${K8S_CLI_BIN} netobserv cleanup' to remove the netobserv components"
236- fi
237- elif [ " $command " = " metrics" ]; then
238- if [[ " $outputYAML " == " true" ]]; then
239- echo " Check the generated YAML file in output folder."
240249 echo
241- echo " You can create metrics agents by executing:"
242- echo " ${K8S_CLI_BIN} apply -f ./output/${command} _capture_${dateName} .yml"
243- echo
244- echo " Then open your OCP Console and search for netobserv-cli dashboard"
250+ echo " Capture ends automatically in $maxTime or reaching $maxBytes bytes"
251+ else
252+ runBackground=" true"
253+ echo " Metrics capture started."
254+ consoleURL=" $( oc whoami --show-console) "
255+ echo " Open ${consoleURL} /monitoring/dashboards/netobserv-cli to see generated metrics."
256+ echo " Use '${K8S_CLI_BIN} netobserv stop' to stop the collection and 'oc netobserv cleanup' to remove everything."
245257 echo
246- exit 0
258+ echo " Capture ends automatically in $maxTime "
247259 fi
248- runBackground=" true"
249- echo " Metrics capture started."
250- consoleURL=" $( oc whoami --show-console) "
251- echo " Open ${consoleURL} /monitoring/dashboards/netobserv-cli to see generated metrics."
252- echo " Use 'oc netobserv stop' to stop the collection and 'oc netobserv cleanup' to remove everything."
253260else
254261 echo " Unexpected exception occured on $command "
255262 exit 1
0 commit comments