improve
This commit is contained in:
		
							parent
							
								
									81b804ede9
								
							
						
					
					
						commit
						a25fe5fc9a
					
				@ -1,6 +1,6 @@
 | 
				
			|||||||
# 哪吒监控
 | 
					# 哪吒监控
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   
 | 
					   
 | 
				
			||||||
 | 
					
 | 
				
			||||||
:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。
 | 
					:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -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() {
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
				
			||||||
 | 
				
			|||||||
@ -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,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -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 {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user