Skip to content

Commit

Permalink
更换LOGO、优化获取IP策略
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Mar 20, 2021
1 parent 3aba6a4 commit 8acf992
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 48 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# 哪吒监控
<div align="center" style="background-color: white">
<img width="500" style="max-width:100%" src="https://raw.githubusercontent.com/naiba/nezha/master/resource/static/brand.png" title="哪吒监控">
</div>

![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)
![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)

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

<div align="center">
<img width="500" style="max-width:100%" src="https://raw.githubusercontent.com/naiba/nezha/master/resource/static/brand.png">
</div>
: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 |
| ------------------------------------------------------- | -------------------------------------------------------- | ---------------------------------------------------------------------- |
Expand Down
2 changes: 2 additions & 0 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func run() {

// 上报服务器信息
go reportState()
// 更新IP信息
go monitor.UpdateIP()

if version != "" {
go func() {
Expand Down
66 changes: 36 additions & 30 deletions cmd/agent/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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,
}
}
Expand Down
2 changes: 1 addition & 1 deletion resource/template/common/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css">
<link rel="stylesheet" type="text/css" href="/static/semantic-ui-alerts.min.css">
<link rel="stylesheet" type="text/css" href="/static/main.css?v202102051040">
<link rel="shortcut icon" type="image/png" href="/static/logo.png" />
<link rel="shortcut icon" type="image/png" href="/static/logo.png?v20210320" />
</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion resource/template/common/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="ui large top fixed menu nb-menu">
<div class="ui container">
<div class="item">
<img src="/static/logo.png">
<img src="/static/logo.png?v20210320">
</div>
{{if .IsAdminPage}}
<a class='item{{if eq .MatchedPath "/server"}} active{{end}}' href="/server"><i class="server icon"></i>资产</a>
Expand Down
2 changes: 1 addition & 1 deletion resource/template/dashboard/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="ui center aligned grid">
<div class="column">
<h2 class="ui teal image header">
<img src="/static/logo.png" class="image">
<img src="/static/logo.png?v20210320" class="image">
<div class="content">
访问受限
</div>
Expand Down
2 changes: 1 addition & 1 deletion resource/template/dashboard/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="ui center aligned grid">
<div class="column">
<h2 class="ui teal image header">
<img src="static/logo.png" class="image">
<img src="static/logo.png?v20210320" class="image">
<div class="content">
使用 GitHub 账号登录
</div>
Expand Down
2 changes: 1 addition & 1 deletion resource/template/theme-daynight/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>{{.Title}}</title>
<link rel="shortcut icon" type="image/png" href="/static/logo.png" />
<link rel="shortcut icon" type="image/png" href="/static/logo.png?v20210320" />

<link rel="stylesheet" href="/static/theme-daynight/css/main.css?v202103202286">
<link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.1/css/all.min.css" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion resource/template/theme-daynight/service.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{.Title}}</title>
<link rel="shortcut icon" type="image/png" href="/static/logo.png" />
<link rel="shortcut icon" type="image/png" href="/static/logo.png?v20210320" />
<link rel="stylesheet" href="/static/theme-daynight/css/service.css?v202103202286" />

<link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.1/css/all.min.css" rel="stylesheet" />
Expand Down
2 changes: 1 addition & 1 deletion resource/template/theme-daynight/viewpassword.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>{{.Title}}</title>
<link rel="shortcut icon" type="image/png" href="/static/logo.png" />
<link rel="shortcut icon" type="image/png" href="/static/logo.png?v20210320" />
<link rel="stylesheet" href="/static/theme-daynight/css/passwd.css?v202103202286" />

{{if ts .CustomCode}}
Expand Down
2 changes: 1 addition & 1 deletion resource/template/theme-default/viewpassword.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="ui center aligned grid">
<div class="column">
<h2 class="ui teal image header">
<img src="static/logo.png" class="image">
<img src="static/logo.png?v20210320" class="image">
<div class="content">
验证查看密码
</div>
Expand Down
2 changes: 1 addition & 1 deletion resource/template/theme-hotaru/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>{{.Title}}</title>
<link rel="shortcut icon" type="image/png" href="/static/logo.png" />
<link rel="shortcut icon" type="image/png" href="/static/logo.png?v20210320" />

<!-- Fix chrome language detection -->
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
Expand Down
2 changes: 1 addition & 1 deletion resource/template/theme-hotaru/viewpassword.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="ui center aligned grid">
<div class="column">
<h2 class="ui teal image header">
<img src="static/logo.png" class="image">
<img src="static/logo.png?v20210320" class="image">
<div class="content">
验证查看密码
</div>
Expand Down
2 changes: 1 addition & 1 deletion service/dao/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
pb "github.com/naiba/nezha/proto"
)

var Version = "v0.4.13" // !!记得修改 README 重的 badge 版本!!
var Version = "v0.4.14" // !!记得修改 README 重的 badge 版本!!

const (
SnapshotDelay = 3
Expand Down

0 comments on commit 8acf992

Please sign in to comment.