提交 ee96ce50 编写于 作者: U UlricQin

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

上级 28d311e7
......@@ -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()
}
......
......@@ -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,
......
......@@ -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
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册