Skip to content

Commit 0ae3043

Browse files
committed
new: xally node statistics, remove: private ipv4 from dashboard
1 parent f250423 commit 0ae3043

File tree

8 files changed

+307
-35
lines changed

8 files changed

+307
-35
lines changed

main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ func main() {
5353

5454
app.Get("/", func(c *fiber.Ctx) error {
5555
return c.Render("views/index.jet", fiber.Map{
56-
"Title": fmt.Sprintf("Dashboard - %s", cfg.Node),
57-
"NodeIP": cfg.IPv4,
56+
"Title": fmt.Sprintf("Dashboard - %s", cfg.Node),
57+
"NodeIP": cfg.IPv4,
58+
"NodeType": cfg.Node,
5859
})
5960
})
6061

public/img/logo/xally-logo.png

6.64 KB
Loading

public/js/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function attachTippy() {
1111
},
1212
],
1313
},
14+
placement: (nodeType === "Xally") ? 'top' : undefined,
1415
flip: false,
1516
content: document.getElementById('activity-bar').getAttribute('tooltip-data'),
1617
allowHTML: true,
@@ -29,6 +30,26 @@ document.addEventListener("htmx:confirm", function(e) {
2930
e.detail.issueRequest(true);
3031
return;
3132
}
33+
34+
console.log(e.detail.question.includes("node"), nodeType, e.detail.question)
35+
36+
if (e.detail.question.includes("node") && nodeType === "Xally") {
37+
//toast on the bottom saying Xally doesn't support node restart
38+
Swal.fire({
39+
title: "Xally does not support restarting",
40+
icon: "error",
41+
toast: true,
42+
position: "bottom",
43+
showConfirmButton: false,
44+
timer: 3000,
45+
width: 400,
46+
timerProgressBar: true,
47+
});
48+
49+
return;
50+
}
51+
52+
3253
Swal.fire({
3354
title: "Are you sure?",
3455
text: `${e.detail.question}`,

services/config/config.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"fmt"
55
"github.com/NodeboxHQ/node-dashboard/utils/logger"
66
"github.com/common-nighthawk/go-figure"
7-
"io/ioutil"
7+
"io"
88
"net"
99
"net/http"
1010
"os"
1111
"strings"
12+
"time"
1213
)
1314

14-
const version = "1.0.8"
15+
const version = "1.0.9"
1516

1617
type Config struct {
1718
Node string `json:"node"`
@@ -88,12 +89,17 @@ func getIPAddresses() (privateIPv4, publicIPv4, publicIPv6 string, err error) {
8889
}
8990

9091
func fetchPublicIP(url string) (string, error) {
91-
resp, err := http.Get(url)
92+
client := &http.Client{
93+
Timeout: 10 * time.Second,
94+
}
95+
96+
resp, err := client.Get(url)
9297
if err != nil {
9398
return "", err
9499
}
95100
defer resp.Body.Close()
96-
ip, err := ioutil.ReadAll(resp.Body)
101+
102+
ip, err := io.ReadAll(resp.Body)
97103
if err != nil {
98104
return "", err
99105
}
@@ -124,9 +130,12 @@ func LoadConfig() (*Config, error) {
124130
} else if strings.Contains(hostname, "-babylon") {
125131
logger.Info("Babylon node detected")
126132
config.Node = "Babylon"
133+
} else if strings.Contains(hostname, "-xcally") || strings.Contains(hostname, "-xally") {
134+
logger.Info("Xally node detected")
135+
config.Node = "Xally"
127136
} else {
128-
logger.Error("Unknown node detected, defaulting to Babylon")
129-
config.Node = "Babylon"
137+
logger.Error("Unknown node detected, defaulting to Xally")
138+
config.Node = "Xally"
130139
badHostname = true
131140
}
132141

services/usage.go

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/NodeboxHQ/node-dashboard/services/dusk"
88
"github.com/NodeboxHQ/node-dashboard/services/linea"
99
"github.com/NodeboxHQ/node-dashboard/services/nulink"
10+
"github.com/NodeboxHQ/node-dashboard/services/xally"
1011
"github.com/NodeboxHQ/node-dashboard/utils"
1112
"github.com/gofiber/fiber/v2"
1213
"github.com/mackerelio/go-osstat/cpu"
@@ -55,6 +56,8 @@ func GetLogo(config *config.Config) fiber.Handler {
5556
return c.SendString(fmt.Sprintf(`<img src="/assets/img/logo/nulink-logo.png?nodeip=%s" alt="logo-expanded" class="w-52 h-auto object-contain mx-auto block" />`, config.IPv4))
5657
} else if config.Node == "Babylon" {
5758
return c.SendString(fmt.Sprintf(`<img src="/assets/img/logo/babylon-logo.png?nodeip=%s" alt="logo-expanded" class="w-52 h-auto object-contain mx-auto block" />`, config.IPv4))
59+
} else if config.Node == "Xally" {
60+
return c.SendString(fmt.Sprintf(`<img src="/assets/img/logo/xally-logo.png?nodeip=%s" alt="logo-expanded" class="w-52 h-auto object-contain mx-auto block" />`, config.IPv4))
5861
} else {
5962
return c.SendString("")
6063
}
@@ -64,7 +67,7 @@ func GetLogo(config *config.Config) fiber.Handler {
6467
func GetCPUUsage(ipv4 string) fiber.Handler {
6568
return func(c *fiber.Ctx) error {
6669
cpuUsageTemplate := `
67-
<div class="items-center py-2.5 px-5 border backdrop-blur-md border-cardBackgroundColor rounded-[20px] bg-cardBackgroundColor w-full shadow-md" hx-get="/data/cpu?nodeip=%s" hx-trigger="load" hx-swap="outerHTML transition:true">
70+
<div class="items-center py-2.5 px-5 border backdrop-blur-md border-cardBackgroundColor rounded-[20px] bg-cardBackgroundColor w-full shadow-md" hx-get="/data/cpu?nodeip=%s" hx-trigger="load" hx-swap="outerHTML">
6871
<h3 class="mb-2.5 text-center text-cardTitleColor text-lg font-semibold">CPU</h3>
6972
<div class="flex flex-col">
7073
<div class="flex content-between items-center gap-1.5 justify-around flex-col">
@@ -104,7 +107,7 @@ func GetCPUUsage(ipv4 string) fiber.Handler {
104107
func GetRAMUsage(ipv4 string) fiber.Handler {
105108
return func(c *fiber.Ctx) error {
106109
ramUsageTemplate := `
107-
<div class="items-center py-2.5 px-5 border backdrop-blur-md border-cardBackgroundColor rounded-[20px] bg-cardBackgroundColor w-full shadow-md" hx-get="/data/ram?nodeip=%s" hx-trigger="every 1s" hx-swap="outerHTML transition:true">
110+
<div class="items-center py-2.5 px-5 border backdrop-blur-md border-cardBackgroundColor rounded-[20px] bg-cardBackgroundColor w-full shadow-md" hx-get="/data/ram?nodeip=%s" hx-trigger="every 1s" hx-swap="outerHTML">
108111
<h3 class="mb-2.5 text-center text-cardTitleColor text-lg font-semibold">RAM</h3>
109112
<div class="flex flex-col">
110113
<div class="flex content-between items-center gap-1.5 justify-around flex-col">
@@ -136,7 +139,7 @@ func GetRAMUsage(ipv4 string) fiber.Handler {
136139
func GetDiskUsage(ipv4 string) fiber.Handler {
137140
return func(c *fiber.Ctx) error {
138141
diskUsageTemplate := `
139-
<div class="items-center py-2.5 px-5 border backdrop-blur-md border-cardBackgroundColor rounded-[20px] bg-cardBackgroundColor w-full shadow-md" hx-get="/data/disk?nodeip=%s" hx-trigger="every 1s" hx-swap="outerHTML transition:true">
142+
<div class="items-center py-2.5 px-5 border backdrop-blur-md border-cardBackgroundColor rounded-[20px] bg-cardBackgroundColor w-full shadow-md" hx-get="/data/disk?nodeip=%s" hx-trigger="every 1s" hx-swap="outerHTML">
140143
<h3 class="mb-2.5 text-center text-cardTitleColor text-lg font-semibold">Disk Usage</h3>
141144
<div class="flex flex-col">
142145
<div class="flex content-between items-center gap-1.5 justify-around flex-col">
@@ -189,7 +192,7 @@ func GetDiskUsage(ipv4 string) fiber.Handler {
189192
func GetSystemUptime(ipv4 string) fiber.Handler {
190193
return func(c *fiber.Ctx) error {
191194
uptimeTemplate := `
192-
<div class="items-center py-2.5 px-5 border backdrop-blur-md border-cardBackgroundColor rounded-[20px] bg-cardBackgroundColor w-full shadow-md" hx-get="/data/uptime?nodeip=%s" hx-trigger="every 1s" hx-swap="outerHTML transition:true">
195+
<div class="items-center py-2.5 px-5 border backdrop-blur-md border-cardBackgroundColor rounded-[20px] bg-cardBackgroundColor w-full shadow-md" hx-get="/data/uptime?nodeip=%s" hx-trigger="every 1s" hx-swap="outerHTML">
193196
<h3 class="mb-2.5 text-center text-cardTitleColor text-lg font-semibold">Uptime</h3>
194197
<div class="flex flex-col">
195198
<div class="flex content-between items-center gap-1.5 justify-around flex-col">
@@ -240,7 +243,7 @@ func GetActivity(config *config.Config) fiber.Handler {
240243
adjective = "Online"
241244
}
242245

243-
tippyContent := fmt.Sprintf("<b>Node</b> - %s <br> <b>Owner</b> - %s<br> <b>Private IPv4</b> - %s <br> <b>Public IPv4</b> - %s <br> <b>Public IPv6</b> - %s <br>", config.Node, config.Owner, config.PrivateIPv4, config.IPv4, config.IPv6)
246+
tippyContent := fmt.Sprintf("<b>Node</b> - %s <br> <b>Owner</b> - %s<br> <b>Public IPv4</b> - %s <br> <b>Public IPv6</b> - %s <br>", config.Node, config.Owner, config.IPv4, config.IPv6)
244247

245248
needBr := ""
246249

@@ -280,7 +283,7 @@ func GetActivity(config *config.Config) fiber.Handler {
280283
adjective = "Online"
281284
}
282285

283-
tippyContent := fmt.Sprintf("<b>Node</b> - %s <br> <b>Version</b> - %s <br> <b>Owner</b> - %s<br> <b>Private IPv4</b> - %s <br> <b>Public IPv4</b> - %s <br> <b>Public IPv6</b> - %s <br>", config.Node, status.Version, config.Owner, config.PrivateIPv4, config.IPv4, config.IPv6)
286+
tippyContent := fmt.Sprintf("<b>Node</b> - %s <br> <b>Version</b> - %s <br> <b>Owner</b> - %s<br> <b>Public IPv4</b> - %s <br> <b>Public IPv6</b> - %s <br>", config.Node, status.Version, config.Owner, config.IPv4, config.IPv6)
284287

285288
needBr := ""
286289

@@ -315,7 +318,7 @@ func GetActivity(config *config.Config) fiber.Handler {
315318
adjective = "Offline"
316319
}
317320

318-
tippyContent := fmt.Sprintf("<b>Node</b> - %s <br> <b>Owner</b> - %s<br> <b>Private IPv4</b> - %s <br> <b>Public IPv4</b> - %s <br> <b>Public IPv6</b> - %s", config.Node, config.Owner, config.PrivateIPv4, config.IPv4, config.IPv6)
321+
tippyContent := fmt.Sprintf("<b>Node</b> - %s <br> <b>Owner</b> - %s<br> <b>Public IPv4</b> - %s <br> <b>Public IPv6</b> - %s", config.Node, config.Owner, config.IPv4, config.IPv6)
319322

320323
tippyContent = tippyContent + fmt.Sprintf("<br> <b>Dashboard Version</b> - %s", config.NodeboxDashboardVersion)
321324
activityTemplate = strings.Replace(activityTemplate, "ALPINE_TOOLTIP", fmt.Sprintf(`tooltip-data="%s"`, tippyContent), -1)
@@ -344,7 +347,7 @@ func GetActivity(config *config.Config) fiber.Handler {
344347
adjective = "Online"
345348
}
346349

347-
tippyContent := fmt.Sprintf("<b>Node</b> - %s <br> <b>Owner</b> - %s<br> <b>Private IPv4</b> - %s <br> <b>Public IPv4</b> - %s <br> <b>Public IPv6</b> - %s <br>", config.Node, config.Owner, config.PrivateIPv4, config.IPv4, config.IPv6)
350+
tippyContent := fmt.Sprintf("<b>Node</b> - %s <br> <b>Owner</b> - %s<br> <b>Public IPv4</b> - %s <br> <b>Public IPv6</b> - %s <br>", config.Node, config.Owner, config.IPv4, config.IPv6)
348351

349352
needBr := ""
350353

@@ -356,6 +359,70 @@ func GetActivity(config *config.Config) fiber.Handler {
356359
tippyContent = tippyContent + fmt.Sprintf("%s <b>Dashboard Version</b> - %s", needBr, config.NodeboxDashboardVersion)
357360
activityTemplate = strings.Replace(activityTemplate, "ALPINE_TOOLTIP", fmt.Sprintf(`tooltip-data="%s"`, tippyContent), -1)
358361

362+
return c.SendString(fmt.Sprintf(activityTemplate, color, adjective))
363+
} else if config.Node == "Xally" {
364+
activityTemplate := `
365+
<div class="w-64 h-7 mt-5 rounded-full overflow-hidden relative m-0" hx-get="/data/activity?nodeip=NODE_IP" hx-trigger="every 1s" hx-swap="outerHTML" id="activity-bar" ALPINE_TOOLTIP>
366+
<div class="absolute top-0 left-0 w-full z-0 h-full bg-progressBarBackgroundColor rounded-full"></div>
367+
<div class="absolute top-0 left-0 h-full rounded-[10px] transition-[width] w-full z-10 %s"></div>
368+
<div class="items-center text-sm font-bold text-textColor absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-20"> Node %s </div>
369+
</div>
370+
`
371+
372+
status, _ := xally.FetchNodeData()
373+
374+
color := ""
375+
adjective := ""
376+
totalRunTime := 0.0
377+
accumulatedGXally := 0.0
378+
lastUpdate := ""
379+
380+
var keyIDs []string
381+
var nodeIDs string
382+
383+
activityTemplate = strings.Replace(activityTemplate, "NODE_IP", config.IPv4, -1)
384+
385+
if len(status) == 0 {
386+
color = "bg-red-500"
387+
adjective = "Offline"
388+
} else {
389+
color = "bg-green-500"
390+
adjective = "Online"
391+
392+
for _, node := range status {
393+
totalRunTime += node.RunningTime
394+
accumulatedGXally += node.Point
395+
keyIDs = append(keyIDs, node.KeyID)
396+
397+
lastCheckTS := node.LastCheckTS
398+
lastCheckTime := time.Unix(lastCheckTS, 0)
399+
duration := time.Since(lastCheckTime).Round(time.Second)
400+
minutes := duration / time.Minute
401+
seconds := (duration % time.Minute) / time.Second
402+
403+
if minutes > 0 {
404+
lastUpdate = fmt.Sprintf("%dm %ds ago", minutes, seconds)
405+
} else {
406+
lastUpdate = fmt.Sprintf("%ds ago", seconds)
407+
}
408+
}
409+
410+
nodeIDs = strings.Join(keyIDs, ", ")
411+
}
412+
413+
tippyContent := fmt.Sprintf("<b>Node</b> - %s <br> <b>Owner</b> - %s<br> <b>Public IPv4</b> - %s <br> <b>Public IPv6</b> - %s", config.Node, config.Owner, config.IPv4, config.IPv6)
414+
415+
if len(status) == 0 {
416+
color = "bg-red-500"
417+
adjective = "Offline"
418+
tippyContent += fmt.Sprintf("<br> <b>Dashboard Version</b> - %s", config.NodeboxDashboardVersion)
419+
} else {
420+
color = "bg-green-500"
421+
adjective = "Online"
422+
tippyContent += fmt.Sprintf("<br> <b>Total Nodes</b> - %d (%s) <br> <b>Total Running Time</b> - %.2f <br> <b>Total gXally</b> - %.2f <br> <b>Last Data Update</b> - %s <br> <b>Dashboard Version</b> - %s", len(status), nodeIDs, totalRunTime, accumulatedGXally, lastUpdate, config.NodeboxDashboardVersion)
423+
}
424+
425+
activityTemplate = strings.Replace(activityTemplate, "ALPINE_TOOLTIP", fmt.Sprintf(`tooltip-data="%s"`, tippyContent), -1)
359426
return c.SendString(fmt.Sprintf(activityTemplate, color, adjective))
360427
} else {
361428
return c.SendString("")

0 commit comments

Comments
 (0)