diff --git a/README.md b/README.md index 0a53304..b7c167d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 哪吒监控 -![GitHub Workflow Status](https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=管理面板%20v0.4.12&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 监控报警,命令批量执行和计划任务。 diff --git a/cmd/dashboard/main.go b/cmd/dashboard/main.go index c36b729..934ccbf 100644 --- a/cmd/dashboard/main.go +++ b/cmd/dashboard/main.go @@ -61,7 +61,7 @@ func initSystem() { } func cleanMonitorHistory() { - dao.DB.Delete(&model.MonitorHistory{}, "created_at < ?", time.Now().AddDate(0, -1, 0)) + dao.DB.Delete(&model.MonitorHistory{}, "created_at < ?", time.Now().AddDate(0, 0, -30)) } func loadServers() { diff --git a/service/dao/dao.go b/service/dao/dao.go index 2386ece..368a342 100644 --- a/service/dao/dao.go +++ b/service/dao/dao.go @@ -13,7 +13,7 @@ import ( pb "github.com/naiba/nezha/proto" ) -var Version = "v0.4.12" // !!记得修改 README 重的 badge 版本!! +var Version = "v0.4.13" // !!记得修改 README 重的 badge 版本!! const ( SnapshotDelay = 3 diff --git a/service/monitor/monitor.go b/service/monitor/monitor.go index 11a7bd9..cd6c7c5 100644 --- a/service/monitor/monitor.go +++ b/service/monitor/monitor.go @@ -26,6 +26,9 @@ type ipDotSbGeoIP struct { var netInSpeed, netOutSpeed, netInTransfer, netOutTransfer, lastUpdate uint64 +var cachedIP, country string +var latestFetchIP time.Time + func GetHost() *model.Host { hi, _ := host.Info() var cpuType string @@ -46,23 +49,31 @@ func GetHost() *model.Host { mv, _ := mem.VirtualMemory() ms, _ := mem.SwapMemory() u, _ := disk.Usage("/") - var ip ipDotSbGeoIP - 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) - } - resp, err = http.Get("https://api-ipv6.ip.sb/ip") - if err == nil { - defer resp.Body.Close() - body, _ := ioutil.ReadAll(resp.Body) - if ip.IP == "" { - ip.IP = string(body) - } else { - ip.IP = fmt.Sprintf("ip(v4: %s, v6: %s)", ip.IP, body) + + 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 + } + resp, err = http.Get("https://api-ipv6.ip.sb/geoip") + if err == nil { + defer resp.Body.Close() + body, _ := ioutil.ReadAll(resp.Body) + if ip.IP == "" { + cachedIP = string(body) + } else { + cachedIP = fmt.Sprintf("ip(v4: %s, v6: %s)", ip.IP, body) + } + country = ip.CountryCode } } + return &model.Host{ Platform: hi.OS, PlatformVersion: hi.PlatformVersion, @@ -73,8 +84,8 @@ func GetHost() *model.Host { Arch: hi.KernelArch, Virtualization: hi.VirtualizationSystem, BootTime: hi.BootTime, - IP: ip.IP, - CountryCode: strings.ToLower(ip.CountryCode), + IP: cachedIP, + CountryCode: strings.ToLower(country), Version: dao.Version, } } diff --git a/service/rpc/nezha.go b/service/rpc/nezha.go index 23759ed..ac23add 100644 --- a/service/rpc/nezha.go +++ b/service/rpc/nezha.go @@ -26,7 +26,9 @@ func (s *NezhaHandler) ReportTask(c context.Context, r *pb.TaskResult) (*pb.Rece var errMsg string if strings.HasPrefix(r.GetData(), "SSL证书错误:") { // 排除 i/o timeont、connection timeout、EOF 错误 - if !strings.HasSuffix(r.GetData(), "timeout") && r.GetData() != "EOF" { + if !strings.HasSuffix(r.GetData(), "timeout") && + r.GetData() != "EOF" && + !strings.HasSuffix(r.GetData(), "timed out") { errMsg = r.GetData() } } else {