code refactor: stats.init

This commit is contained in:
UlricQin 2020-09-22 10:42:50 +08:00
parent bc884175be
commit 9cb3bd564b
1 changed files with 6 additions and 2 deletions

View File

@ -24,11 +24,15 @@ func Init(prefix string, addr ...string) {
if len(addr) > 0 && addr[0] != "" {
//如果配置了 addr使用 addr 参数
PushUrl = addr[0]
} else if file.IsExist(path.Join(runner.Cwd, "etc", "address.yml")) {
//address.yml 存在,则使用配置文件的地址
newAddr := address.GetHTTPAddresses("collector")
PushUrl = fmt.Sprintf("http://%s/api/collector/push", newAddr[0])
if len(newAddr) == 0 {
port := address.GetHTTPPort("collector")
PushUrl = fmt.Sprintf("http://127.0.0.1:%d/api/collector/push", port)
} else {
PushUrl = fmt.Sprintf("http://%s/api/collector/push", newAddr[0])
}
}
Counter = NewCounter(prefix)