Skip to content

Commit 1761440

Browse files
committed
feat(logging): Warn users to remember adding endpoint to Checkmate Infrastructure Dashboard
Signed-off-by: Mert Şişmanoğlu <[email protected]>
1 parent ef5b236 commit 1761440

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cmd/capture/main.go

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"flag"
66
"fmt"
77
"log"
8+
"net"
89
"net/http"
910
"os"
1011
"os/signal"
@@ -21,6 +22,25 @@ var appConfig *config.Config
2122

2223
var Version = "develop" // This will be set during compile time using go build ldflags
2324

25+
// getLocalIP retrieves the local IP address of the machine.
26+
// It returns the first non-loopback IPv4 address found.
27+
// If no valid address is found, it returns "<ip-address>" as a placeholder.
28+
// This function is used to display the local IP address in the log message.
29+
func getLocalIP() string {
30+
addrs, err := net.InterfaceAddrs()
31+
if err != nil {
32+
return "<ip-address>"
33+
}
34+
for _, addr := range addrs {
35+
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
36+
if ipnet.IP.To4() != nil {
37+
return ipnet.IP.String()
38+
}
39+
}
40+
}
41+
return "<ip-address>"
42+
}
43+
2444
func main() {
2545
showVersion := flag.Bool("version", false, "Display the version of the capture")
2646
flag.Parse()
@@ -52,6 +72,8 @@ func main() {
5272
apiV1.GET("/metrics/host", handler.MetricsHost)
5373
apiV1.GET("/metrics/smart", handler.SmartMetrics)
5474

75+
log.Println("WARNING: Remember to add http://" + getLocalIP() + ":" + appConfig.Port + "/api/v1/metrics to your Checkmate Infrastructure Dashboard. Without this endpoint, system metrics will not be displayed.")
76+
5577
server := &http.Server{
5678
Addr: ":" + appConfig.Port,
5779
Handler: r.Handler(),

0 commit comments

Comments
 (0)