Skip to content

Commit 136573b

Browse files
committed
feat: add host IP to deployment metadata dashboard
1 parent f3d902d commit 136573b

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

internal/handler/handler.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"html/template"
77
"log"
8+
"net"
89
"net/http"
910
"runtime"
1011
"time"
@@ -63,11 +64,25 @@ func (h *Handler) buildInfo() model.AppInfo {
6364
Environment: h.cfg.Environment,
6465
PodName: h.cfg.PodName,
6566
NodeName: h.cfg.NodeName,
67+
HostIP: getHostIP(),
6668
GoVersion: runtime.Version(),
6769
Uptime: formatUptime(time.Since(h.startTime)),
6870
}
6971
}
7072

73+
func getHostIP() string {
74+
addrs, err := net.InterfaceAddrs()
75+
if err != nil {
76+
return "unknown"
77+
}
78+
for _, addr := range addrs {
79+
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.To4() != nil {
80+
return ipnet.IP.String()
81+
}
82+
}
83+
return "unknown"
84+
}
85+
7186
func formatUptime(d time.Duration) string {
7287
days := int(d.Hours()) / 24
7388
hours := int(d.Hours()) % 24

internal/model/appinfo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type AppInfo struct {
77
Environment string `json:"environment"`
88
PodName string `json:"pod_name"`
99
NodeName string `json:"node_name"`
10+
HostIP string `json:"host_ip"`
1011
GoVersion string `json:"go_version"`
1112
Uptime string `json:"uptime"`
1213
}

web/templates/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ <h1>GitOps Sample App</h1>
146146
<td>Node</td>
147147
<td>{{.NodeName}}</td>
148148
</tr>
149+
<tr>
150+
<td>Host IP</td>
151+
<td>{{.HostIP}}</td>
152+
</tr>
149153
</table>
150154

151155
<div class="footer">

0 commit comments

Comments
 (0)