Commit edd362af authored by vicotor's avatar vicotor

update server format

parent 55dd59a7
......@@ -75,6 +75,7 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) {
.offline { background-color: #ffebee; }
.online { background-color: #e8f5e8; }
.disk-item { margin-bottom: 5px; }
.high { color: #c62828; font-weight: 700; } /* red bold for >90% */
</style>
</head>
<body>
......@@ -99,7 +100,7 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) {
<td>{{.Status}}</td>
<td>{{.Height}}</td>
<td>{{printf "%.2f" .CPUUsage}}</td>
<td>{{printf "%.2f" .MemoryUsage}}</td>
<td><span class="{{.MemoryUsageClass}}">{{.MemoryUsageFormatted}}</span></td>
<td>{{.MemoryInfo}}</td>
<td>{{.AllDisksInfo}}</td>
<td>{{.PrivateIP}}</td>
......@@ -119,6 +120,8 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) {
MemoryInfo string
AllDisksInfo template.HTML
LastReport string
MemoryUsageClass string
MemoryUsageFormatted string
}
nodeViews := make([]NodeView, len(nodes))
......@@ -131,15 +134,19 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) {
statusClass = "offline"
}
// Format all disk information
// Format all disk information and highlight usage > 90%
var allDisksInfo string
if len(node.DiskInfos) > 0 {
for _, diskInfo := range node.DiskInfos {
mountPoint := diskInfo.Path
usage := diskInfo.UsedPercent
allDisksInfo += fmt.Sprintf("<div class='disk-item'><strong>%s:</strong> %.2f%% (%.2f GB / %.2f GB)</div>",
usageStr := fmt.Sprintf("%.2f%%", usage)
if usage >= 90.0 {
usageStr = fmt.Sprintf("<span class='high'>%.2f%%</span>", usage)
}
allDisksInfo += fmt.Sprintf("<div class='disk-item'><strong>%s:</strong> %s (%.2f GB / %.2f GB)</div>",
mountPoint,
usage,
usageStr,
float64(diskInfo.Free)/(1024*1024*1024),
float64(diskInfo.Total)/(1024*1024*1024))
}
......@@ -147,6 +154,14 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) {
allDisksInfo = "No disk information available"
}
// Memory usage highlight (red & bold if >= 90%)
memUsage := node.MemoryUsage
memUsageClass := ""
if memUsage >= 90.0 {
memUsageClass = "high"
}
memUsageFormatted := fmt.Sprintf("%.2f%%", memUsage)
nodeViews[i] = NodeView{
NodeStatus: node,
Status: status,
......@@ -154,6 +169,8 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) {
MemoryInfo: fmt.Sprintf("%.2f GB / %.2f GB", float64(node.MemoryFree)/(1024*1024*1024), float64(node.MemoryTotal)/(1024*1024*1024)),
AllDisksInfo: template.HTML(allDisksInfo),
LastReport: node.Timestamp.Format("2006-01-02 15:04:05"),
MemoryUsageClass: memUsageClass,
MemoryUsageFormatted: memUsageFormatted,
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment