test port listen on 127.0.0.1 and identity.ip and ::1

This commit is contained in:
UlricQin 2020-12-23 15:57:11 +08:00
parent 28d311e759
commit ee96ce5046
3 changed files with 22 additions and 18 deletions

View File

@ -63,6 +63,11 @@ func main() {
loggeri.Init(config.Config.Logger)
stats.Init("agent")
if err := report.GatherBase(); err != nil {
fmt.Println("gatherBase fail: ", err)
os.Exit(1)
}
if config.Config.Enable.Mon {
monStart()
}
@ -76,7 +81,6 @@ func main() {
}
if config.Config.Enable.Metrics {
// 初始化 statsd服务
statsd.Start()
@ -90,11 +94,6 @@ func main() {
}
func reportStart() {
if err := report.GatherBase(); err != nil {
fmt.Println("gatherBase fail: ", err)
os.Exit(1)
}
go report.LoopReport()
}

View File

@ -19,9 +19,9 @@ import (
)
var (
sn string
ip string
ident string
SN string
IP string
Ident string
)
func LoopReport() {
@ -36,21 +36,21 @@ func LoopReport() {
func GatherBase() error {
var err error
sn, err = exec(config.Config.Report.SN)
SN, err = exec(config.Config.Report.SN)
if err != nil {
return fmt.Errorf("cannot get sn: %s", err)
}
ip, err = identity.GetIP()
IP, err = identity.GetIP()
if err != nil {
return fmt.Errorf("cannot get ip: %s", err)
}
if !str.IsIP(ip) {
return fmt.Errorf("'%s' not ip", ip)
if !str.IsIP(IP) {
return fmt.Errorf("'%s' not ip", IP)
}
ident, err = identity.GetIdent()
Ident, err = identity.GetIdent()
if err != nil {
return fmt.Errorf("cannot get ident: %s", err)
}
@ -98,9 +98,9 @@ func report() error {
}
form := hostRegisterForm{
SN: sn,
IP: ip,
Ident: ident,
SN: SN,
IP: IP,
Ident: Ident,
Name: name,
Cate: config.Config.Report.Cate,
UniqKey: config.Config.Report.UniqKey,

View File

@ -11,6 +11,7 @@ import (
"github.com/didi/nightingale/src/models"
"github.com/didi/nightingale/src/modules/agent/config"
"github.com/didi/nightingale/src/modules/agent/core"
"github.com/didi/nightingale/src/modules/agent/report"
)
type PortScheduler struct {
@ -46,7 +47,11 @@ func (p *PortScheduler) Stop() {
func PortCollect(p *models.PortCollect) {
value := 0
if isListening(p.Port) {
if isListen(p.Port, 1, "127.0.0.1") {
value = 1
} else if isListen(p.Port, 1, report.IP) {
value = 1
} else if isListen(p.Port, 1, "::1") {
value = 1
}