diff --git a/README.md b/README.md index 75620a9..72e088b 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,15 @@ -# 哪吒监控 +
+ +
+ +![GitHub Workflow Status](https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=管理面板%20v0.4.14&logo=github&style=for-the-badge) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge) ![shell](https://img.shields.io/badge/安装脚本-v0.4.9-brightgreen?style=for-the-badge&logo=linux) -![GitHub Workflow Status](https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=管理面板%20v0.4.13&logo=github&style=for-the-badge) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge) ![shell](https://img.shields.io/badge/安装脚本-v0.4.9-brightgreen?style=for-the-badge&logo=linux) :trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。 -
- -
- \>> QQ 交流群:955957790 -\>> [我们的用户](https://www.google.com/search?q="powered+by+哪吒"+"监控%7C面板"&filter=0) (Google) +\>> [我们的用户](https://www.google.com/search?q="powered+by+哪吒监控%7C哪吒面板"&filter=0) (Google) | 默认主题 | DayNight [@JackieSung](https://github.com/JackieSung4ev) | hotaru | | ------------------------------------------------------- | -------------------------------------------------------- | ---------------------------------------------------------------------- | diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 163a664..2239204 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -105,6 +105,8 @@ func run() { // 上报服务器信息 go reportState() + // 更新IP信息 + go monitor.UpdateIP() if version != "" { go func() { diff --git a/cmd/agent/monitor/monitor.go b/cmd/agent/monitor/monitor.go index 5088c89..178feb5 100644 --- a/cmd/agent/monitor/monitor.go +++ b/cmd/agent/monitor/monitor.go @@ -25,8 +25,41 @@ type ipDotSbGeoIP struct { } var netInSpeed, netOutSpeed, netInTransfer, netOutTransfer, lastUpdate uint64 -var cachedIP, country string -var latestFetchIP time.Time +var cachedIP, cachedCountry string + +func UpdateIP() { + var ip ipDotSbGeoIP + for { + var tempIP string + var tempCountry string + resp, err := http.Get("https://api-ipv4.ip.sb/geoip") + if err == nil { + defer resp.Body.Close() + body, _ := ioutil.ReadAll(resp.Body) + json.Unmarshal(body, &ip) + tempIP = ip.IP + tempCountry = ip.CountryCode + } else { + cachedIP = "" + } + time.Sleep(time.Second * 10) + resp, err = http.Get("https://api-ipv6.ip.sb/geoip") + if err == nil { + defer resp.Body.Close() + body, _ := ioutil.ReadAll(resp.Body) + json.Unmarshal(body, &ip) + if tempIP == "" { + tempIP = ip.IP + } else { + tempIP = fmt.Sprintf("ip(v4: %s, v6: %s)", tempIP, ip.IP) + } + tempCountry = ip.CountryCode + } + cachedIP = tempIP + cachedCountry = tempCountry + time.Sleep(time.Minute * 10) + } +} func GetHost() *model.Host { hi, _ := host.Info() @@ -49,33 +82,6 @@ func GetHost() *model.Host { ms, _ := mem.SwapMemory() u, _ := disk.Usage("/") - if latestFetchIP.Before(time.Now().Add(time.Minute * -15)) { - var ip ipDotSbGeoIP - latestFetchIP = time.Now() - resp, err := http.Get("https://api-ipv4.ip.sb/geoip") - if err == nil { - defer resp.Body.Close() - body, _ := ioutil.ReadAll(resp.Body) - json.Unmarshal(body, &ip) - cachedIP = ip.IP - country = ip.CountryCode - } else { - cachedIP = "" - } - resp, err = http.Get("https://api-ipv6.ip.sb/geoip") - if err == nil { - defer resp.Body.Close() - body, _ := ioutil.ReadAll(resp.Body) - json.Unmarshal(body, &ip) - if cachedIP == "" { - cachedIP = ip.IP - } else { - cachedIP = fmt.Sprintf("ip(v4: %s, v6: %s)", cachedIP, ip.IP) - } - country = ip.CountryCode - } - } - return &model.Host{ Platform: hi.OS, PlatformVersion: hi.PlatformVersion, @@ -87,7 +93,7 @@ func GetHost() *model.Host { Virtualization: hi.VirtualizationSystem, BootTime: hi.BootTime, IP: cachedIP, - CountryCode: strings.ToLower(country), + CountryCode: strings.ToLower(cachedCountry), Version: dao.Version, } } diff --git a/resource/template/common/header.html b/resource/template/common/header.html index 705b4ea..2f4d903 100644 --- a/resource/template/common/header.html +++ b/resource/template/common/header.html @@ -10,7 +10,7 @@ - + diff --git a/resource/template/common/menu.html b/resource/template/common/menu.html index fd0e469..e315049 100644 --- a/resource/template/common/menu.html +++ b/resource/template/common/menu.html @@ -2,7 +2,7 @@