-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathget_latency_metrics
More file actions
executable file
·149 lines (137 loc) · 6.13 KB
/
Copy pathget_latency_metrics
File metadata and controls
executable file
·149 lines (137 loc) · 6.13 KB
1
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
#
################################################################################
# This script is used to get all the metrics for a volume.
#
# It is dependent on the 'wf_utils' file that is included in this repo. That
# file contains the 'get_token' function that is used to obtain a valid
# access token that is needed to run the Workload Factory APIs. The file needs
# to either be in the command search path or in the current directory.
################################################################################
################################################################################
# This function just prints the usage of this script and exits the program.
################################################################################
usage() {
cat >&2 <<EOF
This script is used to get all the metrics for a volume.
Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -v volume_id [-j]
Where: refresh_token - Is a refresh token used to obtain an access token needed
to run the Workload Factory APIs. You can obtain a refresh
token by going to https://services.cloud.netapp.com/refresh-token
blueXP_account_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
list of accounts you have access to.
volume_id - is the ID of the volume you want to get latency metrics for.
-j - If specified, the output will be in JSON format instead of a table.
Instead of passing parameters on the command line, you can set the
following environment variables:
export REFRESH_TOKEN=<refresh_token>
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
Legend:
Timestamp - The time the metrics were collected.
Volume ID - The ID of the volume these metrics are for.
Network - The network latency.
Cluster - The cluster interconnect latency.
Data - The CPU latency.
Disk - The disk latency.
QoS Max - The latency caused by a QoS Maximum settings.
QoS Min - The latency caused by a QoS Minimum settings.
NVRAM - The NVRAM synchronization latency.
Cloud - The tiering latency.
FlexCache - The latency caused by retrieving data from a FlexCache source.
SM Sync - The latency caused by a SnapMirror synchronous operations.
VA - The latency caused by volume activation (VA) operations.
Details - Any details about the latency event.
EOF
exit 1
}
################################################################################
# Main logic starts here.
################################################################################
tmpout=$(mktemp /tmp/list_volumes-out.XXXXXX)
tmpout2=$(mktemp /tmp/list_volumes-out2.XXXXXX)
tmperr=$(mktemp /tmp/list_volumes-err.XXXXXX)
trap 'rm -f $tmpout $tmpout2 $tmperr' exit
#
# Source the wf_utils file.
wf_utils=$(command -v wf_utils)
if [ -z "$wf_utils" ]; then
if [ ! -x "./wf_utils" ]; then
cat >&2 <<EOF
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
It is required to run this script. You can download it from:
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
exit 1
else
wf_utils=./wf_utils
fi
fi
. "$wf_utils"
#
# Process command line arguments.
JSON_OUTPUT=false
while getopts "ht:a:v:j" opt; do
case $opt in
t) REFRESH_TOKEN="$OPTARG" ;;
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
v) VOLUME_ID="$OPTARG" ;;
j) JSON_OUTPUT=true ;;
*) usage ;;
esac
done
#
# Declare an array of required options and the error message to display if they are not set.
declare -A required_options
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
https://services.cloud.netapp.com/refresh-token\n\n'
required_options["BLUEXP_ACCOUNT_ID"]='Error: A BlueXP account ID is required to run this script.
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
required_options["VOLUME_ID"]='Error: The ID of the volume to get latency metrics for is required.\n\n'
check_required_options
#
# Check that the required commands are available.
for cmd in jq curl; do
if ! command -v $cmd &> /dev/null; then
echo "Error: The required command '$cmd' not found. Please install it." >&2
exit 1
fi
done
token=$(get_token)
if [ -z "$token" ]; then
echo "Error: Failed to obtain an access token. Exiting." >&2
exit 1
fi
if [ "$JSON_OUTPUT" == true ]; then
jq_query='.'
else
jq_query='.items[] | "\(.createdAt),\(.volumeId),\(if(.latencyAnalysis.Network) then .latencyAnalysis.Network else 0 end),\(if(.latencyAnalysis.Cluster) then .latencyAnalysis.Cluster else 0 end),\(if(.latencyAnalysis.Data) then .latencyAnalysis.Data else 0 end),\(if(.latencyAnalysis.Disk) then .latencyAnalysis.Disk else 0 end),\(if(.latencyAnalysis."QoS Max") then .latencyAnalysis."QoS Max" else 0 end),\(if(.latencyAnalysis.NVRAM) then .latencyAnalysis.NVRAM else 0 end),\(if(.latencyAnalysis.Cloud) then .latencyAnalysis.Cloud else 0 end),\(if(.latencyAnalysis.FlexCache) then .latencyFlexCache else 0 end),\(.details)"'
fi
URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/latency/analysis/${VOLUME_ID}/history"
run_curl GET "$token" "$URL" $tmpout $tmperr
if jq -r "$jq_query" $tmpout > $tmpout2 2> $tmperr; then
:
else
echo "Error: Failed to parse the output from the API." >&2
cat $tmperr >&2
exit 1
fi
#
# Check to see if there are more.
nextToken=$(jq -r '.nextToken' $tmpout)
while [ "$nextToken" != "null" ]; do
run_curl GET "$token" "${URL}?nextToken=$nextToken" $tmpout $tmperr
if jq -r "$jq_query" $tmpout >> $tmpout2 2> $tmperr; then
:
else
echo "Error: Failed to parse the output from the API." >&2
cat $tmperr >&2
exit 1
fi
nextToken=$(jq -r '.nextToken' $tmpout)
done
if [ "$JSON_OUTPUT" == true ]; then
cat $tmpout2
else
sort -f $tmpout2 | column -s, -t -R 3,4,5,6,7,8,9,10 -N "Timestamp,Volume ID,Network,Cluster Inter,Data (CPU),Disk,QoS,NVRAM Sync,Cloud Tiering,Flex Cache,Details"
fi