This commit is contained in:
naiba 2021-03-20 10:05:16 +08:00
parent 81b804ede9
commit a25fe5fc9a
5 changed files with 34 additions and 21 deletions

View File

@ -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 监控报警,命令批量执行和计划任务。 :trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。

View File

@ -61,7 +61,7 @@ func initSystem() {
} }
func cleanMonitorHistory() { 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() { func loadServers() {

View File

@ -13,7 +13,7 @@ import (
pb "github.com/naiba/nezha/proto" pb "github.com/naiba/nezha/proto"
) )
var Version = "v0.4.12" // !!记得修改 README 重的 badge 版本!! var Version = "v0.4.13" // !!记得修改 README 重的 badge 版本!!
const ( const (
SnapshotDelay = 3 SnapshotDelay = 3

View File

@ -26,6 +26,9 @@ type ipDotSbGeoIP struct {
var netInSpeed, netOutSpeed, netInTransfer, netOutTransfer, lastUpdate uint64 var netInSpeed, netOutSpeed, netInTransfer, netOutTransfer, lastUpdate uint64
var cachedIP, country string
var latestFetchIP time.Time
func GetHost() *model.Host { func GetHost() *model.Host {
hi, _ := host.Info() hi, _ := host.Info()
var cpuType string var cpuType string
@ -46,23 +49,31 @@ func GetHost() *model.Host {
mv, _ := mem.VirtualMemory() mv, _ := mem.VirtualMemory()
ms, _ := mem.SwapMemory() ms, _ := mem.SwapMemory()
u, _ := disk.Usage("/") u, _ := disk.Usage("/")
var ip ipDotSbGeoIP
resp, err := http.Get("https://api-ipv4.ip.sb/geoip") if latestFetchIP.Before(time.Now().Add(time.Minute * -15)) {
if err == nil { var ip ipDotSbGeoIP
defer resp.Body.Close() latestFetchIP = time.Now()
body, _ := ioutil.ReadAll(resp.Body) resp, err := http.Get("https://api-ipv4.ip.sb/geoip")
json.Unmarshal(body, &ip) if err == nil {
} defer resp.Body.Close()
resp, err = http.Get("https://api-ipv6.ip.sb/ip") body, _ := ioutil.ReadAll(resp.Body)
if err == nil { json.Unmarshal(body, &ip)
defer resp.Body.Close() cachedIP = ip.IP
body, _ := ioutil.ReadAll(resp.Body) country = ip.CountryCode
if ip.IP == "" { }
ip.IP = string(body) resp, err = http.Get("https://api-ipv6.ip.sb/geoip")
} else { if err == nil {
ip.IP = fmt.Sprintf("ip(v4: %s, v6: %s)", ip.IP, body) 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{ return &model.Host{
Platform: hi.OS, Platform: hi.OS,
PlatformVersion: hi.PlatformVersion, PlatformVersion: hi.PlatformVersion,
@ -73,8 +84,8 @@ func GetHost() *model.Host {
Arch: hi.KernelArch, Arch: hi.KernelArch,
Virtualization: hi.VirtualizationSystem, Virtualization: hi.VirtualizationSystem,
BootTime: hi.BootTime, BootTime: hi.BootTime,
IP: ip.IP, IP: cachedIP,
CountryCode: strings.ToLower(ip.CountryCode), CountryCode: strings.ToLower(country),
Version: dao.Version, Version: dao.Version,
} }
} }

View File

@ -26,7 +26,9 @@ func (s *NezhaHandler) ReportTask(c context.Context, r *pb.TaskResult) (*pb.Rece
var errMsg string var errMsg string
if strings.HasPrefix(r.GetData(), "SSL证书错误") { if strings.HasPrefix(r.GetData(), "SSL证书错误") {
// 排除 i/o timeont、connection timeout、EOF 错误 // 排除 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() errMsg = r.GetData()
} }
} else { } else {