diff --git a/etc/collector.yml b/etc/collector.yml index f1218cdd..8ba85351 100644 --- a/etc/collector.yml +++ b/etc/collector.yml @@ -4,7 +4,7 @@ logger: keepHours: 2 identity: specify: "" - shell: /usr/sbin/ifconfig `/usr/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1 + shell: ifconfig `route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|awk -F ':' '{print $NF}'|head -n 1 sys: # timeout in ms # interval in second diff --git a/etc/index.yml b/etc/index.yml index c65da2e8..736a4e03 100644 --- a/etc/index.yml +++ b/etc/index.yml @@ -4,4 +4,4 @@ logger: keepHours: 2 identity: specify: "" - shell: /usr/sbin/ifconfig `/usr/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1 + shell: ifconfig `route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|awk -F ':' '{print $NF}'|head -n 1 diff --git a/etc/judge.yml b/etc/judge.yml index cebec418..e86f7d39 100644 --- a/etc/judge.yml +++ b/etc/judge.yml @@ -14,9 +14,9 @@ redis: identity: specify: "" - shell: /usr/sbin/ifconfig `/usr/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1 + shell: ifconfig `route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|awk -F ':' '{print $NF}'|head -n 1 logger: dir: logs/judge level: WARNING - keepHours: 2 \ No newline at end of file + keepHours: 2 diff --git a/etc/port/20_2058 b/etc/port/20_2058 new file mode 100644 index 00000000..a8f83c1c --- /dev/null +++ b/etc/port/20_2058 @@ -0,0 +1 @@ +n9e-collector diff --git a/etc/port/20_22 b/etc/port/20_22 deleted file mode 100644 index 09920bc7..00000000 --- a/etc/port/20_22 +++ /dev/null @@ -1 +0,0 @@ -sshd \ No newline at end of file diff --git a/etc/port/20_5800 b/etc/port/20_5800 new file mode 100644 index 00000000..34878d81 --- /dev/null +++ b/etc/port/20_5800 @@ -0,0 +1 @@ +n9e-monapi diff --git a/etc/port/20_5810 b/etc/port/20_5810 new file mode 100644 index 00000000..87fd6ec8 --- /dev/null +++ b/etc/port/20_5810 @@ -0,0 +1 @@ +n9e-transfer \ No newline at end of file diff --git a/etc/port/20_5820 b/etc/port/20_5820 new file mode 100644 index 00000000..76765ebb --- /dev/null +++ b/etc/port/20_5820 @@ -0,0 +1 @@ +n9e-tsdb diff --git a/etc/port/20_5830 b/etc/port/20_5830 new file mode 100644 index 00000000..2fa1392b --- /dev/null +++ b/etc/port/20_5830 @@ -0,0 +1 @@ +n9e-index diff --git a/etc/port/20_5840 b/etc/port/20_5840 new file mode 100644 index 00000000..bd723305 --- /dev/null +++ b/etc/port/20_5840 @@ -0,0 +1 @@ +n9e-judge \ No newline at end of file diff --git a/src/modules/collector/config/config.go b/src/modules/collector/config/config.go index 427d0464..6b64419c 100644 --- a/src/modules/collector/config/config.go +++ b/src/modules/collector/config/config.go @@ -62,16 +62,16 @@ func Parse(conf string) error { "enable": true, "timeout": 1000, "interval": 10, //采集策略更新时间 - "portPath": "/home/n9e/etc/port", - "procPath": "/home/n9e/etc/proc", - "logPath": "/home/n9e/etc/log", + "portPath": "./etc/port", + "procPath": "./etc/proc", + "logPath": "./etc/log", "api": "/api/portal/collects/", }) viper.SetDefault("sys", map[string]interface{}{ "timeout": 1000, //请求超时时间 "interval": 10, //基础指标上报周期 - "plugin": "/home/n9e/plugin", + "plugin": "./plugin", }) err = viper.Unmarshal(&Config) diff --git a/src/modules/index/cache/tag_map.go b/src/modules/index/cache/tag_map.go index 205d5296..dba7a5c8 100644 --- a/src/modules/index/cache/tag_map.go +++ b/src/modules/index/cache/tag_map.go @@ -30,8 +30,9 @@ func (t *TagkvIndex) GetTagkv() []*TagPair { t.RLock() defer t.RUnlock() tagkvs := []*TagPair{} - var vs []string + for k, vm := range t.Tagkv { + var vs []string for v, _ := range vm { vs = append(vs, v) } @@ -50,8 +51,8 @@ func (t *TagkvIndex) GetTagkvMap() map[string][]string { defer t.RUnlock() tagkvs := make(map[string][]string) - var vs []string for k, vm := range t.Tagkv { + var vs []string for v, _ := range vm { vs = append(vs, v) } diff --git a/src/modules/index/http/routes/index_router.go b/src/modules/index/http/routes/index_router.go index c047d972..e5233fe9 100644 --- a/src/modules/index/http/routes/index_router.go +++ b/src/modules/index/http/routes/index_router.go @@ -93,9 +93,8 @@ func GetTagPairs(c *gin.Context) { resp := []*IndexTagkvResp{} - tagkvFilter := make(map[string]map[string]struct{}) - for _, metric := range recv.Metrics { + tagkvFilter := make(map[string]map[string]struct{}) tagkvs := []*cache.TagPair{} for _, endpoint := range recv.Endpoints { @@ -107,6 +106,7 @@ func GetTagPairs(c *gin.Context) { } tagkvMap := metricIndex.TagkvMap.GetTagkvMap() + for tagk, tagvs := range tagkvMap { tagvFilter, exists := tagkvFilter[tagk] if !exists { diff --git a/src/modules/monapi/cron/event_consumer.go b/src/modules/monapi/cron/event_consumer.go index 94610165..9207ff04 100644 --- a/src/modules/monapi/cron/event_consumer.go +++ b/src/modules/monapi/cron/event_consumer.go @@ -58,7 +58,7 @@ func consume(event *model.Event) { SetEventStatus(event, model.STATUS_UPGRADE) if needNotify { - if event.EventType == config.ALERT && NeedCallback(event.Sid) { + if NeedCallback(event.Sid) { if err := PushCallbackEvent(event); err != nil { logger.Errorf("push event to callback queue failed, callbackEvent: %+v", event) } @@ -82,7 +82,7 @@ func consume(event *model.Event) { return } - if event.EventType == config.ALERT && NeedCallback(event.Sid) { + if NeedCallback(event.Sid) { if err := PushCallbackEvent(event); err != nil { logger.Errorf("push event to callback queue failed, callbackEvent: %+v", event) } diff --git a/src/modules/transfer/http/routes/routes.go b/src/modules/transfer/http/routes/routes.go index d6e31563..cec93b7c 100644 --- a/src/modules/transfer/http/routes/routes.go +++ b/src/modules/transfer/http/routes/routes.go @@ -18,7 +18,7 @@ func Config(r *gin.Engine) { sys.GET("/alive-judges", judges) sys.POST("/push", PushData) - sys.POST("/data", QueryDataForJudge) + sys.POST("/data", QueryData) sys.POST("/data/ui", QueryDataForUI) } diff --git a/src/toolkits/stats/init.go b/src/toolkits/stats/init.go index 3ef9bca6..9b74917d 100644 --- a/src/toolkits/stats/init.go +++ b/src/toolkits/stats/init.go @@ -3,12 +3,17 @@ package stats import ( "bytes" "encoding/json" + "fmt" "net/http" + "path" "time" "github.com/didi/nightingale/src/dataobj" + "github.com/didi/nightingale/src/toolkits/address" + "github.com/toolkits/pkg/file" "github.com/toolkits/pkg/logger" + "github.com/toolkits/pkg/runner" ) var ( @@ -16,8 +21,14 @@ var ( ) func Init(prefix string, addr ...string) { - if len(addr) > 0 { + if len(addr) > 0 && addr[0] != "" { + //如果配置了 addr,使用 addr 参数 PushUrl = addr[0] + + } else if file.IsExist(path.Join(runner.Cwd, "etc", "address.yml")) { + //address.yml 存在,则使用配置文件的地址 + port := address.GetHTTPPort("collector") + PushUrl = fmt.Sprintf("http://127.0.0.1:%d/api/collector/push", port) } Counter = NewCounter(prefix)