clementine-oaklight[bot] clementine-oaklight[bot] commited on
Commit
2f6a57f
·
unverified ·
1 Parent(s): 4b885ad

feat: improve dashboard UI with badges, capacity bar, and responsive layout (#20)

Browse files

- Add shields.io badges for GitHub, PyPI, Docker Hub, HF Spaces
- Add capacity utilization bar with color-coded thresholds
- Improve visual hierarchy with section labels and card borders
- Color-code success rate based on thresholds (≥95% green, ≥80% yellow, <80% red)
- Dynamic failure count color (red when >0, green when clean)
- Add hover effects on cards and table rows
- Responsive layout: 2-column grid on mobile
- Polish typography with monospace tabular numbers for stats

Fixes #19

Co-authored-by: clementine-oaklight[bot] <290556973+clementine-oaklight[bot]@users.noreply.github.com>

Files changed (1) hide show
  1. src/veilrender/routes/dashboard.py +149 -47
src/veilrender/routes/dashboard.py CHANGED
@@ -7,18 +7,34 @@ from veilrender._vendor.httpserver import App, Request, Response
7
  from veilrender.browser import browser_manager
8
  from veilrender.config import settings
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  def _stats_row(name: str, ep: stats.EndpointStats) -> str:
12
  """Build an HTML table row for one endpoint."""
 
13
  return f"""
14
  <tr>
15
- <td>{name}</td>
16
- <td>{ep.requests}</td>
17
- <td>{ep.successes}</td>
18
- <td>{ep.failures}</td>
19
- <td>{ep.success_rate:.1f}%</td>
20
- <td>{ep.avg_ms:.0f} ms</td>
21
- <td>{ep.p95_ms:.0f} ms</td>
22
  </tr>"""
23
 
24
 
@@ -32,6 +48,9 @@ def _build_html() -> str:
32
  total_ok = stats.render.successes + stats.screenshot.successes
33
  total_fail = stats.render.failures + stats.screenshot.failures
34
 
 
 
 
35
  return f"""<!DOCTYPE html>
36
  <html lang="en">
37
  <head>
@@ -41,30 +60,104 @@ def _build_html() -> str:
41
  <title>VeilRender Dashboard</title>
42
  <style>
43
  * {{ margin: 0; padding: 0; box-sizing: border-box; }}
44
- body {{ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
45
- background: #0f172a; color: #e2e8f0; padding: 2rem; }}
46
- h1 {{ font-size: 1.5rem; margin-bottom: 1.5rem; color: #f8fafc; }}
47
- .grid {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
48
- gap: 1rem; margin-bottom: 2rem; }}
49
- .card {{ background: #1e293b; border-radius: 8px; padding: 1.2rem; }}
50
- .card .label {{ font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
51
- color: #94a3b8; margin-bottom: 0.3rem; }}
52
- .card .value {{ font-size: 1.5rem; font-weight: 600; }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  .green {{ color: #4ade80; }}
 
54
  .red {{ color: #f87171; }}
55
  .blue {{ color: #60a5fa; }}
56
- table {{ width: 100%; border-collapse: collapse; background: #1e293b;
57
- border-radius: 8px; overflow: hidden; }}
58
- th, td {{ padding: 0.75rem 1rem; text-align: left; }}
59
- th {{ background: #334155; font-size: 0.75rem; text-transform: uppercase;
60
- letter-spacing: 0.05em; color: #94a3b8; }}
61
- td {{ border-top: 1px solid #334155; }}
62
- .footer {{ margin-top: 2rem; font-size: 0.75rem; color: #64748b; }}
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  </style>
64
  </head>
65
  <body>
66
- <h1>👻 VeilRender Dashboard</h1>
 
 
 
 
 
67
 
 
68
  <div class="grid">
69
  <div class="card">
70
  <div class="label">Uptime</div>
@@ -75,12 +168,15 @@ def _build_html() -> str:
75
  <div class="value">{browser_status}</div>
76
  </div>
77
  <div class="card">
78
- <div class="label">Active Pages</div>
79
- <div class="value blue">{active} / {max_conc}</div>
 
 
 
80
  </div>
81
  <div class="card">
82
  <div class="label">Total Requests</div>
83
- <div class="value">{total_req}</div>
84
  </div>
85
  <div class="card">
86
  <div class="label">Successes</div>
@@ -88,29 +184,35 @@ def _build_html() -> str:
88
  </div>
89
  <div class="card">
90
  <div class="label">Failures</div>
91
- <div class="value red">{total_fail}</div>
92
  </div>
93
  </div>
94
 
95
- <table>
96
- <thead>
97
- <tr>
98
- <th>Endpoint</th>
99
- <th>Requests</th>
100
- <th>Success</th>
101
- <th>Failure</th>
102
- <th>Rate</th>
103
- <th>Avg Latency</th>
104
- <th>P95 Latency</th>
105
- </tr>
106
- </thead>
107
- <tbody>
108
- {_stats_row("/render", stats.render)}
109
- {_stats_row("/screenshot", stats.screenshot)}
110
- </tbody>
111
- </table>
112
-
113
- <div class="footer">Auto-refreshes every 5 seconds &middot; Stats are in-memory and reset on restart</div>
 
 
 
 
 
 
114
  </body>
115
  </html>"""
116
 
 
7
  from veilrender.browser import browser_manager
8
  from veilrender.config import settings
9
 
10
+ _BADGES_HTML = """
11
+ <a href="https://github.com/Oaklight/veilrender" target="_blank" rel="noopener">
12
+ <img src="https://img.shields.io/github/stars/Oaklight/veilrender?style=flat&amp;logo=github&amp;label=GitHub" alt="GitHub">
13
+ </a>
14
+ <a href="https://pypi.org/project/veilrender/" target="_blank" rel="noopener">
15
+ <img src="https://img.shields.io/pypi/v/veilrender?style=flat&amp;logo=pypi&amp;logoColor=white&amp;label=PyPI" alt="PyPI">
16
+ </a>
17
+ <a href="https://hub.docker.com/r/oaklight/veilrender" target="_blank" rel="noopener">
18
+ <img src="https://img.shields.io/docker/pulls/oaklight/veilrender?style=flat&amp;logo=docker&amp;logoColor=white&amp;label=Docker" alt="Docker Hub">
19
+ </a>
20
+ <a href="https://huggingface.co/spaces/oaklight/veilrender-public" target="_blank" rel="noopener">
21
+ <img src="https://img.shields.io/badge/%F0%9F%A4%97_HF_Spaces-demo-yellow?style=flat" alt="HF Spaces">
22
+ </a>
23
+ """
24
+
25
 
26
  def _stats_row(name: str, ep: stats.EndpointStats) -> str:
27
  """Build an HTML table row for one endpoint."""
28
+ rate_class = "green" if ep.success_rate >= 95 else "yellow" if ep.success_rate >= 80 else "red"
29
  return f"""
30
  <tr>
31
+ <td><code>{name}</code></td>
32
+ <td class="mono">{ep.requests}</td>
33
+ <td class="mono green">{ep.successes}</td>
34
+ <td class="mono red">{ep.failures}</td>
35
+ <td class="mono {rate_class}">{ep.success_rate:.1f}%</td>
36
+ <td class="mono">{ep.avg_ms:.0f} ms</td>
37
+ <td class="mono">{ep.p95_ms:.0f} ms</td>
38
  </tr>"""
39
 
40
 
 
48
  total_ok = stats.render.successes + stats.screenshot.successes
49
  total_fail = stats.render.failures + stats.screenshot.failures
50
 
51
+ utilization = (active / max_conc * 100) if max_conc > 0 else 0
52
+ util_class = "green" if utilization < 70 else "yellow" if utilization < 90 else "red"
53
+
54
  return f"""<!DOCTYPE html>
55
  <html lang="en">
56
  <head>
 
60
  <title>VeilRender Dashboard</title>
61
  <style>
62
  * {{ margin: 0; padding: 0; box-sizing: border-box; }}
63
+ body {{
64
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
65
+ background: #0f172a; color: #e2e8f0; padding: 2rem;
66
+ min-height: 100vh;
67
+ }}
68
+
69
+ /* Header */
70
+ .header {{
71
+ display: flex; align-items: center; justify-content: space-between;
72
+ flex-wrap: wrap; gap: 1rem; margin-bottom: 2rem;
73
+ padding-bottom: 1.5rem; border-bottom: 1px solid #1e293b;
74
+ }}
75
+ .header h1 {{
76
+ font-size: 1.5rem; font-weight: 700; color: #f8fafc;
77
+ letter-spacing: -0.02em;
78
+ }}
79
+ .header h1 span {{ color: #818cf8; }}
80
+ .badges {{ display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }}
81
+ .badges a {{ text-decoration: none; transition: opacity 0.15s; }}
82
+ .badges a:hover {{ opacity: 0.8; }}
83
+ .badges img {{ height: 20px; vertical-align: middle; }}
84
+
85
+ /* Section labels */
86
+ .section-label {{
87
+ font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
88
+ letter-spacing: 0.08em; color: #64748b; margin-bottom: 0.75rem;
89
+ }}
90
+
91
+ /* Cards */
92
+ .grid {{
93
+ display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
94
+ gap: 0.75rem; margin-bottom: 2rem;
95
+ }}
96
+ .card {{
97
+ background: #1e293b; border-radius: 10px; padding: 1.2rem;
98
+ border: 1px solid #334155; transition: border-color 0.2s;
99
+ }}
100
+ .card:hover {{ border-color: #475569; }}
101
+ .card .label {{
102
+ font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
103
+ color: #94a3b8; margin-bottom: 0.4rem;
104
+ }}
105
+ .card .value {{ font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }}
106
+
107
+ /* Table */
108
+ .table-wrap {{
109
+ background: #1e293b; border-radius: 10px; border: 1px solid #334155;
110
+ overflow: hidden; margin-bottom: 2rem;
111
+ }}
112
+ table {{ width: 100%; border-collapse: collapse; }}
113
+ th {{
114
+ padding: 0.7rem 1rem; text-align: left; font-size: 0.7rem;
115
+ text-transform: uppercase; letter-spacing: 0.06em; color: #94a3b8;
116
+ background: #1e293b; border-bottom: 1px solid #334155;
117
+ }}
118
+ td {{
119
+ padding: 0.7rem 1rem; border-top: 1px solid rgba(51, 65, 85, 0.5);
120
+ }}
121
+ tr:hover td {{ background: rgba(51, 65, 85, 0.3); }}
122
+ code {{ font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace; font-size: 0.9em; }}
123
+ .mono {{ font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace; font-variant-numeric: tabular-nums; }}
124
+
125
+ /* Colors */
126
  .green {{ color: #4ade80; }}
127
+ .yellow {{ color: #facc15; }}
128
  .red {{ color: #f87171; }}
129
  .blue {{ color: #60a5fa; }}
130
+ .indigo {{ color: #818cf8; }}
131
+
132
+ /* Capacity bar */
133
+ .bar-track {{
134
+ height: 6px; background: #334155; border-radius: 3px;
135
+ margin-top: 0.5rem; overflow: hidden;
136
+ }}
137
+ .bar-fill {{ height: 100%; border-radius: 3px; transition: width 0.3s; }}
138
+
139
+ /* Footer */
140
+ .footer {{
141
+ font-size: 0.7rem; color: #475569; display: flex;
142
+ justify-content: space-between; flex-wrap: wrap; gap: 0.5rem;
143
+ }}
144
+
145
+ @media (max-width: 640px) {{
146
+ body {{ padding: 1rem; }}
147
+ .header {{ flex-direction: column; align-items: flex-start; }}
148
+ .grid {{ grid-template-columns: repeat(2, 1fr); }}
149
+ }}
150
  </style>
151
  </head>
152
  <body>
153
+ <div class="header">
154
+ <h1>👻 <span>Veil</span>Render</h1>
155
+ <div class="badges">
156
+ {_BADGES_HTML}
157
+ </div>
158
+ </div>
159
 
160
+ <div class="section-label">Overview</div>
161
  <div class="grid">
162
  <div class="card">
163
  <div class="label">Uptime</div>
 
168
  <div class="value">{browser_status}</div>
169
  </div>
170
  <div class="card">
171
+ <div class="label">Capacity</div>
172
+ <div class="value {util_class}">{active} <span style="font-size:0.8rem;color:#94a3b8">/ {max_conc}</span></div>
173
+ <div class="bar-track">
174
+ <div class="bar-fill" style="width:{utilization:.0f}%;background:{'#4ade80' if utilization < 70 else '#facc15' if utilization < 90 else '#f87171'}"></div>
175
+ </div>
176
  </div>
177
  <div class="card">
178
  <div class="label">Total Requests</div>
179
+ <div class="value indigo">{total_req}</div>
180
  </div>
181
  <div class="card">
182
  <div class="label">Successes</div>
 
184
  </div>
185
  <div class="card">
186
  <div class="label">Failures</div>
187
+ <div class="value {'red' if total_fail > 0 else 'green'}">{total_fail}</div>
188
  </div>
189
  </div>
190
 
191
+ <div class="section-label">Endpoints</div>
192
+ <div class="table-wrap">
193
+ <table>
194
+ <thead>
195
+ <tr>
196
+ <th>Endpoint</th>
197
+ <th>Requests</th>
198
+ <th>Success</th>
199
+ <th>Failure</th>
200
+ <th>Rate</th>
201
+ <th>Avg Latency</th>
202
+ <th>P95 Latency</th>
203
+ </tr>
204
+ </thead>
205
+ <tbody>
206
+ {_stats_row("/render", stats.render)}
207
+ {_stats_row("/screenshot", stats.screenshot)}
208
+ </tbody>
209
+ </table>
210
+ </div>
211
+
212
+ <div class="footer">
213
+ <span>Auto-refreshes every 5s &middot; Stats are in-memory, reset on restart</span>
214
+ <span>VeilRender &middot; Headless browser rendering API</span>
215
+ </div>
216
  </body>
217
  </html>"""
218