use hostname+pid instead of ip
This commit is contained in:
parent
f7318cfc5a
commit
8abb04afde
|
@ -68,12 +68,21 @@ func MustLoad(fpaths ...string) {
|
||||||
|
|
||||||
if C.Heartbeat.IP == "" {
|
if C.Heartbeat.IP == "" {
|
||||||
// auto detect
|
// auto detect
|
||||||
C.Heartbeat.IP = fmt.Sprint(GetOutboundIP())
|
// C.Heartbeat.IP = fmt.Sprint(GetOutboundIP())
|
||||||
|
// 自动获取IP在有些环境下容易出错,这里用hostname+pid来作唯一标识
|
||||||
|
|
||||||
if C.Heartbeat.IP == "" {
|
hostname, err := os.Hostname()
|
||||||
fmt.Println("heartbeat ip auto got is blank")
|
if err != nil {
|
||||||
|
fmt.Println("failed to get hostname:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
C.Heartbeat.IP = hostname + "+" + fmt.Sprint(os.Getpid())
|
||||||
|
|
||||||
|
// if C.Heartbeat.IP == "" {
|
||||||
|
// fmt.Println("heartbeat ip auto got is blank")
|
||||||
|
// os.Exit(1)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
C.Heartbeat.Endpoint = fmt.Sprintf("%s:%d", C.Heartbeat.IP, C.HTTP.Port)
|
C.Heartbeat.Endpoint = fmt.Sprintf("%s:%d", C.Heartbeat.IP, C.HTTP.Port)
|
||||||
|
|
Loading…
Reference in New Issue