improve
This commit is contained in:
parent
81b804ede9
commit
a25fe5fc9a
@ -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 监控报警,命令批量执行和计划任务。
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -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("/")
|
||||
|
||||
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/ip")
|
||||
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 == "" {
|
||||
ip.IP = string(body)
|
||||
cachedIP = string(body)
|
||||
} else {
|
||||
ip.IP = fmt.Sprintf("ip(v4: %s, v6: %s)", ip.IP, body)
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user