Skip to content

Commit 7fba04e

Browse files
committed
Added capacity information to the output.
1 parent 03fe678 commit 7fba04e

2 files changed

Lines changed: 141 additions & 19 deletions

File tree

Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_filesystems

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
# o Subnet ID - optional
2626
# o ARN - optional
2727
# o Backup - The Backup retention period.
28+
# o Capacity - Optional
29+
# o Used Capacity - Optional
2830
#
2931
# In the case of the Management IP and Subnet ID, it will only show the first
3032
# one defined. Based on the potential output from the API call, there could
@@ -50,7 +52,7 @@ Usage $(basename $0) [-r region] [-a] [-n] [-c] [-s] [-b] [-i fileSystemId] [-f
5052
-b means to display the backup retenion period. Not compoatible with the -x or -c options.
5153
-s means to display the current status of a volume. Only relative with the -c option.
5254
-n means to show the AWS ARN for the file system. Not compatible with -x or -c options.
53-
-x means include additional information: vpc, subnet, Size, Deployement Type, Throughput, provisioned IOPS.
55+
-x means include additional information: vpc, subnet, Size, Deployement Type, Throughput, provisioned IOPS, usage.
5456
EOF
5557
exit 1
5658
}
@@ -62,7 +64,10 @@ tmpout=/tmp/list_fss-out.$$
6264
fileSystemsFile=/tmp/list_fss-fss.$$
6365
svmsFile=/tmp/list_fss-svms.$$
6466
volumesFile=/tmp/list_fss-volumes.$$
65-
trap 'rm -f $tmpout $fileSystemsFile $svmsFile $volumesFile' exit
67+
cloudwatchOutputFile=/tmp/list_fss-cloudwatch-output.$$
68+
cloudwatchQueryFile=/tmp/list_fss-cloudwatch-query.$$
69+
fsCapacityFile=/tmp/list_fss-fscapacity.$$
70+
trap 'rm -f $tmpout $fileSystemsFile $svmsFile $volumesFile $cloudwatchOutputFile $cloudwatchQueryFile $fsCapacityFile' exit
6671
#
6772
# Ensure all the required ultilities are installed.
6873
if which aws jq > /dev/null 2>&1; then
@@ -253,7 +258,52 @@ for region in ${regions[*]}; do
253258
largestName=$(awk -F, 'BEGIN {max=0} {if(length($3) > max){max=length($3)}} END {print max}' < $tmpout)
254259
nameFieldWidth=$((largestName + 4))
255260
if [ "$includeExtraInfo" == "true" ]; then
256-
awk -F, -v region=$region 'BEGIN {first=1; formatStr="%12s %23s %'$nameFieldWidth's %14s %15s %22s %25s %6s %12s %11s %6s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "Name", "Status", "Management IP", "VPC ID", "Subnet ID", "Size", "Deployment", "Throughput", "Iops"; first=0}; printf formatStr, region, $1, "\"" $3 "\"", $4, $5, $6, $7, $(12), $9, $(11), $(10)}' < $tmpout
261+
fsxIds=$(awk -F, '{print $1}' < $tmpout)
262+
echo "[" > $cloudwatchQueryFile
263+
first=true
264+
for fsid in $fsxIds; do
265+
fsid2=$(echo $fsid | sed -e 's/-/_/g')
266+
if [ "$first" == "true" ]; then
267+
first=false
268+
else
269+
echo "," >> $cloudwatchQueryFile
270+
fi
271+
cat <<EOF >> $cloudwatchQueryFile
272+
{
273+
"Id": "${fsid2}_StorageUsed",
274+
"MetricStat": {
275+
"Metric": {
276+
"Namespace": "AWS/FSx",
277+
"MetricName": "StorageUsed",
278+
"Dimensions": [
279+
{
280+
"Name": "FileSystemId",
281+
"Value": "${fsid}"
282+
},
283+
{
284+
"Name": "StorageTier",
285+
"Value": "SSD"
286+
},
287+
{
288+
"Name": "DataType",
289+
"Value": "All"
290+
}]
291+
},
292+
"Period": 300,
293+
"Stat": "Average"
294+
}
295+
}
296+
EOF
297+
done
298+
echo "]" >> $cloudwatchQueryFile
299+
aws cloudwatch get-metric-data --region=$region --metric-data-queries file://$cloudwatchQueryFile --start-time=$(date -u -d '5 minutes ago' +"%Y-%m-%dT%H:%M:%SZ") --end-time=$(date -u +"%Y-%m-%dT%H:%M:%SZ") --output=json > $cloudwatchOutputFile 2>&1
300+
for fsid in $fsxIds; do
301+
fsid2=$(echo $fsid | sed -e 's/-/_/g')
302+
storageUsed=$(jq -r '.MetricDataResults[] | if(.Id == "'${fsid2}_StorageUsed'") then .Values[0] else empty end' $cloudwatchOutputFile)
303+
echo "$fsid,$storageUsed" >> $fsCapacityFile
304+
done
305+
306+
awk -F, -v region=$region -v fsCapacityFile=$fsCapacityFile 'BEGIN {first=1; formatStr="%12s %23s %'$nameFieldWidth's %14s %15s %22s %25s %10s %10s %12s %11s %6s\n"; while (getline < fsCapacityFile) {fsidCapacities[$1]=sprintf("%10.0f",$2/1024/1024/1024)}}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "Name", "Status", "Management IP", "VPC ID", "Subnet ID", "Size(GiB)", "Used(GiB)", "Deployment", "Throughput", "Iops"; first=0}; printf formatStr, region, $1, "\"" $3 "\"", $4, $5, $6, $7, $(12), fsidCapacities[$1], $9, $(11), $(10)}' < $tmpout
257307
else
258308
if [ "$showARN" == "true" ]; then
259309
awk -F, -v region=$region 'BEGIN {first=1; formatStr="%12s %23s %70s %'$nameFieldWidth's %14s %15s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "ARN", "Name", "Status", "Management IP"; first=0}; printf formatStr, region, $1, $2, "\"" $3 "\"", $4, $5}' < $tmpout

Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_volumes

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
# It will list:
1818
# o Region
1919
# o File System ID
20-
# o File System Name - optional
20+
# o File System Name - optional with -n option
21+
# o Storage Virtual Machine ID
22+
# o Storage Virtual Machine Name - optional with -n option
2123
# o Volume ID
22-
# o Volume Name
2324
# o Volume Status
25+
# o Volume Size in MB - optional - optional with -x option
26+
# o Volume Used in MB - optional - optional with -x option
27+
# o Volume Name
2428
#
2529
################################################################################
2630

@@ -29,14 +33,16 @@
2933
################################################################################
3034
usage () {
3135
cat 1>&2 <<EOF
32-
Usage $(basename $0) [-r region] [-a] [-o] [-f fileSystemName] [-i fileSystemId] [-n] [-s svmID]
33-
Where: -r region allows you to specify the region you want the list from.
36+
Usage $(basename $0) [-r region] [-a] [-o] [-f fileSystemName] [-i fileSystemId] [-n] [-s svmID] [-x] [volume_pattern]
37+
Where: volume_pattern - Only volumes that match the egrep pattern will be included.
38+
-r region allows you to specify the region you want the list from.
3439
-a means all regions.
35-
-n means include the file system name.
40+
-n means include the file system ans SVM names. Not capable with the -x option.
3641
-f fileSystemName means to only include volumes that are under the named file system.
3742
-i fileSystemId means to only include volumes that are under the file system with the specified file system ID.
3843
-s svmID - Only show volumes that are under the specified SVM ID.
3944
-o means to exclude svm root volumes. Only works in conjunction with the -s option.
45+
-x means to provide capacity information. Not capable with the -n option.
4046
EOF
4147
exit 1
4248
}
@@ -45,9 +51,13 @@ EOF
4551
# Main logic starts here.
4652
################################################################################
4753

48-
tmpout=/tmp/list_aws_vol-out.$$
49-
tmpout2=/tmp/list_aws_vol-out0.$$
50-
trap 'rm -f $tmpout $tmpout2' exit
54+
volumeList=/tmp/list_aws_vol-out.$$
55+
fsNames=/tmp/list_aws_vol-fsNames.$$
56+
svmNames=/tmp/list_aws_vol-svmNames.$$
57+
cloudwatchOutputFile=/tmp/list_vol-cloudwatch-output.$$
58+
cloudwatchQueryFile=/tmp/list_vol-cloudwatch-query.$$
59+
volCapacityFile=/tmp/list_vol-capacity.$$
60+
trap 'rm -f $volumeList $fsNames $svmNames $cloudwatchOutputFile $cloudwatchQueryFile $volCapacityFile' exit
5161
#
5262
# Check that the required utilities are installed.
5363
if which aws jq > /dev/null 2>&1; then
@@ -65,7 +75,9 @@ excludeRoot=false
6575
filter=""
6676
fsid=""
6777
fileSystemName=""
68-
while getopts "hr:af:i:nos:" option; do
78+
extraInfo=false
79+
volumePattern="*"
80+
while getopts "hr:af:i:nos:x" option; do
6981
case "$option" in
7082
r) region="$OPTARG"
7183
;;
@@ -82,16 +94,27 @@ while getopts "hr:af:i:nos:" option; do
8294
;;
8395
s) svmID="$OPTARG"
8496
;;
97+
x) extraInfo=true
98+
;;
8599
*) usage
86100
;;
87101
esac
88102
done
103+
shift $((OPTIND-1))
104+
if [ ! -z "$1" ]; then
105+
volumePattern="$1"
106+
fi
89107

90108
if [ ! -z "$fileSystenName" -a ! -z "$fsid" ]; then
91109
echo "Error, you can't provide both -f and -n options." 1>&2
92110
exit 1
93111
fi
94112

113+
if [ "$extraInfo" != "false" -a "$includeFsName" != "false" ]; then
114+
echo "Error, you can't provide both -n and -x options." 1>&2
115+
exit 1
116+
fi
117+
95118
if [ ! -z "$fileSystemName" ]; then
96119
fsid=$(aws fsx describe-file-systems --region $region --output=json 2> /dev/null | jq -r ".FileSystems[] | if((.Tags[] | select(.Key == \"Name\") .Value) == \"${fileSystemName}\") then .FileSystemId else empty end" 2> /dev/null)
97120
if [ -z "$fsid" ]; then
@@ -127,6 +150,8 @@ if [ "$allRegions" = "true" ]; then
127150
else
128151
regions=($region)
129152
fi
153+
154+
jqFields='\(.FileSystemId),\(.Name),\(.VolumeId),\(.Lifecycle),\(.OntapConfiguration.SizeInMegabytes),\(.OntapConfiguration.StorageVirtualMachineId)'
130155
#
131156
# Loop on all the regions.
132157
for region in ${regions[*]}; do
@@ -135,23 +160,70 @@ for region in ${regions[*]}; do
135160
if [ ! -z "$(getent hosts fsx.$region.amazonaws.com)" ]; then
136161
if [ -z "$svmID" ]; then
137162
if [ "$excludeRoot" != "true" ]; then
138-
aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | .FileSystemId + "," + .Name + "," + .VolumeId + "," + .Lifecycle' | sort > $tmpout
163+
aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | "'$jqFields'"' | egrep ",$volumePattern," | sort > $volumeList
139164
else
140-
aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineRoot | not) then .FileSystemId + "," + .Name + "," + .VolumeId + "," + .Lifecycle else empty end' | sort > $tmpout
165+
aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineRoot | not) then "'$jqFields'" else empty end' | egrep ",$volumePattern," | sort > $volumeList
141166
fi
142167
else
143168
if [ "$excludeRoot" != "true" ]; then
144-
aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineId == "'$svmID'") then .FileSystemId + "," + .Name + "," + .VolumeId + "," + .Lifecycle else empty end' | sort > $tmpout
169+
aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineId == "'$svmID'") then "'$jqFields'" else empty end' | egrep ",$volumePattern," | sort > $volumeList
145170
else
146-
aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineId == "'$svmID'" and (.OntapConfiguration.StorageVirtualMachineRoot | not)) then .FileSystemId + "," + .Name + "," + .VolumeId + "," + .Lifecycle else empty end' | sort > $tmpout
171+
aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineId == "'$svmID'" and (.OntapConfiguration.StorageVirtualMachineRoot | not)) then "'$jqFields'" else empty end' | egrep ",$volumePattern," | sort > $volumeList
147172
fi
148173
fi
149174

150175
if [ $includeFsName == "true" ]; then
151-
aws fsx describe-file-systems --region=$region --output=json | jq -r '.FileSystems[] | .FileSystemId + "," + (.Tags[] | select(.Key == "Name") .Value)' | fgrep "$fileSystemName" > $tmpout2
152-
awk -F, -v region=$region 'BEGIN {first=1; maxNameLen=0; while(getline < "'$tmpout2'") {fss[$1]=$2; if(length($2) > maxNameLen) {maxNameLen=length($2)}}; maxNameLen +=2; formatStr="%12s %21s%-"maxNameLen"s %24s %10s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "(Name)", "Volume ID", "State", "Volume Name"; first=0}; name="("fss[$1]")"; printf formatStr, region, $1, name, $3, $4, $2}' < $tmpout
176+
aws fsx describe-file-systems --region=$region --output=json | jq -r '.FileSystems[] | .FileSystemId + "," + (.Tags[] | select(.Key == "Name") .Value)' > $fsNames
177+
aws fsx describe-storage-virtual-machines --region=$region --output=json | jq -r '.StorageVirtualMachines[] | "\(.StorageVirtualMachineId),\(.Name)"' > $svmNames
178+
awk -F, -v region=$region 'BEGIN {first=1; maxFsNameLen=0; maxSvmNameLen=0; while(getline < "'$fsNames'") {fss[$1]=$2; if(length($2) > maxFsNameLen) {maxFsNameLen=length($2)}}; maxFsNameLen +=2; while(getline < "'$svmNames'") {svm[$1]=$2; if(length($2) > maxSvmNameLen) {maxSvmNameLen=length($2)}}; maxSvmNameLen +=2; formatStr="%12s %21s%-"maxFsNameLen"s %21s-%-"maxSvmNameLen"s %24s %10s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "(Name)", "SVM", "(Name)", "Volume ID", "State", "Volume Name"; first=0}; fsName="("fss[$1]")"; svmName="("svm[$6]")"; printf formatStr, region, $1, fsName, $6, svmName, $3, $4, $2}' < $volumeList
153179
else
154-
awk -F, -v region=$region 'BEGIN {first=1; formatStr="%12s %21s %24s %10s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "Volume ID", "State", "Volume Name"; first=0}; printf formatStr, region, $1, $3, $4, $2}' < $tmpout
180+
if [ $extraInfo == "true" ]; then
181+
volIds=$(awk -F, '{print $3}' < $volumeList)
182+
if [ ! -z "$volIds" ]; then
183+
echo "[" > $cloudwatchQueryFile
184+
first=true
185+
for volId in $volIds; do
186+
volId2=$(echo $volId | sed -e 's/-/_/g')
187+
if [ "$first" = "true" ]; then
188+
first=false
189+
else
190+
echo "," >> $cloudwatchQueryFile
191+
fi
192+
cat <<EOF >> $cloudwatchQueryFile
193+
{
194+
"Id": "m$volId2",
195+
"MetricStat": {
196+
"Metric": {
197+
"Namespace": "AWS/FSx",
198+
"MetricName": "StorageUsed",
199+
"Dimensions": [
200+
{
201+
"Name": "VolumeId",
202+
"Value": "$volId"
203+
},
204+
{
205+
"Name": "FileSystemId",
206+
"Value": "$(awk -F, -v volId=$volId '$3 == volId {print $1}' < $volumeList)"
207+
}]
208+
},
209+
"Period": 300,
210+
"Stat": "Average"
211+
}
212+
}
213+
EOF
214+
done
215+
echo "]" >> $cloudwatchQueryFile
216+
aws cloudwatch get-metric-data --region $region --metric-data-queries file://$cloudwatchQueryFile --start-time=$(date -u -d '5 minutes ago' +"%Y-%m-%dT%H:%M:%SZ") --end-time=$(date -u +"%Y-%m-%dT%H:%M:%SZ") --output=json > $cloudwatchOutputFile 2>&1
217+
for volId in $volIds; do
218+
volId2=$(echo $volId | sed -e 's/-/_/g')
219+
capacity=$(jq -r '.MetricDataResults[] | select(.Id == "m'$volId2'") | .Values[0]' < $cloudwatchOutputFile)
220+
echo "$volId,$capacity" >> $volCapacityFile
221+
done
222+
awk -F, -v region=$region -v volCapacityFile=$volCapacityFile 'BEGIN {first=1; formatStr="%12s %21s %21s %24s %10s %16s %15s %s\n"; while (getline < volCapacityFile) {volidCapacities[$1]=sprintf("%10.0f",$2/1024/1024)}}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "SVM", "Volume ID", "State", "Volume Size (MB)", "Used (MB)", "Volume Name"; first=0}; printf formatStr, region, $1, $6, $3, $4, $5, volidCapacities[$3], $2}' < $volumeList
223+
fi
224+
else
225+
awk -F, -v region=$region 'BEGIN {first=1; formatStr="%12s %21s %21s %24s %10s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "SVM", "Volume ID", "State", "Volume Name"; first=0}; printf formatStr, region, $1, $6, $3, $4, $2}' < $volumeList
226+
fi
155227
fi
156228
else
157229
if [ $allRegions != "true" ]; then

0 commit comments

Comments
 (0)