-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
121 lines (90 loc) · 2.24 KB
/
web.py
File metadata and controls
121 lines (90 loc) · 2.24 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
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
import json
app = FastAPI()
@app.get("/", response_class=HTMLResponse)
def index():
with open("result.json") as f:
data = json.load(f)
cpu_total = data["summary"]["cpu_reclaim"]
ram_total = data["summary"]["ram_reclaim"]
servers = data["summary"]["servers"]
html = f"""
<html>
<head>
<title>Resource Optimizer</title>
<style>
body {{
font-family: Arial;
padding:20px;
}}
summary {{
cursor:pointer;
font-size:18px;
font-weight:bold;
}}
.job {{
margin-top:15px;
}}
.server {{
margin-left:25px;
}}
.box {{
background:#f5f5f5;
padding:10px;
margin-top:5px;
white-space:pre-line;
}}
.total {{
background:#eaeaea;
padding:15px;
margin-bottom:20px;
font-size:18px;
}}
.reclaim {{ color:green; font-weight:bold }}
.grow {{ color:red; font-weight:bold }}
</style>
</head>
<body>
<h1>Resource Optimizer</h1>
<div class="total">
Total servers: {servers}<br>
CPU reclaim: {cpu_total} cores<br>
RAM reclaim: {ram_total} GB
</div>
"""
for job in sorted(data["groups"]):
html += f"""
<details class="job">
<summary>📁 {job}</summary>
"""
for host in sorted(data["groups"][job]):
srv = data["groups"][job][host]
cpu = srv["cpu"]
ram = srv["ram"]
cpu_line = f"<span class='reclaim'>Reclaim: {cpu['reclaim']} cores</span>" if cpu["reclaim"]>0 else (
f"<span class='grow'>Need add: {cpu['grow']} cores</span>" if cpu["grow"]>0 else "Optimal")
ram_line = f"<span class='reclaim'>Reclaim: {ram.get('reclaim',0)} GB</span>" if ram.get("reclaim",0)>0 else (
f"<span class='grow'>Need add: {ram.get('grow',0)} GB</span>" if ram.get("grow",0)>0 else "Optimal")
html += f"""
<div class="server">
<details>
<summary>🖥 {host}</summary>
<div class="box">
CPU:
Current: {cpu['current']}
p95 usage: {cpu['p95']}
Recommended: {cpu['recommended']}
{cpu_line}
RAM:
Current: {ram.get('current','-')} GB
p95 usage: {ram.get('p95','-')} GB
Recommended: {ram.get('recommended','-')} GB
{ram_line}
</div>
</details>
</div>
"""
html += "</details>"
html += "</body></html>"
return html