Skip to content

Commit 624fb9f

Browse files
committed
Initial Version
1 parent 2119173 commit 624fb9f

File tree

2 files changed

+72
-30
lines changed

2 files changed

+72
-30
lines changed

Management-Utilities/FSxN-Report/Generate-FSxN-Report.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def getFSxNInfo(region):
7373
fsxnId = fsxn['FileSystemId']
7474
count += 1
7575
metrics.append({
76-
"Id": f"{fsxnId.replace('fs-', 'm_')}",
76+
"Id": f"{fsxnId.replace('fs-', 'm_')}_StorageUsed",
7777
"MetricStat": {
7878
"Metric": {
7979
"Namespace": "AWS/FSx",
@@ -97,15 +97,31 @@ def getFSxNInfo(region):
9797
},
9898
"ReturnData": True
9999
})
100-
if count > 100:
100+
101+
metrics.append({
102+
"Id": f"{fsxnId.replace('fs-', 'm_')}_StorageSavings",
103+
"MetricStat": {
104+
"Metric": {
105+
"Namespace": "AWS/FSx",
106+
"MetricName": "StorageEfficiencySavings",
107+
"Dimensions": [{
108+
"Name": "FileSystemId",
109+
"Value": fsxnId
110+
}]
111+
},
112+
"Period": 300,
113+
"Stat": "Average"
114+
},
115+
"ReturnData": True
116+
})
117+
#
118+
# The maximum is 500 metrics per request. This loop has 2 metric per iteration.
119+
if count > 200:
101120
response = cwClient.get_metric_data(MetricDataQueries=metrics,
102121
StartTime=datetime.now() - timedelta(minutes=10),
103122
EndTime=datetime.now())
104123
for metric in response['MetricDataResults']:
105-
fsxnId = metric['Id'].replace('m_', 'fs-')
106-
fsxnUsageInfo[fsxnId] = {
107-
'UsedCapacity': metric['Values'][0] if len(metric['Values']) > 0 else 'N/A',
108-
'StorageCapacity': fsxn['StorageCapacity']}
124+
fsxnUsageInfo[metric['Id']] = metric
109125
count = 0
110126
metrics = []
111127

@@ -114,10 +130,8 @@ def getFSxNInfo(region):
114130
StartTime=datetime.now() - timedelta(minutes=10),
115131
EndTime=datetime.now())
116132
for metric in response['MetricDataResults']:
117-
fsxnId = metric['Id'].replace('m_', 'fs-')
118-
fsxnUsageInfo[fsxnId] = {
119-
'UsedCapacity': metric['Values'][0] if len(metric['Values']) > 0 else 'N/A',
120-
'StorageCapacity': fsxn['StorageCapacity']}
133+
fsxnUsageInfo[metric['Id']] = metric
134+
121135
#
122136
# Retrieve all the SVMs
123137
svmsData = fsxClient.describe_storage_virtual_machines()
@@ -206,7 +220,8 @@ def getFSxNInfo(region):
206220
},
207221
"ReturnData": True
208222
})
209-
223+
#
224+
# The maximum is 500 metrics per request. This loop has 6 metric per iteration.
210225
if count > 70:
211226
response = cwClient.get_metric_data(MetricDataQueries=metrics,
212227
StartTime=datetime.now() - timedelta(minutes=10),
@@ -222,6 +237,7 @@ def getFSxNInfo(region):
222237
EndTime=datetime.now())
223238
for metric in response['MetricDataResults']:
224239
volumeUsageInfo[metric['Id']] = metric
240+
225241
################################################################################
226242
# This function is used to generate a html version of the report.
227243
################################################################################
@@ -238,20 +254,23 @@ def generateHTMLReport(region):
238254
fsxnId = fsxn['FileSystemId']
239255
name = getTag('Name', fsxn.get('Tags', []))
240256
ontapConfig = fsxn['OntapConfiguration']
241-
if fsxnUsageInfo[fsxnId]['UsedCapacity'] != 'N/A' :
242-
fileSystemUsedCapacity = int(fsxnUsageInfo[fsxnId]['UsedCapacity']/1024/1024/1024)
257+
if len(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageUsed']['Values']) > 0:
258+
fileSystemUsedCapacity = int(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageUsed']['Values'][0]/1024/1024/1024)
243259
percentUsed = f"{((fileSystemUsedCapacity / fsxn['StorageCapacity']) * 100):.2f}%"
244260
fileSystemUsedCapacity = f"{fileSystemUsedCapacity}GB"
245261
else:
246262
fileSystemUsedCapacity = 'N/A'
247263
percentUsed = 'N/A'
264+
fileSystemStorageSavings = f"{fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageSavings']['Values'][0]/1024/1024/1024:.2f}GB" if len(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageSavings']['Values']) > 0 else 'N/A'
248265
htmlBody += f'<tr><td colspan=11 style="{tableCellStyle}"><b>ID:</b> {fsxnId}<br>\n'
249266
htmlBody += f"<b>Name:</b> {name}<br>\n"
250267
htmlBody += f"<b>Region:</b> {region}<br>\n"
251268
htmlBody += f"<b>Availability:</b> {ontapConfig['DeploymentType']}<br>\n"
269+
htmlBody += f"<b>Provisioned Throughput Capacity:</b> {ontapConfig['ThroughputCapacity']} MB/s<br>\n"
252270
htmlBody += f"<b>Provisioned Performance Tier Storage:</b> {fsxn['StorageCapacity']}GB<br>\n"
253271
htmlBody += f"<b>Used Performance Tier Storage:</b> {fileSystemUsedCapacity}<br>\n"
254272
htmlBody += f"<b>Percent Used Performance Tier:</b> {percentUsed}<br>\n"
273+
htmlBody += f"<b>Storage Savings:</b> {fileSystemStorageSavings}<br>\n"
255274
htmlBody += "</td></tr>\n"
256275
htmlBody += f'<tr><td colspan=11 style="{tableCellStyle}"><b>Volumes:</b></td></tr>\n'
257276
htmlBody += f'<tr><th style="{tableCellStyle}">Name</th><th style="{tableCellStyle}">SVM</th><th style="{tableCellStyle}">ID</th>\n'
@@ -306,15 +325,17 @@ def generateTextReport(region):
306325
backupConfig = fsxn.get('AutomaticBackupRetentionDays', 'N/A')
307326
textReport += f"{indent}Backup Configuration: {backupConfig}\n{indent}Maintenance Schedule: {ontapConfig['WeeklyMaintenanceStartTime']}\n"
308327
textReport += f"{indent}Provisioned Capacity: {fsxn['StorageCapacity']}GB\n"
309-
if fsxnUsageInfo[fsxnId]['UsedCapacity'] != 'N/A' :
310-
fileSystemUsedCapacity = int(fsxnUsageInfo[fsxnId]['UsedCapacity']/1024/1024/1024)
328+
if len(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageUsed']['Values']) > 0:
329+
fileSystemUsedCapacity = int(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageUsed']['Values'][0]/1024/1024/1024)
311330
percentUsed = f"{((fileSystemUsedCapacity / fsxn['StorageCapacity']) * 100):.2f}%"
312331
fileSystemUsedCapacity = f"{fileSystemUsedCapacity}GB"
313332
else:
314333
fileSystemUsedCapacity = 'N/A'
315334
percentUsed = 'N/A'
316335
textReport += f"{indent}Used Capacity: {fileSystemUsedCapacity}\n"
317336
textReport += f"{indent}Percent Capacity Used: {percentUsed}\n"
337+
fileSystemStorageSavings = f"{fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageSavings']['Values'][0]/1024/1024/1024:.2f}GB" if len(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageSavings']['Values']) > 0 else 'N/A'
338+
textReport += f"{indent}Storage Savings: {fileSystemStorageSavings}\n"
318339

319340
textReport += f"{indent}Storage Virtual Machines:\n"
320341
for svm in svms:

Management-Utilities/FSxN-Report/cloudformation.yaml

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ Resources:
269269
fsxnId = fsxn['FileSystemId']
270270
count += 1
271271
metrics.append({
272-
"Id": f"{fsxnId.replace('fs-', 'm_')}",
272+
"Id": f"{fsxnId.replace('fs-', 'm_')}_StorageUsed",
273273
"MetricStat": {
274274
"Metric": {
275275
"Namespace": "AWS/FSx",
@@ -293,15 +293,31 @@ Resources:
293293
},
294294
"ReturnData": True
295295
})
296-
if count > 100:
296+
297+
metrics.append({
298+
"Id": f"{fsxnId.replace('fs-', 'm_')}_StorageSavings",
299+
"MetricStat": {
300+
"Metric": {
301+
"Namespace": "AWS/FSx",
302+
"MetricName": "StorageEfficiencySavings",
303+
"Dimensions": [{
304+
"Name": "FileSystemId",
305+
"Value": fsxnId
306+
}]
307+
},
308+
"Period": 300,
309+
"Stat": "Average"
310+
},
311+
"ReturnData": True
312+
})
313+
#
314+
# The maximum is 500 metrics per request. This loop has 2 metric per iteration.
315+
if count > 200:
297316
response = cwClient.get_metric_data(MetricDataQueries=metrics,
298317
StartTime=datetime.now() - timedelta(minutes=10),
299318
EndTime=datetime.now())
300319
for metric in response['MetricDataResults']:
301-
fsxnId = metric['Id'].replace('m_', 'fs-')
302-
fsxnUsageInfo[fsxnId] = {
303-
'UsedCapacity': metric['Values'][0] if len(metric['Values']) > 0 else 'N/A',
304-
'StorageCapacity': fsxn['StorageCapacity']}
320+
fsxnUsageInfo[metric['Id']] = metric
305321
count = 0
306322
metrics = []
307323
@@ -310,10 +326,8 @@ Resources:
310326
StartTime=datetime.now() - timedelta(minutes=10),
311327
EndTime=datetime.now())
312328
for metric in response['MetricDataResults']:
313-
fsxnId = metric['Id'].replace('m_', 'fs-')
314-
fsxnUsageInfo[fsxnId] = {
315-
'UsedCapacity': metric['Values'][0] if len(metric['Values']) > 0 else 'N/A',
316-
'StorageCapacity': fsxn['StorageCapacity']}
329+
fsxnUsageInfo[metric['Id']] = metric
330+
317331
#
318332
# Retrieve all the SVMs
319333
svmsData = fsxClient.describe_storage_virtual_machines()
@@ -402,7 +416,8 @@ Resources:
402416
},
403417
"ReturnData": True
404418
})
405-
419+
#
420+
# The maximum is 500 metrics per request. This loop has 6 metric per iteration.
406421
if count > 70:
407422
response = cwClient.get_metric_data(MetricDataQueries=metrics,
408423
StartTime=datetime.now() - timedelta(minutes=10),
@@ -418,6 +433,7 @@ Resources:
418433
EndTime=datetime.now())
419434
for metric in response['MetricDataResults']:
420435
volumeUsageInfo[metric['Id']] = metric
436+
421437
################################################################################
422438
# This function is used to generate a html version of the report.
423439
################################################################################
@@ -434,20 +450,23 @@ Resources:
434450
fsxnId = fsxn['FileSystemId']
435451
name = getTag('Name', fsxn.get('Tags', []))
436452
ontapConfig = fsxn['OntapConfiguration']
437-
if fsxnUsageInfo[fsxnId]['UsedCapacity'] != 'N/A' :
438-
fileSystemUsedCapacity = int(fsxnUsageInfo[fsxnId]['UsedCapacity']/1024/1024/1024)
453+
if len(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageUsed']['Values']) > 0:
454+
fileSystemUsedCapacity = int(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageUsed']['Values'][0]/1024/1024/1024)
439455
percentUsed = f"{((fileSystemUsedCapacity / fsxn['StorageCapacity']) * 100):.2f}%"
440456
fileSystemUsedCapacity = f"{fileSystemUsedCapacity}GB"
441457
else:
442458
fileSystemUsedCapacity = 'N/A'
443459
percentUsed = 'N/A'
460+
fileSystemStorageSavings = f"{fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageSavings']['Values'][0]/1024/1024/1024:.2f}GB" if len(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageSavings']['Values']) > 0 else 'N/A'
444461
htmlBody += f'<tr><td colspan=11 style="{tableCellStyle}"><b>ID:</b> {fsxnId}<br>\n'
445462
htmlBody += f"<b>Name:</b> {name}<br>\n"
446463
htmlBody += f"<b>Region:</b> {region}<br>\n"
447464
htmlBody += f"<b>Availability:</b> {ontapConfig['DeploymentType']}<br>\n"
465+
htmlBody += f"<b>Provisioned Throughput Capacity:</b> {ontapConfig['ThroughputCapacity']} MB/s<br>\n"
448466
htmlBody += f"<b>Provisioned Performance Tier Storage:</b> {fsxn['StorageCapacity']}GB<br>\n"
449467
htmlBody += f"<b>Used Performance Tier Storage:</b> {fileSystemUsedCapacity}<br>\n"
450468
htmlBody += f"<b>Percent Used Performance Tier:</b> {percentUsed}<br>\n"
469+
htmlBody += f"<b>Storage Savings:</b> {fileSystemStorageSavings}<br>\n"
451470
htmlBody += "</td></tr>\n"
452471
htmlBody += f'<tr><td colspan=11 style="{tableCellStyle}"><b>Volumes:</b></td></tr>\n'
453472
htmlBody += f'<tr><th style="{tableCellStyle}">Name</th><th style="{tableCellStyle}">SVM</th><th style="{tableCellStyle}">ID</th>\n'
@@ -502,15 +521,17 @@ Resources:
502521
backupConfig = fsxn.get('AutomaticBackupRetentionDays', 'N/A')
503522
textReport += f"{indent}Backup Configuration: {backupConfig}\n{indent}Maintenance Schedule: {ontapConfig['WeeklyMaintenanceStartTime']}\n"
504523
textReport += f"{indent}Provisioned Capacity: {fsxn['StorageCapacity']}GB\n"
505-
if fsxnUsageInfo[fsxnId]['UsedCapacity'] != 'N/A' :
506-
fileSystemUsedCapacity = int(fsxnUsageInfo[fsxnId]['UsedCapacity']/1024/1024/1024)
524+
if len(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageUsed']['Values']) > 0:
525+
fileSystemUsedCapacity = int(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageUsed']['Values'][0]/1024/1024/1024)
507526
percentUsed = f"{((fileSystemUsedCapacity / fsxn['StorageCapacity']) * 100):.2f}%"
508527
fileSystemUsedCapacity = f"{fileSystemUsedCapacity}GB"
509528
else:
510529
fileSystemUsedCapacity = 'N/A'
511530
percentUsed = 'N/A'
512531
textReport += f"{indent}Used Capacity: {fileSystemUsedCapacity}\n"
513532
textReport += f"{indent}Percent Capacity Used: {percentUsed}\n"
533+
fileSystemStorageSavings = f"{fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageSavings']['Values'][0]/1024/1024/1024:.2f}GB" if len(fsxnUsageInfo[fsxnId.replace('fs-', 'm_') + '_StorageSavings']['Values']) > 0 else 'N/A'
534+
textReport += f"{indent}Storage Savings: {fileSystemStorageSavings}\n"
514535
515536
textReport += f"{indent}Storage Virtual Machines:\n"
516537
for svm in svms:

0 commit comments

Comments
 (0)