Skip to content

Commit d49821f

Browse files
committed
Fix: api_stats.sh improvements
* Get latest API version from the API itself * Provide commandline option for port and help
1 parent bd77d7b commit d49821f

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

nginx-debugger/api_stats.sh

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
#!/usr/bin/env bash
2-
for i in /api/8/processes /api/8/connections /api/8/slabs /api/8/http/requests /api/8/http/server_zones /api/8/http/location_zones /api/8/http/caches /api/8/http/upstreams /api/8/http/keyvals; do
3-
echo "**** $i ****" ;
4-
curl -s "127.0.0.1:8080/$i" | jq .;
5-
echo "";
2+
3+
# Parse command line options
4+
set -e
5+
set -o pipefail
6+
while getopts "p:v:h" opt; do
7+
case $opt in
8+
p) API_PORT="$OPTARG"
9+
;;
10+
h) echo "Usage: $0 [-p port]"
11+
exit 0
12+
;;
13+
\?) echo "Invalid option -$OPTARG" >&2
14+
echo "Usage: $0 [-p port]"
15+
exit 1
16+
;;
17+
esac
18+
done
19+
20+
if [ $OPTIND -eq 1 ]; then
21+
echo "No options were passed, exiting ..."
22+
echo "Usage: $(basename "$0") [-p port]"
23+
exit 1
24+
fi
25+
26+
if [ -z "${API_PORT}" ]; then
27+
echo 'Missing -p arg' >&2
28+
exit 1
29+
fi
30+
31+
api_versions=($(curl http://127.0.0.1:$API_PORT/api/ | sed -e 's/\[//g' -e 's/\]//g' -e 's/\,/ /g'))
32+
API_VERSION=${api_versions[-1]}
33+
echo "API_VERSION: $API_VERSION"
34+
35+
echo "**** /api/$API_VERSION/nginx ****" ;
36+
curl -s "127.0.0.1:$API_PORT/api/$API_VERSION/nginx" | jq .;
37+
echo "";
38+
39+
for i in /api/$API_VERSION/processes /api/$API_VERSION/connections /api/$API_VERSION/slabs /api/$API_VERSION/http/requests /api/$API_VERSION/http/server_zones /api/$API_VERSION/http/location_zones /api/$API_VERSION/http/caches /api/$API_VERSION/http/upstreams /api/$API_VERSION/http/keyvals; do
40+
echo "**** $i ****" ;
41+
curl -s "127.0.0.1:$API_PORT/$i" | jq .;
42+
echo "";
643
done

0 commit comments

Comments
 (0)