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) { ...@@ -75,6 +75,7 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) {
.offline { background-color: #ffebee; } .offline { background-color: #ffebee; }
.online { background-color: #e8f5e8; } .online { background-color: #e8f5e8; }
.disk-item { margin-bottom: 5px; } .disk-item { margin-bottom: 5px; }
.high { color: #c62828; font-weight: 700; } /* red bold for >90% */
</style> </style>
</head> </head>
<body> <body>
...@@ -99,7 +100,7 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) { ...@@ -99,7 +100,7 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) {
<td>{{.Status}}</td> <td>{{.Status}}</td>
<td>{{.Height}}</td> <td>{{.Height}}</td>
<td>{{printf "%.2f" .CPUUsage}}</td> <td>{{printf "%.2f" .CPUUsage}}</td>
<td>{{printf "%.2f" .MemoryUsage}}</td> <td><span class="{{.MemoryUsageClass}}">{{.MemoryUsageFormatted}}</span></td>
<td>{{.MemoryInfo}}</td> <td>{{.MemoryInfo}}</td>
<td>{{.AllDisksInfo}}</td> <td>{{.AllDisksInfo}}</td>
<td>{{.PrivateIP}}</td> <td>{{.PrivateIP}}</td>
...@@ -119,6 +120,8 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) { ...@@ -119,6 +120,8 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) {
MemoryInfo string MemoryInfo string
AllDisksInfo template.HTML AllDisksInfo template.HTML
LastReport string LastReport string
MemoryUsageClass string
MemoryUsageFormatted string
} }
nodeViews := make([]NodeView, len(nodes)) nodeViews := make([]NodeView, len(nodes))
...@@ -131,15 +134,19 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) { ...@@ -131,15 +134,19 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) {
statusClass = "offline" statusClass = "offline"
} }
// Format all disk information // Format all disk information and highlight usage > 90%
var allDisksInfo string var allDisksInfo string
if len(node.DiskInfos) > 0 { if len(node.DiskInfos) > 0 {
for _, diskInfo := range node.DiskInfos { for _, diskInfo := range node.DiskInfos {
mountPoint := diskInfo.Path mountPoint := diskInfo.Path
usage := diskInfo.UsedPercent 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, mountPoint,
usage, usageStr,
float64(diskInfo.Free)/(1024*1024*1024), float64(diskInfo.Free)/(1024*1024*1024),
float64(diskInfo.Total)/(1024*1024*1024)) float64(diskInfo.Total)/(1024*1024*1024))
} }
...@@ -147,6 +154,14 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) { ...@@ -147,6 +154,14 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) {
allDisksInfo = "No disk information available" 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{ nodeViews[i] = NodeView{
NodeStatus: node, NodeStatus: node,
Status: status, Status: status,
...@@ -154,6 +169,8 @@ func (s *Server) handleNodes(w http.ResponseWriter, r *http.Request) { ...@@ -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)), MemoryInfo: fmt.Sprintf("%.2f GB / %.2f GB", float64(node.MemoryFree)/(1024*1024*1024), float64(node.MemoryTotal)/(1024*1024*1024)),
AllDisksInfo: template.HTML(allDisksInfo), AllDisksInfo: template.HTML(allDisksInfo),
LastReport: node.Timestamp.Format("2006-01-02 15:04:05"), 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