Skip to content

Commit ea03eb7

Browse files
committed
add web status: Config + System
1 parent 3faa220 commit ea03eb7

7 files changed

Lines changed: 158 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.samourai.javaserver.web.controllers;
2+
3+
import com.samourai.javaserver.web.models.ConfigTemplateModel;
4+
import org.springframework.ui.Model;
5+
6+
public class AbstractConfigWebController {
7+
8+
public String config(Model model, ConfigTemplateModel templateModel) {
9+
templateModel.apply(model);
10+
return "decorators/config.html";
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.samourai.javaserver.web.controllers;
2+
3+
import com.samourai.javaserver.web.models.SystemTemplateModel;
4+
import org.springframework.ui.Model;
5+
6+
public class AbstractSystemWebController {
7+
8+
public String system(Model model, SystemTemplateModel templateModel) {
9+
templateModel.apply(model);
10+
return "decorators/system.html";
11+
}
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.samourai.javaserver.web.models;
2+
3+
import java.util.Map;
4+
import org.springframework.ui.Model;
5+
6+
public class ConfigTemplateModel extends DashboardTemplateModel {
7+
public Map<String, String> configInfo;
8+
9+
public ConfigTemplateModel(String pageTitle, String logoTitle, Map<String, String> configInfo) {
10+
super(pageTitle, logoTitle);
11+
this.configInfo = configInfo;
12+
}
13+
14+
public void apply(Model model) {
15+
super.apply(model);
16+
model.addAttribute("configInfo", configInfo);
17+
}
18+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.samourai.javaserver.web.models;
2+
3+
import java.util.Collection;
4+
import java.util.Comparator;
5+
import java.util.stream.Collectors;
6+
import org.springframework.ui.Model;
7+
8+
public class SystemTemplateModel extends DashboardTemplateModel {
9+
public Collection<Thread> threads;
10+
private long memUsed;
11+
private long memTotal;
12+
13+
public SystemTemplateModel(String pageTitle, String logoTitle) {
14+
super(pageTitle, logoTitle);
15+
16+
ThreadGroup tg = Thread.currentThread().getThreadGroup();
17+
this.threads =
18+
Thread.getAllStackTraces()
19+
.keySet()
20+
.stream()
21+
.filter(t -> t.getThreadGroup() == tg)
22+
.sorted(Comparator.comparing(o -> o.getName().toLowerCase()))
23+
.collect(Collectors.toList());
24+
if (false) {
25+
Thread t = threads.iterator().next();
26+
t.getName();
27+
t.getState();
28+
}
29+
30+
// memory
31+
Runtime rt = Runtime.getRuntime();
32+
memTotal = rt.totalMemory();
33+
long free = rt.freeMemory();
34+
memUsed = memTotal - free;
35+
}
36+
37+
public void apply(Model model) {
38+
super.apply(model);
39+
model.addAttribute("threads", threads);
40+
model.addAttribute("memUsed", memUsed);
41+
model.addAttribute("memTotal", memTotal);
42+
}
43+
}

src/main/resources/static/css/dashboard.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
}
1818
.container-fluid a:hover {
1919
color: #b71c1c;
20+
}
21+
.table-sm {
22+
font-size: 0.8em;
2023
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml"
3+
xmlns:th="http://www.thymeleaf.org"
4+
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
5+
layout:decorate="~{decorators/dashboard}"
6+
th:with="currentPage = 'config'">
7+
<head>
8+
<title>Configuration</title>
9+
<link rel="stylesheet" href="/css/config.css" />
10+
</head>
11+
<body>
12+
<div layout:fragment="main">
13+
<h1 class="h2">Configuration</h1>
14+
15+
<div class="table-responsive">
16+
<table class="table table-sm history">
17+
<thead>
18+
<tr>
19+
<th scope="col">Key</th>
20+
<th scope="col">Value</th>
21+
</tr>
22+
</thead>
23+
<tbody>
24+
<tr th:each="entry : *{configInfo}">
25+
<td class="configInfoKey"><span th:text="${entry.key}"/></td>
26+
<td class="configInfoValue"><pre><code th:text="${entry.value}"/></pre></td>
27+
</tr>
28+
</tbody>
29+
</table>
30+
</div>
31+
</div>
32+
</body>
33+
34+
</html>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml"
3+
xmlns:th="http://www.thymeleaf.org"
4+
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
5+
layout:decorate="~{decorators/dashboard}"
6+
th:with="currentPage = 'system'">
7+
<head>
8+
<title>System</title>
9+
<link rel="stylesheet" href="/css/config.css" />
10+
</head>
11+
<body>
12+
<div layout:fragment="main">
13+
<h1 class="h2">System</h1>
14+
15+
<div>Mem use: <strong th:text="${memUsed}M"/>/<span th:text="${memTotal}M"/></div>
16+
<div><strong th:text="${threads.size()}"/> threads running.</div>
17+
<div class="table-responsive">
18+
<table class="table table-sm system">
19+
<thead>
20+
<tr>
21+
<th scope="col">Thread</th>
22+
<th scope="col">Status</th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
<tr th:each="thread : ${threads}">
27+
<td class="threadName"><span th:text="${thread.getName()}"/></td>
28+
<td class="threadState"><span th:text="${thread.getState()}"/></td>
29+
</tr>
30+
</tbody>
31+
</table>
32+
</div>
33+
</div>
34+
</body>
35+
36+
</html>

0 commit comments

Comments
 (0)