File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
7186func formatUptime (d time.Duration ) string {
7287 days := int (d .Hours ()) / 24
7388 hours := int (d .Hours ()) % 24
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 ">
You can’t perform that action at this time.
0 commit comments