-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.py
More file actions
41 lines (32 loc) · 1.45 KB
/
Copy pathdashboard.py
File metadata and controls
41 lines (32 loc) · 1.45 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
from tabulate import tabulate
from colorama import Fore, Style, init
init()
def generate_dashboard(cloud_data):
print(Style.BRIGHT + Fore.CYAN + "\n" + "="*60)
print(" AWS COST OPTIMIZER REPORT ")
print("="*60 + Style.RESET_ALL)
grand_total = 0.0
summary_data = []
all_details = []
for service, resources in cloud_data.items():
service_total = 0.0
count = len(resources)
for item in resources:
cost = item.get('Cost', 0.0)
service_total += cost
grand_total += cost
all_details.append([service, item.get('ID', 'N/A'), item.get('Reason', 'Unused'), f"${cost:.2f}"])
if count > 0:
summary_data.append([service, count, f"${service_total:.2f}"])
print(Fore.YELLOW + "\n SUMMARY" + Style.RESET_ALL)
if summary_data:
print(tabulate(summary_data, headers=["Service", "Count", "Monthly Waste"], tablefmt="fancy_grid"))
else:
print(Fore.GREEN + " No waste found." + Style.RESET_ALL)
if all_details:
print(Fore.YELLOW + "\n DETAILED FINDINGS" + Style.RESET_ALL)
all_details.sort(key=lambda x: float(x[3].replace('$', '')), reverse=True)
print(tabulate(all_details, headers=["Service", "Resource ID", "Reason", "Est. Cost"], tablefmt="simple"))
print(Style.BRIGHT + "\n" + "-"*60)
print(f" TOTAL POTENTIAL SAVINGS: ${grand_total:.2f} / month")
print("-"*60 + "\n")