Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d4245ee09 | ||
|
|
8df863a3e0 | ||
|
|
07e0382598 | ||
|
|
8dd509aa08 | ||
|
|
99ac12c9fd | ||
|
|
ebc45f9b8f | ||
|
|
3b5ee464a7 | ||
|
|
c4b2c47beb | ||
|
|
0835f13f28 | ||
|
|
ee3cda8aed | ||
|
|
604fc7d4c0 | ||
|
|
5c549261dd | ||
|
|
00041c0ebd | ||
|
|
dbfea9a00b | ||
|
|
e8b208edfa | ||
|
|
7d38634933 | ||
|
|
5bd4b57cbf | ||
|
|
fdb2fd8839 | ||
|
|
f3fac9325c | ||
|
|
626613441d | ||
|
|
b86b73a433 | ||
|
|
e8b8e59bd7 | ||
|
|
c9bcba6f28 | ||
|
|
ad9dc5470a | ||
|
|
8539fb6559 | ||
|
|
11bcc47d49 | ||
|
|
bb789f7652 | ||
|
|
51c1e41123 | ||
|
|
83efdc6258 | ||
|
|
bf58ad24b5 | ||
|
|
53581d48fc | ||
|
|
b00a00e791 | ||
|
|
b91f29077c | ||
|
|
99111a3115 | ||
|
|
30652c3d79 | ||
|
|
ac0103a1ee | ||
|
|
f59b31590e | ||
|
|
1bcddf1944 | ||
|
|
d790ca04d6 | ||
|
|
2106ca41e1 | ||
|
|
927bf13ce4 | ||
|
|
859e263815 | ||
|
|
1dcd899591 | ||
|
|
3059bf2d49 | ||
|
|
74255717ef | ||
|
|
8fa59a4639 | ||
|
|
b3e38e8924 | ||
|
|
2280e0267c | ||
|
|
1871c481e4 | ||
|
|
c3d1eec6bf | ||
|
|
6fc8ec9446 | ||
|
|
52703f38cd | ||
|
|
d0707b9b05 | ||
|
|
ad99a5d032 |
@@ -35,7 +35,7 @@ jobs:
|
||||
|
||||
- name: fix dist
|
||||
run: |
|
||||
cp dist/dashboard-linux-arm-7 dist/dashboard-linux-arm
|
||||
mv dist/dashboard-linux-arm-7 dist/dashboard-linux-arm
|
||||
|
||||
- name: Log in to the GHCR
|
||||
uses: docker/login-action@master
|
||||
|
||||
@@ -11,6 +11,6 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: adambirds/[email protected]
|
||||
with:
|
||||
destination_repository: git@jihulab.com:nezha/dashboard.git
|
||||
destination_repository: git@gitee.com:naibahq/nezha.git
|
||||
destination_branch_name: master
|
||||
destination_ssh_key: ${{ secrets.GITLAB_SSH_KEY }}
|
||||
|
||||
@@ -4,14 +4,12 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths-ignore:
|
||||
- ".github/workflows/codeql-analysis.yml"
|
||||
- ".github/workflows/test-on-pr.yml"
|
||||
- ".github/workflows/contributors.yml"
|
||||
- ".github/workflows/sync.yml"
|
||||
- ".github/workflows/release.yml"
|
||||
- "README.md"
|
||||
- ".goreleaser.yml"
|
||||
paths:
|
||||
- "**.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- "resource/**"
|
||||
- ".github/workflows/test.yml"
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
|
||||
+1
-1
@@ -19,4 +19,4 @@
|
||||
/cmd/dashboard/main
|
||||
/config.yml
|
||||
/resource/template/theme-custom
|
||||
/resource/static/theme-custom
|
||||
/resource/static/custom
|
||||
|
||||
+10
-10
@@ -1,18 +1,18 @@
|
||||
FROM ubuntu:focal-20221130
|
||||
|
||||
ENV TZ="Asia/Shanghai"
|
||||
# latest 镜像还没有 riscv64 https://hub.docker.com/_/alpine/tags
|
||||
FROM alpine:edge
|
||||
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
|
||||
COPY ./script/entrypoint.sh /entrypoint.sh
|
||||
RUN apk update && \
|
||||
apk upgrade --no-cache && \
|
||||
apk add --no-cache tzdata && \
|
||||
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
||||
echo 'Asia/Shanghai' >/etc/timezone && \
|
||||
rm -rf /var/cache/apk/*
|
||||
|
||||
RUN export DEBIAN_FRONTEND="noninteractive" && \
|
||||
apt update && apt install -y ca-certificates tzdata && \
|
||||
update-ca-certificates && \
|
||||
ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && \
|
||||
dpkg-reconfigure tzdata && \
|
||||
chmod +x /entrypoint.sh
|
||||
COPY ./script/entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
WORKDIR /dashboard
|
||||
COPY dist/dashboard-${TARGETOS}-${TARGETARCH} ./app
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<br>
|
||||
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
|
||||
<br><br>
|
||||
<img alt="GitHub release (with filter)" src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&style=for-the-badge&logo=github&label=Dashboard"> <img src="https://img.shields.io/github/v/release/nezhahq/agent?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/actions/workflow/status/nezhahq/agent/agent.yml?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.15.0-brightgreen?style=for-the-badge&logo=linux">
|
||||
<img alt="GitHub release (with filter)" src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&style=for-the-badge&logo=github&label=Dashboard"> <img src="https://img.shields.io/github/v/release/nezhahq/agent?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/actions/workflow/status/nezhahq/agent/agent.yml?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.15.8-brightgreen?style=for-the-badge&logo=linux">
|
||||
<br>
|
||||
<br>
|
||||
<p>:trollface: <b>Nezha Monitoring: Self-hostable, lightweight, servers and websites monitoring and O&M tool.</b></p>
|
||||
@@ -65,80 +65,107 @@ You can change the dashboard language in the settings page (`/setting`) after th
|
||||
<a href="https://github.com/cantoblanco" title="Kris">
|
||||
<img src="https://avatars.githubusercontent.com/u/116849421?v=4" width="50;" alt="Kris"/>
|
||||
</a>
|
||||
<a href="https://github.com/CosmosZ-code" title="CosmosZ-code">
|
||||
<img src="https://avatars.githubusercontent.com/u/81398224?v=4" width="50;" alt="CosmosZ-code"/>
|
||||
<a href="https://github.com/spiritLHLS" title="spiritlhl">
|
||||
<img src="https://avatars.githubusercontent.com/u/103393591?v=4" width="50;" alt="spiritlhl"/>
|
||||
</a>
|
||||
<a href="https://github.com/liuyanxi975" title="刘颜溪">
|
||||
<img src="https://avatars.githubusercontent.com/u/24417037?v=4" width="50;" alt="刘颜溪"/>
|
||||
</a>
|
||||
<a href="https://github.com/CosmosZ-code" title="CosmosZ-code">
|
||||
<img src="https://avatars.githubusercontent.com/u/81398224?v=4" width="50;" alt="CosmosZ-code"/>
|
||||
</a>
|
||||
<a href="https://github.com/uubulb" title="UUBulb">
|
||||
<img src="https://avatars.githubusercontent.com/u/35923940?v=4" width="50;" alt="UUBulb"/>
|
||||
</a>
|
||||
<a href="https://github.com/lvgj-stack" title="Ko no dio">
|
||||
<img src="https://avatars.githubusercontent.com/u/38449861?v=4" width="50;" alt="Ko no dio"/>
|
||||
</a>
|
||||
<a href="https://github.com/hhhkkk520" title="Kris">
|
||||
<img src="https://avatars.githubusercontent.com/u/52115472?v=4" width="50;" alt="Kris"/>
|
||||
</a>
|
||||
<a href="https://github.com/spiritLHLS" title="spiritlhl">
|
||||
<img src="https://avatars.githubusercontent.com/u/103393591?v=4" width="50;" alt="spiritlhl"/>
|
||||
</a>
|
||||
<a href="https://github.com/rootmelo92118" title="rootmelo92118">
|
||||
<img src="https://avatars.githubusercontent.com/u/32770959?v=4" width="50;" alt="rootmelo92118"/>
|
||||
</a>
|
||||
<a href="https://github.com/1ridic" title="1ridic">
|
||||
<img src="https://avatars.githubusercontent.com/u/88495501?v=4" width="50;" alt="1ridic"/>
|
||||
</a>
|
||||
<a href="https://github.com/coreff" title="Core F">
|
||||
<img src="https://avatars.githubusercontent.com/u/38347122?v=4" width="50;" alt="Core F"/>
|
||||
<a href="https://github.com/Mmx233" title="Mmx">
|
||||
<img src="https://avatars.githubusercontent.com/u/36563672?v=4" width="50;" alt="Mmx"/>
|
||||
</a>
|
||||
<a href="https://github.com/Creling" title="Creling">
|
||||
<img src="https://avatars.githubusercontent.com/u/43109504?v=4" width="50;" alt="Creling"/>
|
||||
</a>
|
||||
<a href="https://github.com/ch8o" title="no-name-now">
|
||||
<img src="https://avatars.githubusercontent.com/u/9103372?v=4" width="50;" alt="no-name-now"/>
|
||||
</a>
|
||||
<a href="https://github.com/fscarmen" title="fscarmen">
|
||||
<img src="https://avatars.githubusercontent.com/u/62703343?v=4" width="50;" alt="fscarmen"/>
|
||||
<a href="https://github.com/rootmelo92118" title="rootmelo92118">
|
||||
<img src="https://avatars.githubusercontent.com/u/32770959?v=4" width="50;" alt="rootmelo92118"/>
|
||||
</a>
|
||||
<a href="https://github.com/iilemon" title="Sean">
|
||||
<img src="https://avatars.githubusercontent.com/u/33201711?v=4" width="50;" alt="Sean"/>
|
||||
</a>
|
||||
<a href="https://github.com/Es-dese" title="Esdese">
|
||||
<img src="https://avatars.githubusercontent.com/u/71542548?v=4" width="50;" alt="Esdese"/>
|
||||
<a href="https://github.com/fscarmen" title="fscarmen">
|
||||
<img src="https://avatars.githubusercontent.com/u/62703343?v=4" width="50;" alt="fscarmen"/>
|
||||
</a>
|
||||
<a href="https://github.com/GreenTeodoro839" title="GreenTeodoro839">
|
||||
<img src="https://avatars.githubusercontent.com/u/77104800?v=4" width="50;" alt="GreenTeodoro839"/>
|
||||
<a href="https://github.com/ch8o" title="no-name-now">
|
||||
<img src="https://avatars.githubusercontent.com/u/9103372?v=4" width="50;" alt="no-name-now"/>
|
||||
</a>
|
||||
<a href="https://github.com/techotaku" title="Ian Li">
|
||||
<img src="https://avatars.githubusercontent.com/u/1948179?v=4" width="50;" alt="Ian Li"/>
|
||||
<a href="https://github.com/Creling" title="Creling">
|
||||
<img src="https://avatars.githubusercontent.com/u/43109504?v=4" width="50;" alt="Creling"/>
|
||||
</a>
|
||||
<a href="https://github.com/KorenKrita" title="KorenKrita">
|
||||
<img src="https://avatars.githubusercontent.com/u/22239339?v=4" width="50;" alt="KorenKrita"/>
|
||||
<a href="https://github.com/coreff" title="Core F">
|
||||
<img src="https://avatars.githubusercontent.com/u/38347122?v=4" width="50;" alt="Core F"/>
|
||||
</a>
|
||||
<a href="https://github.com/MartijnLindeman" title="Martijn Lindeman">
|
||||
<img src="https://avatars.githubusercontent.com/u/78365708?v=4" width="50;" alt="Martijn Lindeman"/>
|
||||
<a href="https://github.com/colour93" title="玖叁">
|
||||
<img src="https://avatars.githubusercontent.com/u/64313711?v=4" width="50;" alt="玖叁"/>
|
||||
</a>
|
||||
<a href="https://github.com/nickfox-taterli" title="Tater Li">
|
||||
<img src="https://avatars.githubusercontent.com/u/19658596?v=4" width="50;" alt="Tater Li"/>
|
||||
</a>
|
||||
<a href="https://github.com/hmsjy2017" title="Tony">
|
||||
<img src="https://avatars.githubusercontent.com/u/42692274?v=4" width="50;" alt="Tony"/>
|
||||
</a>
|
||||
<a href="https://github.com/adminsama" title="adminsama">
|
||||
<img src="https://avatars.githubusercontent.com/u/60880076?v=4" width="50;" alt="adminsama"/>
|
||||
</a>
|
||||
<a href="https://github.com/acgpiano" title="Acgpiano">
|
||||
<img src="https://avatars.githubusercontent.com/u/15900800?v=4" width="50;" alt="Acgpiano"/>
|
||||
</a>
|
||||
<a href="https://github.com/guoyongchang" title="guoyongchang">
|
||||
<img src="https://avatars.githubusercontent.com/u/10484506?v=4" width="50;" alt="guoyongchang"/>
|
||||
</a>
|
||||
<a href="https://github.com/yuanweize" title="I">
|
||||
<img src="https://avatars.githubusercontent.com/u/30067203?v=4" width="50;" alt="I"/>
|
||||
</a>
|
||||
<a href="https://github.com/unclezs" title="unclezs">
|
||||
<img src="https://avatars.githubusercontent.com/u/42318775?v=4" width="50;" alt="unclezs"/>
|
||||
<a href="https://github.com/arkylin" title="凌">
|
||||
<img src="https://avatars.githubusercontent.com/u/35104502?v=4" width="50;" alt="凌"/>
|
||||
</a>
|
||||
<a href="https://github.com/ysicing" title="缘生">
|
||||
<img src="https://avatars.githubusercontent.com/u/8605565?v=4" width="50;" alt="缘生"/>
|
||||
</a>
|
||||
<a href="https://github.com/colour93" title="玖叁">
|
||||
<img src="https://avatars.githubusercontent.com/u/64313711?v=4" width="50;" alt="玖叁"/>
|
||||
<a href="https://github.com/xykt" title="xykt">
|
||||
<img src="https://avatars.githubusercontent.com/u/152045469?v=4" width="50;" alt="xykt"/>
|
||||
</a>
|
||||
<a href="https://github.com/unclezs" title="unclezs">
|
||||
<img src="https://avatars.githubusercontent.com/u/42318775?v=4" width="50;" alt="unclezs"/>
|
||||
</a>
|
||||
<a href="https://github.com/nap0o" title="nap0o">
|
||||
<img src="https://avatars.githubusercontent.com/u/144927971?v=4" width="50;" alt="nap0o"/>
|
||||
</a>
|
||||
<a href="https://github.com/yuanweize" title="I">
|
||||
<img src="https://avatars.githubusercontent.com/u/30067203?v=4" width="50;" alt="I"/>
|
||||
</a>
|
||||
<a href="https://github.com/guoyongchang" title="guoyongchang">
|
||||
<img src="https://avatars.githubusercontent.com/u/10484506?v=4" width="50;" alt="guoyongchang"/>
|
||||
</a>
|
||||
<a href="https://github.com/acgpiano" title="Acgpiano">
|
||||
<img src="https://avatars.githubusercontent.com/u/15900800?v=4" width="50;" alt="Acgpiano"/>
|
||||
</a>
|
||||
<a href="https://github.com/adminsama" title="adminsama">
|
||||
<img src="https://avatars.githubusercontent.com/u/60880076?v=4" width="50;" alt="adminsama"/>
|
||||
</a>
|
||||
<a href="https://github.com/hmsjy2017" title="Tony">
|
||||
<img src="https://avatars.githubusercontent.com/u/42692274?v=4" width="50;" alt="Tony"/>
|
||||
</a>
|
||||
<a href="https://github.com/nickfox-taterli" title="Tater Li">
|
||||
<img src="https://avatars.githubusercontent.com/u/19658596?v=4" width="50;" alt="Tater Li"/>
|
||||
</a>
|
||||
<a href="https://github.com/MartijnLindeman" title="Martijn Lindeman">
|
||||
<img src="https://avatars.githubusercontent.com/u/78365708?v=4" width="50;" alt="Martijn Lindeman"/>
|
||||
</a>
|
||||
<a href="https://github.com/KorenKrita" title="KorenKrita">
|
||||
<img src="https://avatars.githubusercontent.com/u/22239339?v=4" width="50;" alt="KorenKrita"/>
|
||||
</a>
|
||||
<a href="https://github.com/techotaku" title="Ian Li">
|
||||
<img src="https://avatars.githubusercontent.com/u/1948179?v=4" width="50;" alt="Ian Li"/>
|
||||
</a>
|
||||
<a href="https://github.com/HsukqiLee" title="HsukqiLee">
|
||||
<img src="https://avatars.githubusercontent.com/u/79034142?v=4" width="50;" alt="HsukqiLee"/>
|
||||
</a>
|
||||
<a href="https://github.com/GreenTeodoro839" title="GreenTeodoro839">
|
||||
<img src="https://avatars.githubusercontent.com/u/77104800?v=4" width="50;" alt="GreenTeodoro839"/>
|
||||
</a>
|
||||
<a href="https://github.com/Es-dese" title="Esdese">
|
||||
<img src="https://avatars.githubusercontent.com/u/71542548?v=4" width="50;" alt="Esdese"/>
|
||||
</a>
|
||||
<a href="https://github.com/DarcJC" title="Darc Z.">
|
||||
<img src="https://avatars.githubusercontent.com/u/53445798?v=4" width="50;" alt="Darc Z."/>
|
||||
</a>
|
||||
<a href="https://github.com/wwng2333" title="Crazy">
|
||||
<img src="https://avatars.githubusercontent.com/u/17147265?v=4" width="50;" alt="Crazy"/>
|
||||
</a><!--GAMFC_DELIMITER_END-->
|
||||
|
||||
## Star History
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/naiba/nezha/pkg/mygin"
|
||||
"github.com/naiba/nezha/service/singleton"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
"github.com/naiba/nezha/pkg/mygin"
|
||||
"github.com/naiba/nezha/service/singleton"
|
||||
)
|
||||
|
||||
type apiV1 struct {
|
||||
@@ -14,18 +17,29 @@ type apiV1 struct {
|
||||
|
||||
func (v *apiV1) serve() {
|
||||
r := v.r.Group("")
|
||||
// API
|
||||
// 强制认证的 API
|
||||
r.Use(mygin.Authorize(mygin.AuthorizeOption{
|
||||
Member: true,
|
||||
IsPage: false,
|
||||
AllowAPI: true,
|
||||
Msg: "访问此接口需要认证",
|
||||
Btn: "点此登录",
|
||||
Redirect: "/login",
|
||||
MemberOnly: true,
|
||||
AllowAPI: true,
|
||||
IsPage: false,
|
||||
Msg: "访问此接口需要认证",
|
||||
Btn: "点此登录",
|
||||
Redirect: "/login",
|
||||
}))
|
||||
r.GET("/server/list", v.serverList)
|
||||
r.GET("/server/details", v.serverDetails)
|
||||
|
||||
// 不强制认证的 API
|
||||
mr := v.r.Group("monitor")
|
||||
mr.Use(mygin.Authorize(mygin.AuthorizeOption{
|
||||
MemberOnly: false,
|
||||
IsPage: false,
|
||||
ValidateViewPassword: true,
|
||||
AllowAPI: true,
|
||||
Msg: "访问此接口需要认证",
|
||||
Btn: "点此登录",
|
||||
Redirect: "/login",
|
||||
}))
|
||||
mr.GET("/:id", v.monitorHistoriesById)
|
||||
}
|
||||
|
||||
// serverList 获取服务器列表 不传入Query参数则获取全部
|
||||
@@ -65,3 +79,31 @@ func (v *apiV1) serverDetails(c *gin.Context) {
|
||||
}
|
||||
c.JSON(200, singleton.ServerAPI.GetAllStatus())
|
||||
}
|
||||
|
||||
func (v *apiV1) monitorHistoriesById(c *gin.Context) {
|
||||
idStr := c.Param("id")
|
||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(400, gin.H{"code": 400, "message": "id参数错误"})
|
||||
return
|
||||
}
|
||||
server, ok := singleton.ServerList[id]
|
||||
if !ok {
|
||||
c.AbortWithStatusJSON(404, gin.H{
|
||||
"code": 404,
|
||||
"message": "id不存在",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
_, isMember := c.Get(model.CtxKeyAuthorizedUser)
|
||||
_, isViewPasswordVerfied := c.Get(model.CtxKeyViewPasswordVerified)
|
||||
authorized := isMember || isViewPasswordVerfied
|
||||
|
||||
if server.HideForGuest && !authorized {
|
||||
c.AbortWithStatusJSON(403, gin.H{"code": 403, "message": "需要认证"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, singleton.MonitorAPI.GetMonitorHistories(map[string]any{"server_id": server.ID}))
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -42,12 +43,17 @@ type commonPage struct {
|
||||
|
||||
func (cp *commonPage) serve() {
|
||||
cr := cp.r.Group("")
|
||||
cr.Use(mygin.Authorize(mygin.AuthorizeOption{}))
|
||||
cr.Use(mygin.Authorize(mygin.AuthorizeOption{
|
||||
ValidateViewPassword: true,
|
||||
}))
|
||||
cr.Use(mygin.PreferredTheme)
|
||||
cr.GET("/terminal/:id", cp.terminal)
|
||||
cr.POST("/view-password", cp.issueViewPassword)
|
||||
cr.Use(cp.checkViewPassword) // 前端查看密码鉴权
|
||||
cr.GET("/", cp.home)
|
||||
cr.GET("/service", cp.service)
|
||||
// TODO: 界面直接跳转使用该接口
|
||||
cr.GET("/network/:id", cp.network)
|
||||
cr.GET("/network", cp.network)
|
||||
cr.GET("/ws", cp.ws)
|
||||
cr.POST("/terminal", cp.createTerminal)
|
||||
}
|
||||
@@ -81,31 +87,6 @@ func (p *commonPage) issueViewPassword(c *gin.Context) {
|
||||
c.Redirect(http.StatusFound, c.Request.Referer())
|
||||
}
|
||||
|
||||
func (p *commonPage) checkViewPassword(c *gin.Context) {
|
||||
if singleton.Conf.Site.ViewPassword == "" {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
if _, authorized := c.Get(model.CtxKeyAuthorizedUser); authorized {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
// 验证查看密码
|
||||
viewPassword, _ := c.Cookie(singleton.Conf.Site.CookieName + "-vp")
|
||||
if err := bcrypt.CompareHashAndPassword([]byte(viewPassword), []byte(singleton.Conf.Site.ViewPassword)); err != nil {
|
||||
c.HTML(http.StatusOK, "theme-"+singleton.Conf.Site.Theme+"/viewpassword", mygin.CommonEnvironment(c, gin.H{
|
||||
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "VerifyPassword"}),
|
||||
"CustomCode": singleton.Conf.Site.CustomCode,
|
||||
}))
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Set(model.CtxKeyViewPasswordVerified, true)
|
||||
c.Next()
|
||||
}
|
||||
|
||||
func (p *commonPage) service(c *gin.Context) {
|
||||
res, _, _ := p.requestGroup.Do("servicePage", func() (interface{}, error) {
|
||||
singleton.AlertsLock.RLock()
|
||||
@@ -114,12 +95,17 @@ func (p *commonPage) service(c *gin.Context) {
|
||||
var statsStore map[uint64]model.CycleTransferStats
|
||||
copier.Copy(&stats, singleton.ServiceSentinelShared.LoadStats())
|
||||
copier.Copy(&statsStore, singleton.AlertsCycleTransferStatsStore)
|
||||
for k, service := range stats {
|
||||
if !service.Monitor.EnableShowInService {
|
||||
delete(stats, k)
|
||||
}
|
||||
}
|
||||
return []interface {
|
||||
}{
|
||||
stats, statsStore,
|
||||
}, nil
|
||||
})
|
||||
c.HTML(http.StatusOK, "theme-"+singleton.Conf.Site.Theme+"/service", mygin.CommonEnvironment(c, gin.H{
|
||||
c.HTML(http.StatusOK, mygin.GetPreferredTheme(c, "/service"), mygin.CommonEnvironment(c, gin.H{
|
||||
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "ServicesStatus"}),
|
||||
"Services": res.([]interface{})[0],
|
||||
"CycleTransferStats": res.([]interface{})[1],
|
||||
@@ -127,6 +113,112 @@ func (p *commonPage) service(c *gin.Context) {
|
||||
}))
|
||||
}
|
||||
|
||||
func (cp *commonPage) network(c *gin.Context) {
|
||||
var (
|
||||
monitorHistory *model.MonitorHistory
|
||||
servers []*model.Server
|
||||
serverIdsWithMonitor []uint64
|
||||
monitorInfos = []byte("{}")
|
||||
id uint64
|
||||
)
|
||||
if len(singleton.SortedServerList) > 0 {
|
||||
id = singleton.SortedServerList[0].ID
|
||||
}
|
||||
if err := singleton.DB.Model(&model.MonitorHistory{}).Select("monitor_id, server_id").
|
||||
Where("monitor_id != 0 and server_id != 0").Limit(1).First(&monitorHistory).Error; err != nil {
|
||||
mygin.ShowErrorPage(c, mygin.ErrInfo{
|
||||
Code: http.StatusForbidden,
|
||||
Title: "请求失败",
|
||||
Msg: "请求参数有误:" + "server monitor history not found",
|
||||
Link: "/",
|
||||
Btn: "返回重试",
|
||||
}, true)
|
||||
return
|
||||
} else {
|
||||
if monitorHistory == nil || monitorHistory.ServerID == 0 {
|
||||
if len(singleton.SortedServerList) > 0 {
|
||||
id = singleton.SortedServerList[0].ID
|
||||
}
|
||||
} else {
|
||||
id = monitorHistory.ServerID
|
||||
}
|
||||
}
|
||||
|
||||
idStr := c.Param("id")
|
||||
if idStr != "" {
|
||||
var err error
|
||||
id, err = strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
mygin.ShowErrorPage(c, mygin.ErrInfo{
|
||||
Code: http.StatusForbidden,
|
||||
Title: "请求失败",
|
||||
Msg: "请求参数有误:" + err.Error(),
|
||||
Link: "/",
|
||||
Btn: "返回重试",
|
||||
}, true)
|
||||
return
|
||||
}
|
||||
_, ok := singleton.ServerList[id]
|
||||
if !ok {
|
||||
mygin.ShowErrorPage(c, mygin.ErrInfo{
|
||||
Code: http.StatusForbidden,
|
||||
Title: "请求失败",
|
||||
Msg: "请求参数有误:" + "server id not found",
|
||||
Link: "/",
|
||||
Btn: "返回重试",
|
||||
}, true)
|
||||
return
|
||||
}
|
||||
}
|
||||
monitorHistories := singleton.MonitorAPI.GetMonitorHistories(map[string]any{"server_id": id})
|
||||
monitorInfos, _ = utils.Json.Marshal(monitorHistories)
|
||||
_, isMember := c.Get(model.CtxKeyAuthorizedUser)
|
||||
_, isViewPasswordVerfied := c.Get(model.CtxKeyViewPasswordVerified)
|
||||
|
||||
if err := singleton.DB.Model(&model.MonitorHistory{}).
|
||||
Select("distinct(server_id)").
|
||||
Where("server_id != 0").
|
||||
Find(&serverIdsWithMonitor).
|
||||
Error; err != nil {
|
||||
mygin.ShowErrorPage(c, mygin.ErrInfo{
|
||||
Code: http.StatusForbidden,
|
||||
Title: "请求失败",
|
||||
Msg: "请求参数有误:" + "no server with monitor histories",
|
||||
Link: "/",
|
||||
Btn: "返回重试",
|
||||
}, true)
|
||||
return
|
||||
}
|
||||
if isMember || isViewPasswordVerfied {
|
||||
for _, server := range singleton.SortedServerList {
|
||||
for _, id := range serverIdsWithMonitor {
|
||||
if server.ID == id {
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, server := range singleton.SortedServerListForGuest {
|
||||
for _, id := range serverIdsWithMonitor {
|
||||
if server.ID == id {
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
serversBytes, _ := utils.Json.Marshal(Data{
|
||||
Now: time.Now().Unix() * 1000,
|
||||
Servers: servers,
|
||||
})
|
||||
|
||||
c.HTML(http.StatusOK, mygin.GetPreferredTheme(c, "/network"), mygin.CommonEnvironment(c, gin.H{
|
||||
"Servers": string(serversBytes),
|
||||
"MonitorInfos": string(monitorInfos),
|
||||
"CustomCode": singleton.Conf.Site.CustomCode,
|
||||
"MaxTCPPingValue": singleton.Conf.MaxTCPPingValue,
|
||||
}))
|
||||
}
|
||||
|
||||
func (cp *commonPage) getServerStat(c *gin.Context) ([]byte, error) {
|
||||
v, err, _ := cp.requestGroup.Do("serverStats", func() (any, error) {
|
||||
singleton.SortedServerLock.RLock()
|
||||
@@ -165,7 +257,7 @@ func (cp *commonPage) home(c *gin.Context) {
|
||||
}, true)
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "theme-"+singleton.Conf.Site.Theme+"/home", mygin.CommonEnvironment(c, gin.H{
|
||||
c.HTML(http.StatusOK, mygin.GetPreferredTheme(c, "/home"), mygin.CommonEnvironment(c, gin.H{
|
||||
"Servers": string(stat),
|
||||
"CustomCode": singleton.Conf.Site.CustomCode,
|
||||
}))
|
||||
|
||||
@@ -43,6 +43,7 @@ func ServeWeb(port uint) *http.Server {
|
||||
panic(err)
|
||||
}
|
||||
r.StaticFS("/static", http.FS(staticFs))
|
||||
r.Static("/static-custom", "resource/static/custom")
|
||||
routers(r)
|
||||
|
||||
page404 := func(c *gin.Context) {
|
||||
|
||||
@@ -19,11 +19,11 @@ type guestPage struct {
|
||||
func (gp *guestPage) serve() {
|
||||
gr := gp.r.Group("")
|
||||
gr.Use(mygin.Authorize(mygin.AuthorizeOption{
|
||||
Guest: true,
|
||||
IsPage: true,
|
||||
Msg: "您已登录",
|
||||
Btn: "返回首页",
|
||||
Redirect: "/",
|
||||
GuestOnly: true,
|
||||
IsPage: true,
|
||||
Msg: "您已登录",
|
||||
Btn: "返回首页",
|
||||
Redirect: "/",
|
||||
}))
|
||||
|
||||
gr.GET("/login", gp.login)
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jinzhu/copier"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
"github.com/naiba/nezha/pkg/mygin"
|
||||
@@ -27,11 +28,11 @@ type memberAPI struct {
|
||||
func (ma *memberAPI) serve() {
|
||||
mr := ma.r.Group("")
|
||||
mr.Use(mygin.Authorize(mygin.AuthorizeOption{
|
||||
Member: true,
|
||||
IsPage: false,
|
||||
Msg: "访问此接口需要登录",
|
||||
Btn: "点此登录",
|
||||
Redirect: "/login",
|
||||
MemberOnly: true,
|
||||
IsPage: false,
|
||||
Msg: "访问此接口需要登录",
|
||||
Btn: "点此登录",
|
||||
Redirect: "/login",
|
||||
}))
|
||||
|
||||
mr.GET("/search-server", ma.searchServer)
|
||||
@@ -185,7 +186,17 @@ func (ma *memberAPI) delete(c *gin.Context) {
|
||||
var err error
|
||||
switch c.Param("model") {
|
||||
case "server":
|
||||
err = singleton.DB.Unscoped().Delete(&model.Server{}, "id = ?", id).Error
|
||||
err := singleton.DB.Transaction(func(tx *gorm.DB) error {
|
||||
err = singleton.DB.Unscoped().Delete(&model.Server{}, "id = ?", id).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = singleton.DB.Unscoped().Delete(&model.MonitorHistory{}, "server_id = ?", id).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err == nil {
|
||||
// 删除服务器
|
||||
singleton.ServerLock.Lock()
|
||||
@@ -289,6 +300,8 @@ type serverForm struct {
|
||||
Tag string
|
||||
Note string
|
||||
HideForGuest string
|
||||
EnableDDNS string
|
||||
DDNSDomain string
|
||||
}
|
||||
|
||||
func (ma *memberAPI) addOrEditServer(c *gin.Context) {
|
||||
@@ -304,6 +317,8 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
|
||||
s.Tag = sf.Tag
|
||||
s.Note = sf.Note
|
||||
s.HideForGuest = sf.HideForGuest == "on"
|
||||
s.EnableDDNS = sf.EnableDDNS == "on"
|
||||
s.DDNSDomain = sf.DDNSDomain
|
||||
if s.ID == 0 {
|
||||
s.Secret, err = utils.GenerateRandomString(18)
|
||||
if err == nil {
|
||||
@@ -383,6 +398,7 @@ type monitorForm struct {
|
||||
MaxLatency float32
|
||||
LatencyNotify string
|
||||
EnableTriggerTask string
|
||||
EnableShowInService string
|
||||
FailTriggerTasksRaw string
|
||||
RecoverTriggerTasksRaw string
|
||||
}
|
||||
@@ -404,6 +420,7 @@ func (ma *memberAPI) addOrEditMonitor(c *gin.Context) {
|
||||
m.LatencyNotify = mf.LatencyNotify == "on"
|
||||
m.MinLatency = mf.MinLatency
|
||||
m.MaxLatency = mf.MaxLatency
|
||||
m.EnableShowInService = mf.EnableShowInService == "on"
|
||||
m.EnableTriggerTask = mf.EnableTriggerTask == "on"
|
||||
m.RecoverTriggerTasksRaw = mf.RecoverTriggerTasksRaw
|
||||
m.FailTriggerTasksRaw = mf.FailTriggerTasksRaw
|
||||
@@ -427,6 +444,13 @@ func (ma *memberAPI) addOrEditMonitor(c *gin.Context) {
|
||||
err = singleton.DB.Save(&m).Error
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
if m.Cover == 0 {
|
||||
err = singleton.DB.Unscoped().Delete(&model.MonitorHistory{}, "monitor_id = ? and server_id in (?)", m.ID, strings.Split(m.SkipServersRaw[1:len(m.SkipServersRaw)-1], ",")).Error
|
||||
} else {
|
||||
err = singleton.DB.Unscoped().Delete(&model.MonitorHistory{}, "monitor_id = ? and server_id not in (?)", m.ID, strings.Split(m.SkipServersRaw[1:len(m.SkipServersRaw)-1], ",")).Error
|
||||
}
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
err = singleton.ServiceSentinelShared.OnMonitorUpdate(m)
|
||||
|
||||
@@ -17,11 +17,11 @@ type memberPage struct {
|
||||
func (mp *memberPage) serve() {
|
||||
mr := mp.r.Group("")
|
||||
mr.Use(mygin.Authorize(mygin.AuthorizeOption{
|
||||
Member: true,
|
||||
IsPage: true,
|
||||
Msg: singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "YouAreNotAuthorized"}),
|
||||
Btn: singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "Login"}),
|
||||
Redirect: "/login",
|
||||
MemberOnly: true,
|
||||
IsPage: true,
|
||||
Msg: singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "YouAreNotAuthorized"}),
|
||||
Btn: singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "Login"}),
|
||||
Redirect: "/login",
|
||||
}))
|
||||
mr.GET("/server", mp.server)
|
||||
mr.GET("/monitor", mp.monitor)
|
||||
@@ -81,7 +81,6 @@ func (mp *memberPage) setting(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "dashboard-"+singleton.Conf.Site.DashboardTheme+"/setting", mygin.CommonEnvironment(c, gin.H{
|
||||
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "Settings"}),
|
||||
"Languages": model.Languages,
|
||||
"Themes": model.Themes,
|
||||
"DashboardThemes": model.DashboardThemes,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -49,10 +49,20 @@ func DispatchTask(serviceSentinelDispatchBus <-chan model.Monitor) {
|
||||
workedServerIndex++
|
||||
continue
|
||||
}
|
||||
if task.Cover == model.MonitorCoverIgnoreAll && task.SkipServers[singleton.SortedServerList[workedServerIndex].ID] {
|
||||
singleton.SortedServerList[workedServerIndex].TaskStream.Send(task.PB())
|
||||
workedServerIndex++
|
||||
continue
|
||||
}
|
||||
if task.Cover == model.MonitorCoverAll && !task.SkipServers[singleton.SortedServerList[workedServerIndex].ID] {
|
||||
singleton.SortedServerList[workedServerIndex].TaskStream.Send(task.PB())
|
||||
workedServerIndex++
|
||||
continue
|
||||
}
|
||||
// 找到合适机器执行任务,跳出循环
|
||||
singleton.SortedServerList[workedServerIndex].TaskStream.Send(task.PB())
|
||||
workedServerIndex++
|
||||
break
|
||||
// singleton.SortedServerList[workedServerIndex].TaskStream.Send(task.PB())
|
||||
// workedServerIndex++
|
||||
// break
|
||||
}
|
||||
singleton.SortedServerLock.RUnlock()
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ require (
|
||||
github.com/spf13/viper v1.17.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
github.com/xanzy/go-gitlab v0.94.0
|
||||
golang.org/x/crypto v0.15.0
|
||||
golang.org/x/crypto v0.17.0
|
||||
golang.org/x/oauth2 v0.14.0
|
||||
golang.org/x/sync v0.5.0
|
||||
golang.org/x/text v0.14.0
|
||||
@@ -80,7 +80,7 @@ require (
|
||||
golang.org/x/arch v0.3.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||
golang.org/x/net v0.18.0 // indirect
|
||||
golang.org/x/sys v0.14.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
|
||||
|
||||
@@ -339,8 +339,8 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
|
||||
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
|
||||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
@@ -478,12 +478,12 @@ golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
||||
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8=
|
||||
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
|
||||
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
||||
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
||||
+7
-7
@@ -85,13 +85,13 @@ func (r *AlertRule) Snapshot(cycleTransferStats *CycleTransferStats, server *Ser
|
||||
|
||||
// Check 传入包含当前报警规则下所有type检查结果的空接口 返回报警持续时间与是否通过报警检查(通过则返回true)
|
||||
func (r *AlertRule) Check(points [][]interface{}) (int, bool) {
|
||||
var max int // 报警持续时间
|
||||
var count int // 检查未通过的个数
|
||||
var maxNum int // 报警持续时间
|
||||
var count int // 检查未通过的个数
|
||||
for i := 0; i < len(r.Rules); i++ {
|
||||
if r.Rules[i].IsTransferDurationRule() {
|
||||
// 循环区间流量报警
|
||||
if max < 1 {
|
||||
max = 1
|
||||
if maxNum < 1 {
|
||||
maxNum = 1
|
||||
}
|
||||
for j := len(points[i]) - 1; j >= 0; j-- {
|
||||
if points[i][j] != nil {
|
||||
@@ -104,8 +104,8 @@ func (r *AlertRule) Check(points [][]interface{}) (int, bool) {
|
||||
total := 0.0
|
||||
fail := 0.0
|
||||
num := int(r.Rules[i].Duration)
|
||||
if num > max {
|
||||
max = num
|
||||
if num > maxNum {
|
||||
maxNum = num
|
||||
}
|
||||
if len(points) < num {
|
||||
continue
|
||||
@@ -124,5 +124,5 @@ func (r *AlertRule) Check(points [][]interface{}) (int, bool) {
|
||||
}
|
||||
}
|
||||
// 仅当所有检查均未通过时 返回false
|
||||
return max, count != len(r.Rules)
|
||||
return maxNum, count != len(r.Rules)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
const CtxKeyAuthorizedUser = "ckau"
|
||||
const CtxKeyViewPasswordVerified = "ckvpv"
|
||||
const CtxKeyPreferredTheme = "ckpt"
|
||||
const CacheKeyOauth2State = "p:a:state"
|
||||
|
||||
type Common struct {
|
||||
|
||||
@@ -110,6 +110,21 @@ type Config struct {
|
||||
|
||||
v *viper.Viper
|
||||
IgnoredIPNotificationServerIDs map[uint64]bool // [ServerID] -> bool(值为true代表当前ServerID在特定服务器列表内)
|
||||
MaxTCPPingValue int32
|
||||
AvgPingCount int
|
||||
|
||||
// 动态域名解析更新
|
||||
DDNS struct {
|
||||
Enable bool
|
||||
Provider string
|
||||
AccessID string
|
||||
AccessSecret string
|
||||
WebhookURL string
|
||||
WebhookMethod string
|
||||
WebhookRequestBody string
|
||||
WebhookHeaders string
|
||||
MaxRetries uint32
|
||||
}
|
||||
}
|
||||
|
||||
// Read 读取配置文件并应用
|
||||
@@ -144,6 +159,21 @@ func (c *Config) Read(path string) error {
|
||||
if c.Location == "" {
|
||||
c.Location = "Asia/Shanghai"
|
||||
}
|
||||
if c.MaxTCPPingValue == 0 {
|
||||
c.MaxTCPPingValue = 1000
|
||||
}
|
||||
if c.AvgPingCount == 0 {
|
||||
c.AvgPingCount = 2
|
||||
}
|
||||
if c.DDNS.Provider == "" {
|
||||
c.DDNS.Provider = "webhook"
|
||||
}
|
||||
if c.DDNS.WebhookMethod == "" {
|
||||
c.DDNS.WebhookMethod = "POST"
|
||||
}
|
||||
if c.DDNS.MaxRetries == 0 {
|
||||
c.DDNS.MaxRetries = 3
|
||||
}
|
||||
|
||||
c.updateIgnoredIPNotificationID()
|
||||
return nil
|
||||
|
||||
+4
-2
@@ -4,10 +4,11 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
pb "github.com/naiba/nezha/proto"
|
||||
"github.com/robfig/cron/v3"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
pb "github.com/naiba/nezha/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -49,6 +50,7 @@ type Monitor struct {
|
||||
Cover uint8
|
||||
|
||||
EnableTriggerTask bool `gorm:"default: false"`
|
||||
EnableShowInService bool `gorm:"default: false"`
|
||||
FailTriggerTasksRaw string `gorm:"default:'[]'"`
|
||||
RecoverTriggerTasksRaw string `gorm:"default:'[]'"`
|
||||
FailTriggerTasks []uint64 `gorm:"-" json:"-"` // 失败时执行的触发任务id
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// MonitorHistory 历史监控记录
|
||||
type MonitorHistory struct {
|
||||
Common
|
||||
MonitorID uint64
|
||||
AvgDelay float32 // 平均延迟,毫秒
|
||||
Up uint64 // 检查状态良好计数
|
||||
Down uint64 // 检查状态异常计数
|
||||
ID uint64 `gorm:"primaryKey"`
|
||||
CreatedAt time.Time `gorm:"index;<-:create;index:idx_server_id_created_at_monitor_id_avg_delay"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
MonitorID uint64 `gorm:"index:idx_server_id_created_at_monitor_id_avg_delay"`
|
||||
ServerID uint64 `gorm:"index:idx_server_id_created_at_monitor_id_avg_delay"`
|
||||
AvgDelay float32 `gorm:"index:idx_server_id_created_at_monitor_id_avg_delay"` // 平均延迟,毫秒
|
||||
Up uint64 // 检查状态良好计数
|
||||
Down uint64 // 检查状态异常计数
|
||||
Data string
|
||||
}
|
||||
|
||||
|
||||
+9
-11
@@ -1,7 +1,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -111,17 +110,14 @@ func (n *Notification) setRequestHeader(req *http.Request) error {
|
||||
}
|
||||
|
||||
func (ns *NotificationServerBundle) Send(message string) error {
|
||||
var verifySSL bool
|
||||
var client *http.Client
|
||||
n := ns.Notification
|
||||
if n.VerifySSL != nil && *n.VerifySSL {
|
||||
verifySSL = true
|
||||
client = utils.HttpClient
|
||||
} else {
|
||||
client = utils.HttpClientSkipTlsVerify
|
||||
}
|
||||
|
||||
transCfg := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: verifySSL},
|
||||
}
|
||||
|
||||
client := &http.Client{Transport: transCfg, Timeout: time.Minute * 10}
|
||||
reqBody, err := ns.reqBody(message)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -147,13 +143,15 @@ func (ns *NotificationServerBundle) Send(message string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return fmt.Errorf("%d@%s %s", resp.StatusCode, resp.Status, string(body))
|
||||
} else {
|
||||
_, _ = io.Copy(io.Discard, resp.Body)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+4
-1
@@ -17,6 +17,8 @@ type Server struct {
|
||||
Note string `json:"-"` // 管理员可见备注
|
||||
DisplayIndex int // 展示排序,越大越靠前
|
||||
HideForGuest bool // 对游客隐藏
|
||||
EnableDDNS bool // 是否启用DDNS 未在配置文件中启用DDNS 或 DDNS检查时间为0时此项无效
|
||||
DDNSDomain string // DDNS中的前缀 如基础域名为abc.oracle DDNSName为mjj 就会把mjj.abc.oracle解析服务器IP 为空则停用
|
||||
|
||||
Host *Host `gorm:"-"`
|
||||
State *HostState `gorm:"-"`
|
||||
@@ -51,5 +53,6 @@ func (s Server) Marshal() template.JS {
|
||||
tag, _ := utils.Json.Marshal(s.Tag)
|
||||
note, _ := utils.Json.Marshal(s.Note)
|
||||
secret, _ := utils.Json.Marshal(s.Secret)
|
||||
return template.JS(fmt.Sprintf(`{"ID":%d,"Name":%s,"Secret":%s,"DisplayIndex":%d,"Tag":%s,"Note":%s,"HideForGuest": %s}`, s.ID, name, secret, s.DisplayIndex, tag, note, boolToString(s.HideForGuest))) // #nosec
|
||||
ddnsDomain, _ := utils.Json.Marshal(s.DDNSDomain)
|
||||
return template.JS(fmt.Sprintf(`{"ID":%d,"Name":%s,"Secret":%s,"DisplayIndex":%d,"Tag":%s,"Note":%s,"HideForGuest": %s,"EnableDDNS": %s,"DDNSDomain": %s}`, s.ID, name, secret, s.DisplayIndex, tag, note, boolToString(s.HideForGuest), boolToString(s.EnableDDNS), ddnsDomain)) // #nosec
|
||||
}
|
||||
|
||||
+30
-10
@@ -6,25 +6,28 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
"github.com/naiba/nezha/service/singleton"
|
||||
)
|
||||
|
||||
type AuthorizeOption struct {
|
||||
Guest bool
|
||||
Member bool
|
||||
IsPage bool
|
||||
AllowAPI bool
|
||||
Msg string
|
||||
Redirect string
|
||||
Btn string
|
||||
GuestOnly bool
|
||||
MemberOnly bool
|
||||
ValidateViewPassword bool
|
||||
IsPage bool
|
||||
AllowAPI bool
|
||||
Msg string
|
||||
Redirect string
|
||||
Btn string
|
||||
}
|
||||
|
||||
func Authorize(opt AuthorizeOption) func(*gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var code = http.StatusForbidden
|
||||
if opt.Guest {
|
||||
if opt.GuestOnly {
|
||||
code = http.StatusBadRequest
|
||||
}
|
||||
|
||||
@@ -67,15 +70,32 @@ func Authorize(opt AuthorizeOption) func(*gin.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 已登录且只能游客访问
|
||||
if isLogin && opt.Guest {
|
||||
if isLogin && opt.GuestOnly {
|
||||
ShowErrorPage(c, commonErr, opt.IsPage)
|
||||
return
|
||||
}
|
||||
|
||||
// 未登录且需要登录
|
||||
if !isLogin && opt.Member {
|
||||
if !isLogin && opt.MemberOnly {
|
||||
ShowErrorPage(c, commonErr, opt.IsPage)
|
||||
return
|
||||
}
|
||||
|
||||
// 验证查看密码
|
||||
if opt.ValidateViewPassword && singleton.Conf.Site.ViewPassword != "" {
|
||||
viewPassword, _ := c.Cookie(singleton.Conf.Site.CookieName + "-vp")
|
||||
if err := bcrypt.CompareHashAndPassword([]byte(viewPassword), []byte(singleton.Conf.Site.ViewPassword)); err != nil {
|
||||
c.HTML(http.StatusOK, GetPreferredTheme(c, "/viewpassword"), CommonEnvironment(c, gin.H{
|
||||
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "VerifyPassword"}),
|
||||
"CustomCode": singleton.Conf.Site.CustomCode,
|
||||
}))
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Set(model.CtxKeyViewPasswordVerified, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ func CommonEnvironment(c *gin.Context, data map[string]interface{}) gin.H {
|
||||
data["MatchedPath"] = c.MustGet("MatchedPath")
|
||||
data["Version"] = singleton.Version
|
||||
data["Conf"] = singleton.Conf
|
||||
data["Themes"] = model.Themes
|
||||
// 是否是管理页面
|
||||
data["IsAdminPage"] = adminPage[data["MatchedPath"].(string)]
|
||||
// 站点标题
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package mygin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/naiba/nezha/model"
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
"github.com/naiba/nezha/service/singleton"
|
||||
)
|
||||
|
||||
func PreferredTheme(c *gin.Context) {
|
||||
// 采用前端传入的主题
|
||||
if theme, err := c.Cookie("preferred_theme"); err == nil {
|
||||
if _, has := model.Themes[theme]; has {
|
||||
// 检验自定义主题
|
||||
if theme == "custom" && singleton.Conf.Site.Theme != "custom" && !utils.IsFileExists("resource/template/custom/home.html") {
|
||||
return
|
||||
}
|
||||
c.Set(model.CtxKeyPreferredTheme, theme)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetPreferredTheme(c *gin.Context, path string) string {
|
||||
if theme, has := c.Get(model.CtxKeyPreferredTheme); has {
|
||||
return fmt.Sprintf("theme-%s%s", theme, path)
|
||||
}
|
||||
return fmt.Sprintf("theme-%s%s", singleton.Conf.Site.Theme, path)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
HttpClientSkipTlsVerify *http.Client
|
||||
HttpClient *http.Client
|
||||
)
|
||||
|
||||
func init() {
|
||||
HttpClientSkipTlsVerify = httpClient(_httpClient{
|
||||
Transport: httpTransport(_httpTransport{
|
||||
SkipVerifySSL: true,
|
||||
}),
|
||||
})
|
||||
HttpClient = httpClient(_httpClient{
|
||||
Transport: httpTransport(_httpTransport{
|
||||
SkipVerifySSL: false,
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
type _httpTransport struct {
|
||||
SkipVerifySSL bool
|
||||
}
|
||||
|
||||
func httpTransport(conf _httpTransport) *http.Transport {
|
||||
return &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: conf.SkipVerifySSL},
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
}
|
||||
}
|
||||
|
||||
type _httpClient struct {
|
||||
Transport *http.Transport
|
||||
}
|
||||
|
||||
func httpClient(conf _httpClient) *http.Client {
|
||||
return &http.Client{
|
||||
Transport: conf.Transport,
|
||||
Timeout: time.Minute * 10,
|
||||
}
|
||||
}
|
||||
Vendored
+18
@@ -609,3 +609,21 @@ other = "Hide for Guest"
|
||||
|
||||
[Menu]
|
||||
other = "Menu"
|
||||
|
||||
[NetworkSpiter]
|
||||
other = "Network"
|
||||
|
||||
[EnableShowInService]
|
||||
other = "Enable Show in Service"
|
||||
|
||||
[EnableDDNS]
|
||||
other = "Enable DDNS"
|
||||
|
||||
[DDNSDomain]
|
||||
other = "DDNS Domain"
|
||||
|
||||
[Feature]
|
||||
other = "Feature"
|
||||
|
||||
[Template]
|
||||
other = "Template"
|
||||
|
||||
Vendored
+18
@@ -609,3 +609,21 @@ other = "Ocultar para Invitados"
|
||||
|
||||
[Menu]
|
||||
other = "Menú"
|
||||
|
||||
[NetworkSpiter]
|
||||
other = "Red"
|
||||
|
||||
[EnableShowInService]
|
||||
other = "Mostrar en servicio"
|
||||
|
||||
[EnableDDNS]
|
||||
other = "Habilitar DDNS"
|
||||
|
||||
[DDNSDomain]
|
||||
other = "Dominio DDNS"
|
||||
|
||||
[Feature]
|
||||
other = "Característica"
|
||||
|
||||
[Template]
|
||||
other = "Plantilla"
|
||||
|
||||
Vendored
+19
-1
@@ -608,4 +608,22 @@ other = "信息"
|
||||
other = "对游客隐藏"
|
||||
|
||||
[Menu]
|
||||
other = "菜单"
|
||||
other = "菜单"
|
||||
|
||||
[NetworkSpiter]
|
||||
other = "网络"
|
||||
|
||||
[EnableShowInService]
|
||||
other = "在服务中显示"
|
||||
|
||||
[EnableDDNS]
|
||||
other = "启用DDNS"
|
||||
|
||||
[DDNSDomain]
|
||||
other = "DDNS域名"
|
||||
|
||||
[Feature]
|
||||
other = "功能"
|
||||
|
||||
[Template]
|
||||
other = "主题"
|
||||
|
||||
Vendored
+19
-1
@@ -608,4 +608,22 @@ other = "信息"
|
||||
other = "對遊客隱藏"
|
||||
|
||||
[Menu]
|
||||
other = "菜單"
|
||||
other = "菜單"
|
||||
|
||||
[NetworkSpiter]
|
||||
other = "網絡"
|
||||
|
||||
[EnableShowInService]
|
||||
other = "在服務中顯示"
|
||||
|
||||
[EnableDDNS]
|
||||
other = "啟用DDNS"
|
||||
|
||||
[DDNSDomain]
|
||||
other = "DDNS網域"
|
||||
|
||||
[Feature]
|
||||
other = "功能"
|
||||
|
||||
[Template]
|
||||
other = "主題"
|
||||
|
||||
@@ -302,6 +302,7 @@ function addOrEditServer(server, conf) {
|
||||
modal.find("input[name=id]").val(server ? server.ID : null);
|
||||
modal.find("input[name=name]").val(server ? server.Name : null);
|
||||
modal.find("input[name=Tag]").val(server ? server.Tag : null);
|
||||
modal.find("input[name=DDNSDomain]").val(server ? server.DDNSDomain : null);
|
||||
modal
|
||||
.find("input[name=DisplayIndex]")
|
||||
.val(server ? server.DisplayIndex : null);
|
||||
@@ -321,6 +322,11 @@ function addOrEditServer(server, conf) {
|
||||
} else {
|
||||
modal.find(".ui.hideforguest.checkbox").checkbox("set unchecked");
|
||||
}
|
||||
if (server && server.EnableDDNS) {
|
||||
modal.find(".ui.enableddns.checkbox").checkbox("set checked");
|
||||
} else {
|
||||
modal.find(".ui.enableddns.checkbox").checkbox("set unchecked");
|
||||
}
|
||||
showFormModal(".server.modal", "#serverForm", "/api/server");
|
||||
}
|
||||
|
||||
@@ -339,6 +345,11 @@ function addOrEditMonitor(monitor) {
|
||||
modal.find("select[name=Type]").val(monitor ? monitor.Type : 1);
|
||||
modal.find("select[name=Cover]").val(monitor ? monitor.Cover : 0);
|
||||
modal.find("input[name=NotificationTag]").val(monitor ? monitor.NotificationTag : null);
|
||||
if (monitor && monitor.EnableShowInService) {
|
||||
modal.find(".ui.nb-show-in-service.checkbox").checkbox("set checked")
|
||||
} else {
|
||||
modal.find(".ui.nb-show-in-service.checkbox").checkbox("set unchecked")
|
||||
}
|
||||
if (monitor && monitor.Notify) {
|
||||
modal.find(".ui.nb-notify.checkbox").checkbox("set checked");
|
||||
} else {
|
||||
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
/* 屏幕适配 */
|
||||
@media only screen and (min-width:1200px) {
|
||||
.ui.container {
|
||||
width:95% !important;
|
||||
font-size: 90% !important;
|
||||
}
|
||||
}
|
||||
@media only screen and (max-width:767px) {
|
||||
.ui.card>.content>.header:not(.ui),.ui.cards>.card>.content>.header:not(.ui) {
|
||||
margin-top:0.4em !important;
|
||||
}
|
||||
.ui.menu .item>img:not(.ui){
|
||||
width: 2.2rem;
|
||||
}
|
||||
.ui.menu .item:before{
|
||||
width:0.5px;
|
||||
}
|
||||
.ui.menu .item{
|
||||
padding: 0.9rem 0.55rem;
|
||||
}
|
||||
.ui.large.menu{
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
i.icon {
|
||||
color:#000;
|
||||
width:1.2em !important;
|
||||
}
|
||||
i.fi {
|
||||
width:0.9em;
|
||||
margin:0px 6px 0px 2px;
|
||||
}
|
||||
|
||||
body {
|
||||
content:" " !important;
|
||||
background:fixed !important;
|
||||
z-index:-1 !important;
|
||||
top:0 !important;
|
||||
right:0 !important;
|
||||
bottom:0 !important;
|
||||
left:0 !important;
|
||||
}
|
||||
|
||||
td {
|
||||
word-wrap: break-word;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.nb-container {
|
||||
padding-top: 75px;
|
||||
min-height: 100vh;
|
||||
padding-bottom: 65px;
|
||||
margin-bottom: -47px;
|
||||
}
|
||||
|
||||
#app .ui.fluid.accordion {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.login.nb-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-top: unset;
|
||||
}
|
||||
|
||||
.login.nb-container > .grid {
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.login.nb-container > .grid .column {
|
||||
max-width: 450px;
|
||||
}
|
||||
|
||||
.ui.menu .item-right:before{
|
||||
width:0px;
|
||||
}
|
||||
|
||||
.status.cards .flag {
|
||||
margin-right: 0 !important;
|
||||
}
|
||||
|
||||
.status.cards .header > .info.icon {
|
||||
float: right;
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.status.cards .wide.column {
|
||||
padding-top: 0 !important;
|
||||
padding-bottom: 0 !important;
|
||||
height:3.3rem !important;
|
||||
}
|
||||
|
||||
.status.cards .wide.column:nth-child(1) {
|
||||
margin-top:2rem !important;
|
||||
}
|
||||
|
||||
.status.cards .wide.column:nth-child(2) {
|
||||
margin-top:2rem !important;
|
||||
}
|
||||
|
||||
.status.cards .thirteen.wide.column{
|
||||
padding-left:0;
|
||||
}
|
||||
|
||||
.status.cards .description {
|
||||
padding-bottom:0 !important;
|
||||
}
|
||||
|
||||
.status.cards .flag {
|
||||
margin-right:0.5rem !important;
|
||||
}
|
||||
|
||||
.status.cards .header > .info.icon {
|
||||
float: right;
|
||||
margin-right:0 !important;
|
||||
}
|
||||
|
||||
.ui.popup:before {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.closePopup{
|
||||
color:rgb(10, 148, 242) !important;
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
cursor: pointer;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.ui.content {
|
||||
margin:0 !important;
|
||||
padding:1em !important;
|
||||
}
|
||||
|
||||
.status.cards .ui.content.popup {
|
||||
min-width:calc(100%)!important;
|
||||
line-height:2rem !important;
|
||||
border-radius:5px !important;
|
||||
border:1px solid transparent !important;
|
||||
font-family:Arial,Helvetica,sans-serif !important;
|
||||
}
|
||||
|
||||
.status.cards .outline.icon {
|
||||
margin-right:1px !important;
|
||||
}
|
||||
|
||||
.ui.progress .bar {
|
||||
min-width:1.8em !important;
|
||||
border-radius:5px !important;
|
||||
line-height:1.65em !important;
|
||||
text-align: right;
|
||||
padding-right: 0.4em;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
font-weight: 700;
|
||||
max-width: 100% !important;
|
||||
}
|
||||
|
||||
.service-status .delay-today {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.service-status .delay-today > i {
|
||||
display: inline-block;
|
||||
width: 1.2em;
|
||||
height: 1.2em;
|
||||
border-radius: 0.6em;
|
||||
background-color: grey;
|
||||
margin-right: 0.3em;
|
||||
}
|
||||
|
||||
.service-status .danger {
|
||||
background-color: crimson !important;
|
||||
}
|
||||
|
||||
.service-status .good {
|
||||
background-color: rgb(10, 148, 242) !important;
|
||||
}
|
||||
|
||||
.service-status .warning {
|
||||
background-color: orange !important;
|
||||
}
|
||||
|
||||
.nezha-primary-btn {
|
||||
background-color: #0338d6 !important;
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.nezha-primary-font {
|
||||
color: #0338d6 !important;
|
||||
}
|
||||
|
||||
.nezha-secondary-font {
|
||||
color: rgb(10, 148, 242) !important;
|
||||
}
|
||||
|
||||
.ui-alerts.top-center {
|
||||
z-index: 99999999;
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+79
-52
File diff suppressed because one or more lines are too long
+73
-17
File diff suppressed because one or more lines are too long
+226
-107
@@ -1,51 +1,125 @@
|
||||
body {
|
||||
padding-top: 70px !important;
|
||||
padding-top:70px !important;
|
||||
padding-bottom: 30px !important;
|
||||
}
|
||||
|
||||
/* 导航部分 开始*/
|
||||
.navbar {
|
||||
min-height: 40px !important;
|
||||
margin:0 auto;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.navbar-collapse:not([aria-expanded]) .navbar-nav .dropdown-toggle {
|
||||
.navbar .container{
|
||||
max-width: 95vw;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.navbar-inverse{
|
||||
background-image: none;
|
||||
background-color: #1C2127;
|
||||
box-shadow: 0 1px 40px -8px #00000080;
|
||||
}
|
||||
|
||||
.navbar-inverse .navbar-toggle:focus,
|
||||
.navbar-inverse .navbar-toggle:hover {
|
||||
background-color: #1C2127;
|
||||
}
|
||||
|
||||
.navbar .navbar-collapse:not([aria-expanded]) .navbar-nav .dropdown-toggle {
|
||||
margin-top: 18px;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-size: 20px;
|
||||
text-align: center;
|
||||
.navbar .navbar-toggle {
|
||||
margin-right:0
|
||||
}
|
||||
|
||||
.node-cell-expand {
|
||||
max-width: 420px;
|
||||
.navbar .navbar-brand {
|
||||
font-size: 20px;
|
||||
text-align: center;
|
||||
padding:12px 0 0 0;
|
||||
margin-right:30px;
|
||||
}
|
||||
|
||||
.navbar .node-cell-expand {
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.node-cell-expand-label {
|
||||
margin-right: 5px;
|
||||
.navbar .node-cell-expand-label {
|
||||
/*margin-right: 5px;*/
|
||||
}
|
||||
|
||||
.dropdown .dropdown-toggle {
|
||||
.navbar .dropdown .dropdown-toggle {
|
||||
padding-bottom: 10px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
margin-right: 10px;
|
||||
.navbar .navbar-nav {
|
||||
margin:0px -15px;
|
||||
}
|
||||
|
||||
.navbar-inverse, .nav.navbar-nav {
|
||||
background-image: linear-gradient(rgb(60, 60, 60) 0px, rgb(34, 34, 34) 100%) !important;
|
||||
.navbar .navbar-nav>li>a {
|
||||
color:#f1f1f1;
|
||||
}
|
||||
|
||||
.navbar-inverse .navbar-brand {
|
||||
font-size: 20px;
|
||||
.navbar-nav li a span{
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.navbar .navbar-collapse{
|
||||
max-height: 500px;
|
||||
}
|
||||
|
||||
/* 导航部分 结束 */
|
||||
|
||||
|
||||
/* toolbox 开始 */
|
||||
|
||||
.toolbox {
|
||||
position: fixed;
|
||||
bottom:20px;
|
||||
right: 12px;
|
||||
z-index: 999999;
|
||||
}
|
||||
|
||||
.toolbox span{
|
||||
display: block;
|
||||
width: 2.75rem;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.toolbox i{
|
||||
display: block;
|
||||
color: rgba(241,241,241,1);
|
||||
cursor: pointer;
|
||||
border-radius: 5px;
|
||||
font-size: 1.5rem;
|
||||
height: 2.75rem;
|
||||
width: 2.75rem;
|
||||
line-height: 2.75rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.toolbox .toggleView i.show-nogroup {
|
||||
font-size: 1.85rem;
|
||||
}
|
||||
|
||||
.toolbox .setTheme i.setTheme-dark {
|
||||
font-size: 1.35rem;
|
||||
}
|
||||
|
||||
.toolbox .setTheme i.setTheme-light {
|
||||
font-size: 1.45rem;
|
||||
}
|
||||
|
||||
.toolbox .showGoTop i.goTop {
|
||||
font-size: 1.55rem;
|
||||
}
|
||||
|
||||
/* toolbox 结束 */
|
||||
|
||||
|
||||
/* 正文部分 开始 */
|
||||
.content {
|
||||
padding: 20px;
|
||||
@@ -63,6 +137,40 @@ body {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.table > tbody > tr > td,
|
||||
.table > tbody > tr > th,
|
||||
.table > tfoot > tr > td,
|
||||
.table > tfoot > tr > th,
|
||||
.table > thead > tr > td,
|
||||
.table > thead > tr > th {
|
||||
position: relative;
|
||||
border:none;
|
||||
line-height:20px;
|
||||
}
|
||||
|
||||
.table > tbody > tr > td:before,
|
||||
.table > tbody > tr > th:before,
|
||||
.table > tfoot > tr > td:before,
|
||||
.table > tfoot > tr > th:before,
|
||||
.table > thead > tr > td:before,
|
||||
.table > thead > tr > th:before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 0.7px;
|
||||
}
|
||||
|
||||
.table .node-group-tag th{
|
||||
font-size: 18px;
|
||||
padding-bottom:15px;
|
||||
}
|
||||
|
||||
.table .node-cell-os-text {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.progress {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
@@ -72,12 +180,15 @@ body {
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
|
||||
.expandRow > td {
|
||||
padding: 0 !important;
|
||||
border-top: 0 !important;
|
||||
}
|
||||
|
||||
.accordian-body{
|
||||
margin: 10px 0px 10px 18px;
|
||||
}
|
||||
|
||||
.node-cell.center {
|
||||
text-align: center !important;
|
||||
}
|
||||
@@ -106,25 +217,49 @@ body {
|
||||
}
|
||||
|
||||
.node-cell.network {
|
||||
min-width: 110px;
|
||||
max-width: 110px;
|
||||
min-width: 100px;
|
||||
max-width: 100px;
|
||||
}
|
||||
|
||||
.node-cell.cpu, .node-cell.ram, .node-cell.hdd {
|
||||
min-width: 45px;
|
||||
max-width: 90px;
|
||||
.node-cell.traffic {
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
.node-cell.cpu, .node-cell.ram, .node-cell.hdd, .node-cell.memory {
|
||||
min-width: 50px;
|
||||
max-width: 50px;
|
||||
}
|
||||
|
||||
/*正文结束*/
|
||||
|
||||
/* 服务页 正文*/
|
||||
.service-status {
|
||||
|
||||
}
|
||||
|
||||
.service-status .service-status-th{
|
||||
min-width:60px;
|
||||
}
|
||||
|
||||
.service-status .service-name-th{
|
||||
min-width:50px;
|
||||
}
|
||||
|
||||
.service-status .service-averagelatency-th{
|
||||
min-width:80px;
|
||||
}
|
||||
|
||||
.service-status .service-30daysonline-th{
|
||||
min-width:80px;
|
||||
}
|
||||
|
||||
.service-status .delay-today {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: left;
|
||||
}
|
||||
|
||||
.service-status .delay-today > i {
|
||||
.service-status .delay-today i {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
@@ -138,113 +273,97 @@ body {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
margin-right: 4px;
|
||||
margin-bottom: -3.25px;
|
||||
border-radius: 3px;
|
||||
box-shadow: inset 0 2px 2px rgba(0, 0, 0, .1);
|
||||
}
|
||||
|
||||
.service-status {
|
||||
|
||||
.service-status .tooltip-inner {
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* 服务页 正文结束 */
|
||||
|
||||
@media only screen and (max-width: 1200px) {
|
||||
.accordian-body{
|
||||
margin: 5px 0px 5px 10px;
|
||||
}
|
||||
.table .node-group-tag th{
|
||||
font-size:16px;
|
||||
padding-bottom:6px;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 767px) {
|
||||
body {
|
||||
font-size: 10px !important;
|
||||
padding-top:60px !important;
|
||||
}
|
||||
.content {
|
||||
padding: 0;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.navbar .navbar-nav .open .dropdown-menu>li>a {
|
||||
color: #f1f1f1;
|
||||
}
|
||||
.navbar .navbar-nav .open .dropdown-menu {
|
||||
list-style-image: initial;
|
||||
background-color: #181a1b;
|
||||
border-color: rgba(140, 130, 115, 0.15);
|
||||
box-shadow: rgba(0, 0, 0, 0.18) 0px 6px 12px;
|
||||
}
|
||||
.table > tbody > tr > td:before,
|
||||
.table > tbody > tr > th:before,
|
||||
.table > tfoot > tr > td:before,
|
||||
.table > tfoot > tr > th:before,
|
||||
.table > thead > tr > td:before,
|
||||
.table > thead > tr > th:before {
|
||||
height: 0.5px;
|
||||
}
|
||||
.node-cell.os,
|
||||
.node-cell.location,
|
||||
.node-cell.uptime {
|
||||
display: none;
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 720px) {
|
||||
body {
|
||||
font-size: 10px !important;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.node-cell.os,
|
||||
.node-cell.location,
|
||||
.node-cell.uptime {
|
||||
display: none;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.service-day-status-icon {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
margin-right: 2px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 620px) {
|
||||
body {
|
||||
font-size: 10px !important;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.node-cell.type,
|
||||
.node-cell.location,
|
||||
.node-cell.uptime,
|
||||
.node-cell.traffic {
|
||||
.node-cell.traffic{
|
||||
display: none;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.service-day-status-icon {
|
||||
.node-cell.location{
|
||||
display: table-cell;
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 533px) {
|
||||
body {
|
||||
font-size: 10px !important;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.node-cell.os,
|
||||
.node-cell.location,
|
||||
.node-cell.uptime,
|
||||
.node-cell.traffic {
|
||||
.node-cell-os-text,.node-cell-location-text{
|
||||
display: none;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.service-day-status-icon {
|
||||
.accordian-body{
|
||||
margin: 5px 0px 5px 10px;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 450px) {
|
||||
body {
|
||||
font-size: 10px !important;
|
||||
.table .node-group-tag th{
|
||||
font-size:16px;
|
||||
padding-bottom:6px;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 0;
|
||||
.service-status .service-status-th{
|
||||
min-width:30px;
|
||||
}
|
||||
|
||||
.node-cell.type,
|
||||
.node-cell.location,
|
||||
.node-cell.uptime,
|
||||
.node-cell.traffic {
|
||||
.service-status .delay-today{
|
||||
margin-top:4px;
|
||||
justify-content: center;
|
||||
}
|
||||
.service-status .delay-today i{
|
||||
margin-right:0px;
|
||||
}
|
||||
.service-status .delay-today-text{
|
||||
display: none;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.node-cell.cpu,
|
||||
.node-cell.ram,
|
||||
.node-cell.hdd {
|
||||
min-width: 25px;
|
||||
max-width: 50px;
|
||||
.service-status .service-averagelatency-th{
|
||||
min-width:70px;
|
||||
}
|
||||
.service-status .service-30daysonline-th{
|
||||
min-width:75px;
|
||||
}
|
||||
.toolbox {
|
||||
right: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+102
-10
@@ -2,27 +2,74 @@ const mixinsVue = {
|
||||
data: {
|
||||
cache: [],
|
||||
theme: "light",
|
||||
isSystemTheme: false
|
||||
isSystemTheme: false,
|
||||
showGroup: false,
|
||||
showGoTop: false,
|
||||
preferredTemplate: 'default',
|
||||
isMobile: false
|
||||
},
|
||||
created() {
|
||||
this.initTheme()
|
||||
this.isMobile = this.checkIsMobile();
|
||||
this.initTheme();
|
||||
this.storedShowGroup();
|
||||
this.preferredTemplate = this.getCookie('preferred_theme') ? this.getCookie('preferred_theme') : 'default';
|
||||
window.addEventListener('scroll', this.handleScroll);
|
||||
},
|
||||
destroyed() {
|
||||
window.removeEventListener('scroll', this.handleScroll);
|
||||
},
|
||||
methods: {
|
||||
toggleView() {
|
||||
this.showGroup = !this.showGroup;
|
||||
localStorage.setItem("showGroup", JSON.stringify(this.showGroup));
|
||||
return this.showGroup;
|
||||
},
|
||||
storedShowGroup() {
|
||||
const storedShowGroup = localStorage.getItem("showGroup");
|
||||
if (storedShowGroup !== null) {
|
||||
this.showGroup = JSON.parse(storedShowGroup);
|
||||
}
|
||||
},
|
||||
toggleTemplate(template) {
|
||||
if( template != this.preferredTemplate){
|
||||
this.preferredTemplate = template;
|
||||
this.updateCookie("preferred_theme", template);
|
||||
window.location.reload();
|
||||
}
|
||||
},
|
||||
updateCookie(name, value) {
|
||||
document.cookie = name + "=" + value +"; path=/";
|
||||
},
|
||||
getCookie(name) {
|
||||
const cookies = document.cookie.split(';');
|
||||
let cookieValue = null;
|
||||
for (let i = 0; i < cookies.length; i++) {
|
||||
const cookie = cookies[i].trim();
|
||||
if (cookie.startsWith(name + '=')) {
|
||||
cookieValue = cookie.substring(name.length + 1, cookie.length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
},
|
||||
setTheme(title, store = false) {
|
||||
this.theme = title
|
||||
document.body.setAttribute("theme", title)
|
||||
this.theme = title;
|
||||
document.body.setAttribute("theme", title);
|
||||
if (store) {
|
||||
localStorage.setItem("theme", title)
|
||||
this.isSystemTheme = false
|
||||
localStorage.setItem("theme", title);
|
||||
this.isSystemTheme = false;
|
||||
if(this.$root.page == 'index') {
|
||||
this.$root.reloadCharts(); //重新载入echarts图表
|
||||
}
|
||||
}
|
||||
},
|
||||
setSystemTheme() {
|
||||
localStorage.removeItem("theme")
|
||||
this.initTheme()
|
||||
this.isSystemTheme = true
|
||||
localStorage.removeItem("theme");
|
||||
this.initTheme();
|
||||
this.isSystemTheme = true;
|
||||
},
|
||||
initTheme() {
|
||||
const storeTheme = localStorage.getItem("theme")
|
||||
const storeTheme = localStorage.getItem("theme");
|
||||
if (storeTheme === 'dark' || storeTheme === 'light') {
|
||||
this.setTheme(storeTheme, true);
|
||||
} else {
|
||||
@@ -45,5 +92,50 @@ const mixinsVue = {
|
||||
toFixed2(f) {
|
||||
return f.toFixed(2)
|
||||
},
|
||||
logOut(id) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/api/logout',
|
||||
data: JSON.stringify({ id: id }),
|
||||
contentType: 'application/json',
|
||||
success: function (resp) {
|
||||
if (resp.code == 200) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
alert('注销失败(Error ' + resp.code + '): ' + resp.message);
|
||||
}
|
||||
},
|
||||
error: function (err) {
|
||||
alert('网络错误: ' + err.responseText);
|
||||
}
|
||||
});
|
||||
},
|
||||
goTop() {
|
||||
$('html, body').animate({ scrollTop: 0 }, 400);
|
||||
return false;
|
||||
},
|
||||
handleScroll() {
|
||||
this.showGoTop = window.scrollY >= 100;
|
||||
},
|
||||
groupingData(data, field) {
|
||||
let map = new Map();
|
||||
let dest = [];
|
||||
|
||||
data.forEach(item => {
|
||||
if (!map.has(item[field])) {
|
||||
dest.push({
|
||||
[field]: item[field],
|
||||
data: [item]
|
||||
});
|
||||
map.set(item[field], item);
|
||||
} else {
|
||||
dest.find(dItem => dItem[field] === item[field]).data.push(item);
|
||||
}
|
||||
});
|
||||
return dest;
|
||||
},
|
||||
checkIsMobile() { // 检测设备类型,页面宽度小于768px认为是移动设备
|
||||
return window.innerWidth <= 768;
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+4
-4
@@ -6,11 +6,11 @@
|
||||
{{.Version}}</small>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/semantic-ui/2.4.1/semantic.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/semantic-ui/2.4.1/semantic.min.js"></script>
|
||||
<script src="/static/semantic-ui-alerts.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
|
||||
<script src="/static/main.js?v20230614"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/vue/2.6.14/vue.min.js"></script>
|
||||
<script src="/static/main.js?v20240224"></script>
|
||||
<script>
|
||||
(function () {
|
||||
updateLang({{.LANG }});
|
||||
|
||||
Vendored
+2
-2
@@ -9,8 +9,8 @@
|
||||
<meta content="telephone=no" name="format-detection">
|
||||
<title>{{.Title}}</title>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="https://cdn.staticfile.org/semantic-ui/2.4.1/semantic.min.css">
|
||||
<link href="https://cdn.staticfile.org/font-logos/0.17/font-logos.min.css" type="text/css"
|
||||
href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/semantic-ui/2.4.1/semantic.min.css">
|
||||
<link href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/font-logos/0.17/font-logos.min.css" type="text/css"
|
||||
rel="stylesheet" />
|
||||
<link rel="stylesheet" type="text/css" href="/static/semantic-ui-alerts.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/main.css?v2022042314">
|
||||
|
||||
Vendored
+2
-1
@@ -15,6 +15,7 @@
|
||||
{{else}}
|
||||
<a class='item{{if eq .MatchedPath "/"}} active{{end}}' href="/"><i class="home icon"></i>{{tr "Home"}}</a>
|
||||
<a class='item{{if eq .MatchedPath "/service"}} active{{end}}' href="/service"><i class="rss icon"></i>{{tr "Services"}}</a>
|
||||
<a class='item{{if eq .MatchedPath "/network"}} active{{end}}' href="/network"><i class="server icon"></i>{{tr "NetworkSpiter"}}</a>
|
||||
{{end}}
|
||||
<div class="right menu">
|
||||
<div class="item">
|
||||
@@ -50,4 +51,4 @@
|
||||
</div>
|
||||
</div>
|
||||
{{template "component/confirm" .}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
+7
@@ -24,6 +24,12 @@
|
||||
<option value="3">TCP-Ping</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="ui nb-show-in-service checkbox">
|
||||
<input name="EnableShowInService" type="checkbox" tabindex="0" class="hidden" />
|
||||
<label>{{tr "EnableShowInService"}}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{tr "Duration"}}</label>
|
||||
<input type="number" name="Duration" placeholder="{{tr "Seconds"}}" />
|
||||
@@ -110,3 +116,4 @@
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
|
||||
+10
@@ -26,6 +26,16 @@
|
||||
<label>{{tr "HideForGuest"}}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="ui enableddns checkbox">
|
||||
<input name="EnableDDNS" type="checkbox" tabindex="0" />
|
||||
<label>{{tr "EnableDDNS"}}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{tr "DDNSDomain"}}</label>
|
||||
<input type="text" name="DDNSDomain" placeholder="{{tr "DDNSDomain"}}">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{tr "Note"}}</label>
|
||||
<textarea name="Note"></textarea>
|
||||
|
||||
+1
-1
@@ -68,4 +68,4 @@
|
||||
<script>
|
||||
$(".checkbox").checkbox();
|
||||
</script>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
+5
-1
@@ -29,6 +29,8 @@
|
||||
<th>IP</th>
|
||||
<th>{{tr "VersionNumber"}}</th>
|
||||
<th>{{tr "HideForGuest"}}</th>
|
||||
<th>{{tr "EnableDDNS"}}</th>
|
||||
<th>{{tr "DDNSDomain"}}</th>
|
||||
<th>{{tr "Secret"}}</th>
|
||||
<th>{{tr "OneKeyInstall"}}</th>
|
||||
<th>{{tr "Note"}}</th>
|
||||
@@ -45,6 +47,8 @@
|
||||
<td>{{$server.Host.IP}}</td>
|
||||
<td>{{$server.Host.Version}}</td>
|
||||
<td>{{$server.HideForGuest}}</td>
|
||||
<td>{{$server.EnableDDNS}}</td>
|
||||
<td>{{$server.DDNSDomain}}</td>
|
||||
<td>
|
||||
<button class="ui icon green mini button" data-clipboard-text="{{$server.Secret}}" data-tooltip="{{tr "ClickToCopy"}}">
|
||||
<i class="copy icon"></i>
|
||||
@@ -85,7 +89,7 @@
|
||||
</div>
|
||||
{{template "component/server" .}}
|
||||
{{template "common/footer" .}}
|
||||
<script src="https://cdn.staticfile.org/clipboard.js/2.0.10/clipboard.min.js" type="application/javascript"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/clipboard.js/2.0.10/clipboard.min.js" type="application/javascript"></script>
|
||||
<script>
|
||||
var clipboard = new ClipboardJS('.ui.icon.green.mini.button');
|
||||
const checkBoxList = document.querySelectorAll('tbody > tr > td > input.nezha-servers[type=checkbox]')
|
||||
|
||||
+4
-4
@@ -8,7 +8,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>tty@{{.ServerName}} - {{.Title}}</title>
|
||||
<link rel="shortcut icon" type="image/png" href="/static/logo.svg?v20210804" />
|
||||
<link href="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/xterm/4.11.0/xterm.css" type="text/css" rel="stylesheet"/>
|
||||
<link href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/xterm/4.11.0/xterm.css" type="text/css" rel="stylesheet"/>
|
||||
</head>
|
||||
|
||||
<style>
|
||||
@@ -28,9 +28,9 @@
|
||||
|
||||
<body onresize="onResize()">
|
||||
<div id="terminal-container"></div>
|
||||
<script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/xterm/4.11.0/xterm.js" type="application/javascript"></script>
|
||||
<script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/xterm/4.11.0/addons/attach/xterm-addon-attach.js"></script>
|
||||
<script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/xterm/4.11.0/addons/fit/xterm-addon-fit.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/xterm/4.11.0/xterm.js" type="application/javascript"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/xterm/4.11.0/addons/attach/xterm-addon-attach.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/xterm/4.11.0/addons/fit/xterm-addon-fit.js"></script>
|
||||
<script>
|
||||
let sendResizing = false;
|
||||
|
||||
|
||||
+4
-4
@@ -8,11 +8,11 @@
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/semantic-ui/2.4.1/semantic.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/semantic-ui/2.4.1/semantic.min.js"></script>
|
||||
<script src="/static/semantic-ui-alerts.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
|
||||
<script src="/static/main.js?v20230614"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/vue/2.6.14/vue.min.js"></script>
|
||||
<script src="/static/main.js?v20240224"></script>
|
||||
<script>
|
||||
(function () {
|
||||
updateLang({{.LANG }});
|
||||
|
||||
+3
-3
@@ -9,10 +9,10 @@
|
||||
<meta content="telephone=no" name="format-detection">
|
||||
<title>{{.Title}}</title>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="https://cdn.staticfile.org/semantic-ui/2.4.1/semantic.min.css">
|
||||
<link href="https://cdn.staticfile.org/font-logos/0.17/font-logos.min.css" type="text/css"
|
||||
href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/semantic-ui/2.4.1/semantic.min.css">
|
||||
<link href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/font-logos/0.17/font-logos.min.css" type="text/css"
|
||||
rel="stylesheet" />
|
||||
<link href="https://cdn.staticfile.org/bootstrap-icons/1.10.3/font/bootstrap-icons.css" type="text/css"
|
||||
<link href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/bootstrap-icons/1.8.1/font/bootstrap-icons.min.css" type="text/css"
|
||||
rel="stylesheet" />
|
||||
<link rel="stylesheet" type="text/css" href="/static/semantic-ui-alerts.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/main.css?v2022042314">
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
<div v-for="server in group.data" :id="server.ID" class="ui card">
|
||||
<div class="content" v-if="server.Host" style="margin-top: 10px; padding-bottom: 5px">
|
||||
<div class="header">
|
||||
<img v-if="server.Host.CountryCode" style="border-radius: 50%;box-shadow:-1px -1px 2px #eee, 1px 1px 2px #000;width:19px;" :src="'https://cdn.staticfile.org/flag-icon-css/6.6.5/flags/1x1/'+server.Host.CountryCode + '.svg'" alt="国家"/> <i v-if='server.Host.Platform == "darwin"'
|
||||
<img v-if="server.Host.CountryCode" style="border-radius: 50%;box-shadow:-1px -1px 2px #eee, 1px 1px 2px #000;width:19px;" :src="'https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/flag-icon-css/4.1.5/flags/1x1/'+server.Host.CountryCode + '.svg'" alt="国家"/> <i v-if='server.Host.Platform == "darwin"'
|
||||
class="apple icon"></i><i v-else-if='isWindowsPlatform(server.Host.Platform)'
|
||||
class="windows icon"></i><i v-else :class="'fl-' + getFontLogoClass(server.Host.Platform)"></i>
|
||||
@#server.Name + (server.live?'':'[{{tr "Offline"}}]')#@
|
||||
|
||||
+5
-4
@@ -10,8 +10,8 @@
|
||||
<link rel="shortcut icon" type="image/png" href="/static/logo.svg?v20210804" />
|
||||
|
||||
<link rel="stylesheet" href="/static/theme-daynight/css/main.css?v202108042286">
|
||||
<link href="https://cdn.staticfile.org/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
|
||||
<link href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/jquery/3.6.0/jquery.min.js"></script>
|
||||
|
||||
{{if ts .CustomCode}}
|
||||
{{.CustomCode|safe}}
|
||||
@@ -39,6 +39,7 @@
|
||||
<ul>
|
||||
<li><a href="/">{{tr "Home"}}</a></li>
|
||||
<li><a href="/service">{{tr "Services"}}</a></li>
|
||||
<li><a href="/network">{{tr "NetworkSpiter"}}</a></li>
|
||||
{{if .Admin}}
|
||||
<li><a href="/server">{{tr "AdminPanel"}}</a></li>
|
||||
{{else}}
|
||||
@@ -165,8 +166,8 @@
|
||||
</footer>
|
||||
|
||||
<script src="/static/theme-daynight/js/main.js?v202102012266"></script>
|
||||
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/limonte-sweetalert2/11.4.4/sweetalert2.all.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/vue/2.6.14/vue.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/limonte-sweetalert2/11.4.4/sweetalert2.all.min.js"></script>
|
||||
|
||||
<script>
|
||||
const initData = JSON.parse('{{.Servers}}').servers;
|
||||
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
{{define "theme-daynight/network"}}
|
||||
<!doctype html>
|
||||
<html lang="{{.Conf.Language}}">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<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.svg?v20210804" />
|
||||
|
||||
<link rel="stylesheet" href="/static/theme-daynight/css/main.css?v202108042286">
|
||||
<link href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/echarts/5.3.0-rc.1/echarts.min.js"></script>
|
||||
|
||||
{{if ts .CustomCode}}
|
||||
{{.CustomCode|safe}}
|
||||
{{end}}
|
||||
</head>
|
||||
|
||||
<body data-theme="light" data-gridlist="grid">
|
||||
<header>
|
||||
<section class="nav-bar clearfix">
|
||||
<figure class="logo">
|
||||
<a href="/">
|
||||
<img src="/static/logo.svg?v20210804" alt='{{tr "NezhaMonitoring"}}' width="50" height="50">
|
||||
</a>
|
||||
<a href="/">{{.Conf.Site.Brand}}</a>
|
||||
</figure>
|
||||
<div class="icon-container">
|
||||
<div class="row cf">
|
||||
<div class="three col">
|
||||
<div class="hamburger" id="hamburger-icon"><span class="line"></span><span
|
||||
class="line"></span><span class="line"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<nav class="nav-menu">
|
||||
<ul>
|
||||
<li><a href="/">{{tr "Home"}}</a></li>
|
||||
<li><a href="/service">{{tr "Services"}}</a></li>
|
||||
<li><a href="/network">{{tr "NetworkSpiter"}}</a></li>
|
||||
{{if .Admin}}
|
||||
<li><a href="/server">{{tr "AdminPanel"}}</a></li>
|
||||
{{else}}
|
||||
<li><a href="/login">{{tr "Login"}}</a></li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</nav>
|
||||
</section>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<div id="network">
|
||||
<div class="server-info-container" v-for='server in servers' :id="server.ID" style="font-size: .6em">
|
||||
<div class="info-body" @click="redirectNetwork(server.ID)">
|
||||
<ul class="server-info-body-container">
|
||||
<li>
|
||||
<h3>@#server.Name#@</h3>
|
||||
</li>
|
||||
<li><img :src="'/static/theme-daynight/img/flag/'+(server.Host&&server.Host.CountryCode?server.Host.CountryCode.toUpperCase():'CN')+'.png'"
|
||||
:title="server.Host.CountryCode.toUpperCase()" /></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="network-chart" style="height: 800px;overflow: hidden">
|
||||
<div id="monitor-info-container" style="height: 520px;max-width: 1400px">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sidebar-container">
|
||||
<ul>
|
||||
<li><i class="fas fa-sun" title='{{tr "LightMode"}}'></i><span>{{tr "LightMode"}}</span></li>
|
||||
<li><i class="fas fa-moon" title='{{tr "DarkMode"}}'></i><span>{{tr "DarkMode"}}</span></li>
|
||||
<li><i class="fas fa-th" title='{{tr "GridLayout"}}'></i><span>{{tr "GridLayout"}}</span></li>
|
||||
<li><i class="fas fa-list-ul" title='{{tr "ListLayout"}}'></i><span>{{tr "ListLayout"}}</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<section class="dark-light-toggle">
|
||||
<label class="switcher">
|
||||
<input type="checkbox" name="theme" id="dark-light" />
|
||||
<div>
|
||||
<i class="fas fa-adjust"></i>
|
||||
</div>
|
||||
</label>
|
||||
</section>
|
||||
|
||||
<!-- Back to top button -->
|
||||
<a id="back-to-top"></a>
|
||||
|
||||
<footer>
|
||||
<div class="footer-container">
|
||||
<div><a href="https://github.com/naiba/nezha" target="_blank">Powered by {{tr "NezhaMonitoring"}} · {{.Version}}</a>
|
||||
<p>© <span id="copyright-date">
|
||||
<script>document.getElementById('copyright-date').appendChild(document.createTextNode(new Date().getFullYear()))</script>
|
||||
</span> · <a href="https://blog.jackiesung.com" target="_blank">Theme designed by Jackie Sung</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="/static/theme-daynight/js/main.js?v202102012266"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/vue/2.6.14/vue.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/limonte-sweetalert2/11.4.4/sweetalert2.all.min.js"></script>
|
||||
|
||||
<script>
|
||||
const monitorInfo = JSON.parse('{{.MonitorInfos}}');
|
||||
const initData = JSON.parse('{{.Servers}}').servers;
|
||||
let MaxTCPPingValue = {{.MaxTCPPingValue}};
|
||||
if (MaxTCPPingValue == null) {
|
||||
MaxTCPPingValue = 300;
|
||||
}
|
||||
// 基于准备好的dom,初始化echarts实例
|
||||
var myChart = echarts.init(document.getElementById('monitor-info-container'));
|
||||
// 使用刚指定的配置项和数据显示图表。
|
||||
var statusCards = new Vue({
|
||||
el: '#network',
|
||||
delimiters: ['@#', '#@'],
|
||||
data: {
|
||||
servers: initData,
|
||||
cache: [],
|
||||
option: {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
position: function (pt) {
|
||||
return [pt[0], '10%'];
|
||||
},
|
||||
formatter: function(params){
|
||||
let result = params[0].axisValueLabel + "<br />";
|
||||
params.forEach(function(item){
|
||||
result += item.marker + item.seriesName + ": " + item.value[1].toFixed(2) + " ms<br />";
|
||||
})
|
||||
return result;
|
||||
},
|
||||
confine: true,
|
||||
transitionDuration: 0
|
||||
},
|
||||
title: {
|
||||
left: 'center',
|
||||
text: "",
|
||||
textStyle: {}
|
||||
},
|
||||
legend: {
|
||||
top: '5%',
|
||||
data: [],
|
||||
textStyle: {
|
||||
fontSize: 14
|
||||
}
|
||||
},
|
||||
toolbox: {
|
||||
feature: {
|
||||
dataZoom: {
|
||||
yAxisIndex: 'none'
|
||||
},
|
||||
restore: {},
|
||||
saveAsImage: {}
|
||||
}
|
||||
},
|
||||
dataZoom: [
|
||||
{
|
||||
start: 94,
|
||||
end: 100
|
||||
}
|
||||
],
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
boundaryGap: false
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
boundaryGap: [0, '100%']
|
||||
},
|
||||
series: [],
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.DarkMode();
|
||||
this.parseMonitorInfo(monitorInfo);
|
||||
},
|
||||
methods: {
|
||||
DarkMode() {
|
||||
const hour = new Date(Date.now()).getHours()
|
||||
if (hour > 17 || hour < 4) {
|
||||
document.querySelector("input[name=theme]").checked = true;
|
||||
document.getElementsByTagName("BODY")[0].setAttribute('data-theme', 'dark');
|
||||
document.getElementById("monitor-info-container").style.backgroundColor = "#1E1E1E";
|
||||
}
|
||||
},
|
||||
redirectNetwork(id) {
|
||||
this.getMonitorHistory(id)
|
||||
.then(function(monitorInfo) {
|
||||
var vm = network.__vue__;
|
||||
vm.parseMonitorInfo(monitorInfo);
|
||||
})
|
||||
.catch(function(error){
|
||||
window.location.href = "/404";
|
||||
})
|
||||
},
|
||||
getMonitorHistory(id) {
|
||||
return $.ajax({
|
||||
url: "/api/v1/monitor/"+id,
|
||||
method: "GET"
|
||||
});
|
||||
},
|
||||
parseMonitorInfo(monitorInfo) {
|
||||
let tSeries = [];
|
||||
let tLegendData = [];
|
||||
for (let i = 0; i < monitorInfo.result.length; i++) {
|
||||
let loss = 0;
|
||||
let data = [];
|
||||
for (let j = 0; j < monitorInfo.result[i].created_at.length; j++) {
|
||||
avgDelay = monitorInfo.result[i].avg_delay[j];
|
||||
if (avgDelay > 0.9 * MaxTCPPingValue) {
|
||||
loss += 1
|
||||
}
|
||||
data.push([monitorInfo.result[i].created_at[j], avgDelay]);
|
||||
}
|
||||
lossRate = ((loss / monitorInfo.result[i].created_at.length) * 100).toFixed(1);
|
||||
legendName = monitorInfo.result[i].monitor_name +" "+ lossRate + "%";
|
||||
tLegendData.push(legendName);
|
||||
tSeries.push({
|
||||
name: legendName,
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
data: data
|
||||
});
|
||||
}
|
||||
this.option.title.text = monitorInfo.result[0].server_name;
|
||||
this.option.series = tSeries;
|
||||
this.option.legend.data = tLegendData;
|
||||
const hour = new Date(Date.now()).getHours()
|
||||
if (hour > 17 || hour < 4) {
|
||||
this.option.legend.textStyle.color = "#F1F1F2";
|
||||
this.option.title.textStyle.color = "#ccc";
|
||||
}
|
||||
myChart.clear();
|
||||
myChart.setOption(this.option);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
<style>
|
||||
#network {
|
||||
display: grid;
|
||||
/*grid-template-columns: repeat(5, 1fr);*/
|
||||
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
|
||||
grid-gap: 1em;
|
||||
width: 100%;
|
||||
width: calc(100vw - 6em);
|
||||
max-width: 1400px;
|
||||
margin: 1em auto;
|
||||
align-content: start;
|
||||
}
|
||||
#monitor-info-container{
|
||||
margin: 0em auto;
|
||||
align-content: start;
|
||||
background-color: #F1F1F2;
|
||||
}
|
||||
</style>
|
||||
|
||||
</html>
|
||||
{{end}}
|
||||
|
||||
+5
-4
@@ -8,9 +8,9 @@
|
||||
<title>{{.Title}}</title>
|
||||
<link rel="shortcut icon" type="image/png" href="/static/logo.svg?v20210804" />
|
||||
<link rel="stylesheet" href="/static/theme-daynight/css/service.css?v202108042286" />
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/mdui/1.0.2/css/mdui.min.css"/>
|
||||
<link href="https://cdn.staticfile.org/font-awesome/6.0.0/css/all.min.css" rel="stylesheet" />
|
||||
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
|
||||
<link rel="stylesheet" href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/mdui/1.0.2/css/mdui.min.css"/>
|
||||
<link href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/font-awesome/6.0.0/css/all.min.css" rel="stylesheet" />
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/jquery/3.6.0/jquery.min.js"></script>
|
||||
|
||||
{{if ts .CustomCode}}
|
||||
{{.CustomCode|safe}}
|
||||
@@ -43,6 +43,7 @@
|
||||
<ul>
|
||||
<li><a href="/">{{tr "Home"}}</a></li>
|
||||
<li><a href="/service">{{tr "Services"}}</a></li>
|
||||
<li><a href="/network">{{tr "NetworkSpiter"}}</a></li>
|
||||
{{if .Admin}}
|
||||
<li><a href="/server">{{tr "AdminPanel"}}</a></li>
|
||||
{{else}}
|
||||
@@ -80,7 +81,7 @@
|
||||
{{end}}
|
||||
</div>
|
||||
</section>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</section>
|
||||
{{if .CycleTransferStats}}
|
||||
<h2 class="mdui-m-t-5 mdui-text-center">{{tr "CycleTransferStats"}}</h2>
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
{{define "theme-default/footer"}}
|
||||
</div>
|
||||
<div class="ui inverted vertical footer segment">
|
||||
<div class="ui center aligned is-size-7 container">
|
||||
<b>© <a style="color: white;" href="/">{{.Conf.Site.Brand}}</a></b> | <small>Powered by <a
|
||||
href="https://github.com/naiba/nezha" style="color: white;" target="_blank">{{tr "NezhaMonitoring"}}</a>
|
||||
{{.Version}}</small>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
{{define "theme-default/header"}}
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{.Conf.Language}}">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<meta content="telephone=no" name="format-detection">
|
||||
<title>{{.Title}}</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/assets/font-logos.css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lipis/[email protected]/css/flag-icons.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/semantic-ui-alerts.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/theme-default/css/main.css?v20240222">
|
||||
<link rel="shortcut icon" type="image/png" href="/static/logo.svg" />
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.js"></script>
|
||||
<script src="/static/semantic-ui-alerts.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js"></script>
|
||||
<script src="/static/theme-server-status/js/mixin.js?v20240225"></script>
|
||||
</head>
|
||||
<body>
|
||||
{{end}}
|
||||
+233
-27
@@ -1,10 +1,10 @@
|
||||
{{define "theme-default/home"}}
|
||||
{{template "common/header" .}}
|
||||
{{template "theme-default/header" .}}
|
||||
{{if ts .CustomCode}} {{.CustomCode|safe}} {{end}}
|
||||
{{template "common/menu" .}}
|
||||
{{template "theme-default/menu" .}}
|
||||
<div class="nb-container">
|
||||
<div class="ui container">
|
||||
<div id="app">
|
||||
<div class="ui container">
|
||||
<template v-if="groups">
|
||||
<div class="ui styled fluid accordion" v-for="group in groups">
|
||||
<div class="active title">
|
||||
<i class="dropdown icon"></i>
|
||||
@@ -15,12 +15,13 @@
|
||||
<div v-for="server in group.data" :id="server.ID" class="ui card">
|
||||
<div class="content" v-if="server.Host" style="margin-top: 10px; padding-bottom: 5px">
|
||||
<div class="header">
|
||||
<i :class="server.Host.CountryCode + ' flag'"></i> <i v-if='server.Host.Platform == "darwin"'
|
||||
<i :class="'fi fi-' + server.Host.CountryCode"></i> <i v-if='server.Host.Platform == "darwin"'
|
||||
class="apple icon"></i><i v-else-if='isWindowsPlatform(server.Host.Platform)'
|
||||
class="windows icon"></i><i v-else :class="'fl-' + getFontLogoClass(server.Host.Platform)"></i>
|
||||
@#server.Name + (server.live?'':'[{{tr "Offline"}}]')#@
|
||||
<i class="nezha-secondary-font info circle icon" style="height: 28px"></i>
|
||||
<div class="ui content popup" style="margin-bottom: 0">
|
||||
<i @click="togglePopup($event, server.ID)" aria-expanded="false" class="nezha-secondary-font info circle icon" style="height: 28px"></i>
|
||||
<div class="ui content popup" :class="{ 'visible': isActive(server.ID) }" style="margin-bottom: 0;">
|
||||
<i class="closePopup window close icon" @click="closePopup(server.ID)"></i>
|
||||
{{tr "Platform"}}: @#server.Host.Platform#@-@#server.Host.PlatformVersion#@
|
||||
[<span
|
||||
v-if="server.Host.Virtualization">@#server.Host.Virtualization#@:</span>@#server.Host.Arch#@]<br />
|
||||
@@ -40,7 +41,8 @@
|
||||
{{tr "ConnCount"}}: TCP @# server.State.TcpConnCount #@ / UDP @# server.State.UdpConnCount #@<br />
|
||||
{{tr "BootTime"}}: @# formatTimestamp(server.Host.BootTime) #@<br />
|
||||
{{tr "LastActive"}}: @# new Date(server.LastActive).toLocaleString() #@<br />
|
||||
{{tr "Version"}}: @#server.Host.Version#@<br />
|
||||
{{tr "Version"}}: @#server.Host.Version#@
|
||||
<div class="chartbox" :key="server.ID" :ref="`chart${server.ID}`" style="width: 100%; height: auto; margin-bottom: 2px;"></div>
|
||||
</div>
|
||||
<div class="ui divider" style="margin-bottom: 5px"></div>
|
||||
</div>
|
||||
@@ -72,13 +74,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide column">{{tr "NetSpeed"}}</div>
|
||||
<div class="thirteen wide column">
|
||||
<i class="arrow alternate circle down outline icon"></i>
|
||||
@#formatByteSize(server.State.NetInSpeed)#@/s
|
||||
<i class="arrow alternate circle up outline icon"></i>
|
||||
@#formatByteSize(server.State.NetOutSpeed)#@/s
|
||||
</div>
|
||||
<div class="three wide column">{{tr "DiskUsed"}}</div>
|
||||
<div class="thirteen wide column">
|
||||
<div :class="formatPercent(server.live,server.State.DiskUsed, server.Host.DiskTotal).class">
|
||||
@@ -88,6 +83,36 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide column">{{tr "NetSpeed"}}</div>
|
||||
<div class="thirteen wide column">
|
||||
<i class="arrow alternate circle down outline icon"></i>
|
||||
@#formatByteSize(server.State.NetInSpeed)#@/s
|
||||
<i class="arrow alternate circle up outline icon"></i>
|
||||
@#formatByteSize(server.State.NetOutSpeed)#@/s
|
||||
</div>
|
||||
<div class="three wide column">流量</div>
|
||||
<div class="thirteen wide column">
|
||||
<i class="arrow circle down icon"></i>
|
||||
@#formatByteSize(server.State.NetInTransfer)#@
|
||||
|
||||
<i class="arrow circle up icon"></i>
|
||||
@#formatByteSize(server.State.NetOutTransfer)#@
|
||||
</div>
|
||||
<div class="three wide column">信息</div>
|
||||
<div class="thirteen wide column">
|
||||
<i class="bi bi-cpu-fill" style="font-size: 1.1rem; color: #4a86e8;"></i> @#getCoreAndGHz(server.Host.CPU)#@
|
||||
|
||||
<i class="bi bi-memory" style="font-size: 1.1rem; color: #00ac0d;"></i> @#getK2Gb(server.Host.MemTotal)#@
|
||||
|
||||
<i class="bi bi-hdd" style="font-size: 1.1rem; color: #e41e10"></i> @#getK2Gb(server.Host.DiskTotal)#@
|
||||
</div>
|
||||
<div class="three wide column">{{tr "Load"}}</div>
|
||||
<div class="thirteen wide column">
|
||||
<i class="bi bi-activity" style="font-size: 1.1rem; color: #e41e10;"></i>
|
||||
@# toFixed2(server.State.Load1) #@ |
|
||||
@# toFixed2(server.State.Load5) #@ |
|
||||
@# toFixed2(server.State.Load15) #@
|
||||
</div>
|
||||
<div class="three wide column">{{tr "Uptime"}}</div>
|
||||
<div class="thirteen wide column">
|
||||
<i class="clock icon"></i>@#secondToDate(server.State.Uptime)#@
|
||||
@@ -103,30 +128,171 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
{{template "common/footer" .}}
|
||||
{{template "theme-default/footer" .}}
|
||||
<script>
|
||||
const initData = JSON.parse('{{.Servers}}').servers;
|
||||
var statusCards = new Vue({
|
||||
el: '#app',
|
||||
delimiters: ['@#', '#@'],
|
||||
data: {
|
||||
data: initData,
|
||||
page: 'index',
|
||||
templates: {{.Themes}},
|
||||
data: [],
|
||||
groups: [],
|
||||
cache: [],
|
||||
chartDataList: [],
|
||||
activePopup: null,
|
||||
|
||||
},
|
||||
mixins: [mixinsVue],
|
||||
created() {
|
||||
this.data = JSON.parse('{{.Servers}}').servers;
|
||||
this.group()
|
||||
},
|
||||
mounted() {
|
||||
$('.nezha-secondary-font.info.icon').popup({
|
||||
popup: '.ui.content.popup',
|
||||
exclusive: true,
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
togglePopup(event, id) {
|
||||
// 切换弹出层的激活状态
|
||||
this.activePopup = this.activePopup === id ? null : id;
|
||||
this.showCharts(id);
|
||||
},
|
||||
isActive(id) {
|
||||
// 检查弹出层是否处于激活状态
|
||||
return this.activePopup === id;
|
||||
},
|
||||
closePopup(id) {
|
||||
this.activePopup = null;
|
||||
},
|
||||
showCharts(id) {
|
||||
// 发起数据请求
|
||||
const url = `/api/v1/monitor/${id}`;
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.result) { // 数据请求成功,更新数据并渲染图表
|
||||
this.chartDataList[id - 1] = data.result;
|
||||
this.$nextTick(() => {
|
||||
this.renderCharts(id);
|
||||
});
|
||||
} else {
|
||||
console.log('this agent (id:'+ id + ') has no monitor.');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching data:', error);
|
||||
});
|
||||
},
|
||||
renderCharts(id) {
|
||||
if (!this.chartDataList[id - 1]) return;
|
||||
const MaxTCPPingValue = {{.MaxTCPPingValue}} ? {{.MaxTCPPingValue}} : 300;
|
||||
const isMobile = this.checkIsMobile();
|
||||
const fontSize = isMobile ? 10 : 9;
|
||||
const itemGap = isMobile ? 5 : 2;
|
||||
const itemWidth = isMobile ? 20 : 15;
|
||||
const gridLeft = 25;
|
||||
const gridRight = 12;
|
||||
const fontColor = "rgba(0, 0, 0, 0.68)";
|
||||
const backgroundColor = '';
|
||||
const borderColor = "#ffffff";
|
||||
const chartData = this.chartDataList[id - 1];
|
||||
const chartContainer = this.$refs[`chart${id}`][0];
|
||||
const chart = echarts.init(chartContainer, null, {
|
||||
renderer: 'canvas',
|
||||
useDirtyRect: false,
|
||||
width: 'auto',
|
||||
height: 120,
|
||||
});
|
||||
const xAxisData = chartData[0].created_at.map(time => new Date(time).toLocaleString());
|
||||
const seriesData = chartData.map(item => {
|
||||
let loss = 0;
|
||||
const data = item.avg_delay.map((avgDelay, index) => {
|
||||
if (avgDelay > 0.9 * MaxTCPPingValue) {
|
||||
loss += 1;
|
||||
}
|
||||
return [new Date(item.created_at[index]).toLocaleString(), avgDelay];
|
||||
});
|
||||
const lossRate = ((loss / item.created_at.length) * 100).toFixed(1);
|
||||
item.monitor_name = item.monitor_name + " " + lossRate + "%";
|
||||
return {
|
||||
name: item.monitor_name,
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
data: data
|
||||
};
|
||||
});
|
||||
const option = {
|
||||
backgroundColor: backgroundColor,
|
||||
title: {
|
||||
show: false
|
||||
},
|
||||
tooltip: {
|
||||
show: true,
|
||||
trigger: 'axis',
|
||||
textStyle: {
|
||||
fontSize: fontSize,
|
||||
color: fontColor
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
data: chartData.map(item => item.monitor_name),
|
||||
show: true,
|
||||
textStyle: {
|
||||
fontSize: fontSize,
|
||||
color: fontColor
|
||||
},
|
||||
lineStyle: {
|
||||
cap: 'butt'
|
||||
},
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
itemGap: itemGap,
|
||||
itemWidth: itemWidth,
|
||||
padding: [5,0,5,0]
|
||||
},
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
data: xAxisData,
|
||||
axisLabel: {
|
||||
textStyle: {
|
||||
fontSize: fontSize
|
||||
}
|
||||
}
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
axisLabel: {
|
||||
textStyle: {
|
||||
fontSize: fontSize
|
||||
}
|
||||
}
|
||||
},
|
||||
dataZoom: [
|
||||
{
|
||||
show: false,
|
||||
type: 'slider',
|
||||
start: 0,
|
||||
end: 100
|
||||
}
|
||||
],
|
||||
series: seriesData,
|
||||
textStyle: {
|
||||
fontSize: fontSize,
|
||||
color: fontColor
|
||||
},
|
||||
grid: {
|
||||
top: '40',
|
||||
bottom: '20',
|
||||
left: gridLeft,
|
||||
right: gridRight
|
||||
}
|
||||
};
|
||||
chart.setOption(option);
|
||||
},
|
||||
checkIsMobile() { // 检测设备类型,页面宽度小于768px认为是移动设备
|
||||
return window.innerWidth <= 768;
|
||||
},
|
||||
toFixed2(f) {
|
||||
return f.toFixed(2)
|
||||
},
|
||||
@@ -227,7 +393,7 @@
|
||||
secondToDate(s) {
|
||||
var d = Math.floor(s / 3600 / 24);
|
||||
if (d > 0) {
|
||||
return d + ' {{tr "Day"}}'
|
||||
return d + " {{tr "Day"}}"
|
||||
}
|
||||
var h = Math.floor(s / 3600 % 24);
|
||||
var m = Math.floor(s / 60 % 60);
|
||||
@@ -238,8 +404,48 @@
|
||||
return new Date(t * 1000).toLocaleString()
|
||||
},
|
||||
formatByteSize(bs) {
|
||||
const x = readableBytes(bs)
|
||||
const x = this.readableBytes(bs)
|
||||
return x != "NaN undefined" ? x : '0B'
|
||||
},
|
||||
readableBytes(bytes) {
|
||||
if (!bytes) {
|
||||
return '0B'
|
||||
}
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1024)),
|
||||
sizes = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];
|
||||
return parseFloat((bytes / Math.pow(1024, i)).toFixed(2)) + sizes[i];
|
||||
},
|
||||
getCoreAndGHz(str){
|
||||
if((str || []).hasOwnProperty(0) === false){
|
||||
return '';
|
||||
}
|
||||
str = str[0];
|
||||
let GHz = str.match(/(\d|\.)+GHz/g);
|
||||
let Core = str.match(/(\d|\.)+ Physical/g);
|
||||
GHz = GHz!==null?GHz.hasOwnProperty(0)===false?'':GHz[0]:''
|
||||
Core = Core!==null?Core.hasOwnProperty(0)===false?'?':Core[0]:'?'
|
||||
if(Core === '?'){
|
||||
let Core = str.match(/(\d|\.)+ Virtual/g);
|
||||
Core = Core!==null?Core.hasOwnProperty(0)===false?'?':Core[0]:'?'
|
||||
return Core.replace('Virtual','Core')
|
||||
}
|
||||
return Core.replace('Physical','Core');
|
||||
},
|
||||
getK2Gb(bs){
|
||||
bs = bs / 1024 /1024 /1024;
|
||||
if(bs>=1){
|
||||
return Math.ceil(bs.toFixed(2)) + 'GB';
|
||||
}else{
|
||||
bs = bs * 1024;
|
||||
return Math.ceil(bs.toFixed(2)) + 'MB';
|
||||
}
|
||||
},
|
||||
listTipsMouseenter(obj,strs,tipsNum=1){
|
||||
this.layerIndex = layer.tips(strs, '#'+obj,{tips: [tipsNum, 'rgb(0 0 0 / 85%)'],time:0});
|
||||
$('#'+obj).attr('layerIndex',this.layerIndex)
|
||||
},
|
||||
listTipsMouseleave(obj){
|
||||
layer.close(this.layerIndex)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
{{define "theme-default/menu"}}
|
||||
<div id="app">
|
||||
<div class="ui large top fixed menu nb-menu" style="z-index:9999999;">
|
||||
<div class="ui container">
|
||||
<a class="item" href="/">
|
||||
<img src="/static/logo.svg?v20210804">
|
||||
</a>
|
||||
<a class='item' href="/"><i class="home icon"></i>{{tr "Home"}}</a>
|
||||
<template v-if="isMobile">
|
||||
<div class="item ui simple dropdown">
|
||||
<div class="text"><i class="bi bi-gear-wide-connected icon" style="margin-right:3px;"></i>{{tr "Feature" }}<i class="dropdown icon" style="margin-right:0px;"></i></div>
|
||||
<div class="menu">
|
||||
<a href="/service" class="item"><i class="rss icon"></i>{{tr "Services" }}</a>
|
||||
<a href="/network" class="item"><i class="bi bi-hdd-network icon"></i>{{tr "NetworkSpiter"}}</a>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<a href="/service" class='item'><i class="rss icon"></i>{{tr "Services" }}</a>
|
||||
<a href="/network" class="item"><i class="bi bi-hdd-network icon"></i>{{tr "NetworkSpiter"}}</a>
|
||||
</template>
|
||||
<div class="item ui simple dropdown">
|
||||
<div class="text"><i class="bi bi-incognito icon" style="margin-right:3px;"></i>{{tr "Template" }}<i class="dropdown icon" style="margin-right:0px;"></i></div>
|
||||
<div class="menu">
|
||||
<a v-for="(value, key) in templates" :key="key" @click="toggleTemplate(key)" class="item"><i class="th large icon"></i>@#value#@
|
||||
<i class="check icon" v-if="preferredTemplate === key"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{{if .Admin}}
|
||||
<div class="item right item-right ui simple dropdown">
|
||||
<div class="text">
|
||||
<i class="user icon" style="margin-right:3px"></i>{{.Admin.Name}}
|
||||
<i class="dropdown icon"></i>
|
||||
</div>
|
||||
<div class="menu">
|
||||
<a class="item" href="/server"><i class="terminal icon"></i>{{tr "AdminPanel"}}</a>
|
||||
<a class="item" @click="logOut({{.Admin.ID}})"><i class="logout icon"></i>{{tr "Logout"}}</a>
|
||||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<a href="/login" class="item right item-right" style="padding-right:1.2rem"><i class="sign-in icon"></i>{{tr "Login"}}</a>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{template "component/confirm" .}}
|
||||
{{end}}
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
{{define "theme-default/network"}}
|
||||
{{template "theme-default/header" .}}
|
||||
{{if ts .CustomCode}}
|
||||
{{.CustomCode|safe}}
|
||||
{{end}}
|
||||
{{template "theme-default/menu" .}}
|
||||
<div class="nb-container">
|
||||
<div class="ui container">
|
||||
<div class="service-status">
|
||||
<table class="ui celled table">
|
||||
<button class="ui nezha-primary-btn button"
|
||||
v-for="server in servers"
|
||||
style="margin-top: 3px"
|
||||
@click="redirectNetwork(server.ID)">
|
||||
@#server.Name#@ <i :class="server.Host.CountryCode + ' flag'"></i>
|
||||
</button>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui container" style="max-width: 95vw">
|
||||
<div ref="chartDom" style="border-radius: 28px; margin-top: 15px;height: 520px;max-width: 1400px;overflow: hidden"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{template "theme-default/footer" .}}
|
||||
|
||||
<script>
|
||||
const monitorInfo = JSON.parse('{{.MonitorInfos}}');
|
||||
const initData = JSON.parse('{{.Servers}}').servers;
|
||||
let MaxTCPPingValue = {{.MaxTCPPingValue}};
|
||||
if (MaxTCPPingValue == null) {
|
||||
MaxTCPPingValue = 1000;
|
||||
}
|
||||
new Vue({
|
||||
el: '#app',
|
||||
delimiters: ['@#', '#@'],
|
||||
data: {
|
||||
page: 'network',
|
||||
templates: {{.Themes}},
|
||||
servers: initData,
|
||||
option: {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
position: function (pt) {
|
||||
return [pt[0], '10%'];
|
||||
},
|
||||
formatter: function(params){
|
||||
let result = params[0].axisValueLabel + "<br />";
|
||||
params.forEach(function(item){
|
||||
result += item.marker + item.seriesName + ": " + item.value[1].toFixed(2) + " ms<br />";
|
||||
})
|
||||
return result;
|
||||
},
|
||||
confine: true,
|
||||
transitionDuration: 0
|
||||
},
|
||||
title: {
|
||||
left: 'center',
|
||||
text: "",
|
||||
textStyle: {}
|
||||
},
|
||||
legend: {
|
||||
top: '5%',
|
||||
data: [],
|
||||
textStyle: {
|
||||
fontSize: 14
|
||||
}
|
||||
},
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.8)',
|
||||
toolbox: {
|
||||
feature: {
|
||||
dataZoom: {
|
||||
yAxisIndex: 'none'
|
||||
},
|
||||
restore: {},
|
||||
saveAsImage: {}
|
||||
}
|
||||
},
|
||||
dataZoom: [
|
||||
{
|
||||
start: 0,
|
||||
end: 100
|
||||
}
|
||||
],
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
boundaryGap: false
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
boundaryGap: false
|
||||
},
|
||||
series: [],
|
||||
},
|
||||
chartOnOff: true,
|
||||
},
|
||||
mixins: [mixinsVue],
|
||||
mounted() {
|
||||
this.renderChart();
|
||||
this.parseMonitorInfo(monitorInfo);
|
||||
},
|
||||
methods: {
|
||||
getFontLogoClass(str) {
|
||||
if (["almalinux",
|
||||
"alpine",
|
||||
"aosc",
|
||||
"apple",
|
||||
"archlinux",
|
||||
"archlabs",
|
||||
"artix",
|
||||
"budgie",
|
||||
"centos",
|
||||
"coreos",
|
||||
"debian",
|
||||
"deepin",
|
||||
"devuan",
|
||||
"docker",
|
||||
"elementary",
|
||||
"fedora",
|
||||
"ferris",
|
||||
"flathub",
|
||||
"freebsd",
|
||||
"gentoo",
|
||||
"gnu-guix",
|
||||
"illumos",
|
||||
"kali-linux",
|
||||
"linuxmint",
|
||||
"mageia",
|
||||
"mandriva",
|
||||
"manjaro",
|
||||
"nixos",
|
||||
"openbsd",
|
||||
"opensuse",
|
||||
"pop-os",
|
||||
"raspberry-pi",
|
||||
"redhat",
|
||||
"rocky-linux",
|
||||
"sabayon",
|
||||
"slackware",
|
||||
"snappy",
|
||||
"solus",
|
||||
"tux",
|
||||
"ubuntu",
|
||||
"void",
|
||||
"zorin"].indexOf(str)
|
||||
> -1) {
|
||||
return str;
|
||||
}
|
||||
if (['openwrt', 'linux', "immortalwrt"].indexOf(str) > -1) {
|
||||
return 'tux';
|
||||
}
|
||||
if (str == 'amazon') {
|
||||
return 'redhat';
|
||||
}
|
||||
if (str == 'arch') {
|
||||
return 'archlinux';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
redirectNetwork(id) {
|
||||
this.getMonitorHistory(id)
|
||||
.then(function(monitorInfo) {
|
||||
var vm = app.__vue__;
|
||||
vm.parseMonitorInfo(monitorInfo);
|
||||
})
|
||||
.catch(function(error){
|
||||
window.location.href = "/404";
|
||||
})
|
||||
},
|
||||
getMonitorHistory(id) {
|
||||
return $.ajax({
|
||||
url: "/api/v1/monitor/"+id,
|
||||
method: "GET"
|
||||
});
|
||||
},
|
||||
parseMonitorInfo(monitorInfo) {
|
||||
let tSeries = [];
|
||||
let tLegendData = [];
|
||||
for (let i = 0; i < monitorInfo.result.length; i++) {
|
||||
let loss = 0;
|
||||
let data = [];
|
||||
for (let j = 0; j < monitorInfo.result[i].created_at.length; j++) {
|
||||
avgDelay = Math.round(monitorInfo.result[i].avg_delay[j]);
|
||||
if (avgDelay > 0.9 * MaxTCPPingValue) {
|
||||
loss += 1
|
||||
}
|
||||
if (avgDelay > 0) {
|
||||
data.push([monitorInfo.result[i].created_at[j], avgDelay]);
|
||||
}
|
||||
}
|
||||
lossRate = ((loss / monitorInfo.result[i].created_at.length) * 100).toFixed(1);
|
||||
legendName = monitorInfo.result[i].monitor_name +" "+ lossRate + "%";
|
||||
tLegendData.push(legendName);
|
||||
tSeries.push({
|
||||
name: legendName,
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
data: data,
|
||||
markPoint: {
|
||||
data: [
|
||||
{ type: 'max', symbol: 'pin', name: 'Max', itemStyle: { color: '#f00' } },
|
||||
{ type: 'min', symbol: 'pin', name: 'Min', itemStyle: { color: '#0f0' } }
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
this.option.title.text = monitorInfo.result[0].server_name;
|
||||
this.option.series = tSeries;
|
||||
this.option.legend.data = tLegendData;
|
||||
this.myChart.clear();
|
||||
this.myChart.setOption(this.option);
|
||||
},
|
||||
isWindowsPlatform(str) {
|
||||
return str.includes('Windows')
|
||||
},
|
||||
renderChart() {
|
||||
this.myChart = echarts.init(this.$refs.chartDom);
|
||||
this.myChart.setOption(this.option);
|
||||
},
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.myChart.dispose();
|
||||
this.myChart = null;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
{{end}}
|
||||
+14
-4
@@ -1,9 +1,9 @@
|
||||
{{define "theme-default/service"}}
|
||||
{{template "common/header" .}}
|
||||
{{template "theme-default/header" .}}
|
||||
{{if ts .CustomCode}}
|
||||
{{.CustomCode|safe}}
|
||||
{{end}}
|
||||
{{template "common/menu" .}}
|
||||
{{template "theme-default/menu" .}}
|
||||
<div class="nb-container">
|
||||
<div class="ui container">
|
||||
<div class="service-status">
|
||||
@@ -76,10 +76,20 @@
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{template "common/footer" .}}
|
||||
{{template "theme-default/footer" .}}
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
delimiters: ['@#', '#@'],
|
||||
data: {
|
||||
page: 'service',
|
||||
templates: {{.Themes}}
|
||||
},
|
||||
mixins: [mixinsVue]
|
||||
})
|
||||
</script>
|
||||
{{end}}
|
||||
+5
-5
@@ -14,8 +14,8 @@
|
||||
<meta http-equiv="Content-Language" content="zh" />
|
||||
|
||||
<!-- Styles -->
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/semantic-ui/2.4.1/semantic.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/font-awesome/6.0.0/css/all.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/semantic-ui/2.4.1/semantic.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/font-awesome/6.0.0/css/all.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/semantic-ui-alerts.min.css">
|
||||
<link rel="stylesheet" href="/static/theme-hotaru/css/core.css?v202012121912" type="text/css">
|
||||
<link rel="stylesheet" href="/static/theme-hotaru/css/main.css?v202101171153" type="text/css">
|
||||
@@ -141,10 +141,10 @@
|
||||
<a href="/server">{{tr "AdminPanel"}}</a>
|
||||
</p>
|
||||
</footer>
|
||||
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/semantic-ui/2.4.1/semantic.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/semantic-ui/2.4.1/semantic.min.js"></script>
|
||||
<script src="/static/semantic-ui-alerts.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/vue/2.6.14/vue.min.js"></script>
|
||||
<script>
|
||||
const initData = JSON.parse('{{.Servers}}').servers;
|
||||
var statusCards = new Vue({
|
||||
|
||||
+5
-5
@@ -9,7 +9,7 @@
|
||||
<link rel="shortcut icon" type="image/png" href="/static/logo.svg?v20210804" />
|
||||
|
||||
<!-- MDUI CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/mdui/1.0.2/css/mdui.min.css"/>
|
||||
<link rel="stylesheet" href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/mdui/1.0.2/css/mdui.min.css"/>
|
||||
<link rel="stylesheet" href="/static/theme-mdui/mdui.css" type="text/css">
|
||||
<style>
|
||||
.mdui-table td, .mdui-table th{padding: 6px;}
|
||||
@@ -37,7 +37,7 @@
|
||||
<div class="mdui-col" v-for='server in servers' :id="server.ID">
|
||||
<div :class="'mdui-card mt' + (server.live?'':' offline')">
|
||||
<div class="mdui-card-header">
|
||||
<img class="mdui-card-header-avatar" :src="'https://cdn.staticfile.org/flag-icon-css/4.1.5/flags/1x1/' + (server.Host.CountryCode?server.Host.CountryCode:'cn') + '.svg'"/>
|
||||
<img class="mdui-card-header-avatar" :src="'https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/flag-icon-css/4.1.5/flags/1x1/' + (server.Host.CountryCode?server.Host.CountryCode:'cn') + '.svg'"/>
|
||||
<div class="mdui-card-header-title">@#server.Name#@</div>
|
||||
<div class="mdui-card-header-subtitle">@#server.Host.CountryCode.toUpperCase()#@ | @#server.Host.Platform#@ @#server.Host.PlatformVersion#@</div>
|
||||
</div>
|
||||
@@ -153,9 +153,9 @@
|
||||
{{template "theme-mdui/footer" .}}
|
||||
|
||||
<script src="/static/theme-mdui/mdui.js"></script>
|
||||
<script src="https://cdn.staticfile.org/mdui/1.0.2/js/mdui.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/mdui/1.0.2/js/mdui.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/vue/2.6.14/vue.min.js"></script>
|
||||
|
||||
<script>
|
||||
var container=document.querySelector("#container");
|
||||
|
||||
+1
@@ -12,6 +12,7 @@
|
||||
{{else}}
|
||||
<a href="/" class='mdui-ripple mdui-ripple-white mdui-hoverable{{if eq .MatchedPath "/"}} mdui-tab-active{{end}}'><i class="mdui-icon material-icons">home</i>{{tr "Home"}}</a>
|
||||
<a href="/service" class='mdui-ripple mdui-ripple-white mdui-hoverable{{if eq .MatchedPath "/service"}} mdui-tab-active{{end}}'><i class="mdui-icon material-icons">accessibility</i>{{tr "Services"}}</a>
|
||||
<a href="/network" class='mdui-ripple mdui-ripple-white mdui-hoverable{{if eq .MatchedPath "/network"}} mdui-tab-active{{end}}'><i class="mdui-icon material-icons">network_check</i>{{tr "NetworkSpiter"}}</a>
|
||||
{{end}}
|
||||
<div class="mdui-toolbar-spacer"></div>
|
||||
{{if .Admin}}
|
||||
|
||||
+255
@@ -0,0 +1,255 @@
|
||||
{{define "theme-mdui/network"}}
|
||||
<!doctype html>
|
||||
<html lang="{{.Conf.Language}}">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>{{.Title}}</title>
|
||||
<link rel="shortcut icon" type="image/png" href="/static/logo.svg?v20210804" />
|
||||
|
||||
<!-- MDUI CSS -->
|
||||
<link rel="stylesheet" href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/mdui/1.0.2/css/mdui.min.css"/>
|
||||
<link rel="stylesheet" href="/static/theme-mdui/mdui.css" type="text/css">
|
||||
<style>
|
||||
.mdui-table td, .mdui-table th{padding: 6px;}
|
||||
.progress{width: 10%;min-width: 75px;}
|
||||
.progress-text{font-size: 16px;font-weight: 800;position: relative;top: 4px;left: 6px;}
|
||||
.offline st,.offline at,.offline gt,.offline .progress-text{color: grey;}
|
||||
a{text-decoration:none;color:#333;}.mdui-theme-layout-dark a{color:#fff;}
|
||||
</style>
|
||||
{{if ts .CustomCode}}
|
||||
{{.CustomCode|safe}}
|
||||
{{end}}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{{template "theme-mdui/menu" .}}
|
||||
<div class="nb-container" id="app">
|
||||
<div class="ui container">
|
||||
<div class="service-status">
|
||||
<table class="ui celled table">
|
||||
<button
|
||||
v-for="server in servers"
|
||||
@click="redirectNetwork(server.ID)"
|
||||
class="mdui-btn mdui-btn-raised mdui-color-theme mdui-color-indigo mdui-text-color-white"
|
||||
style="margin-top: 6px;margin-left:5px">
|
||||
<img :src="'https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/flag-icon-css/4.1.5/flags/4x3/' + (server.Host.CountryCode?server.Host.CountryCode:'cn') + '.svg'" alt="Flag Icon" style="vertical-align: middle;height:14px"> <span>@#server.Name#@ </span></button>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui container" style="max-width: 95vw">
|
||||
<div ref="chartDom" style="border-radius: 28px; margin-top: 15px;height: 520px;max-width: 1400px;overflow: hidden"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{template "theme-mdui/footer" .}}
|
||||
<script src="/static/theme-mdui/mdui.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/mdui/1.0.2/js/mdui.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/vue/2.6.14/vue.min.js"></script>
|
||||
|
||||
<script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/echarts/5.3.0-rc.1/echarts.min.js"></script>
|
||||
|
||||
<script>
|
||||
const monitorInfo = JSON.parse('{{.MonitorInfos}}');
|
||||
const initData = JSON.parse('{{.Servers}}').servers;
|
||||
let MaxTCPPingValue = {{.MaxTCPPingValue}};
|
||||
if (MaxTCPPingValue == null) {
|
||||
MaxTCPPingValue = 1000;
|
||||
}
|
||||
new Vue({
|
||||
el: '#app',
|
||||
delimiters: ['@#', '#@'],
|
||||
data: {
|
||||
servers: initData,
|
||||
option: {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
position: function (pt) {
|
||||
return [pt[0], '10%'];
|
||||
},
|
||||
formatter: function(params){
|
||||
let result = params[0].axisValueLabel + "<br />";
|
||||
params.forEach(function(item){
|
||||
result += item.marker + item.seriesName + ": " + item.value[1].toFixed(2) + " ms<br />";
|
||||
})
|
||||
return result;
|
||||
},
|
||||
confine: true,
|
||||
transitionDuration: 0
|
||||
},
|
||||
title: {
|
||||
left: 'center',
|
||||
text: "",
|
||||
textStyle: {}
|
||||
},
|
||||
legend: {
|
||||
top: '5%',
|
||||
data: [],
|
||||
textStyle: {
|
||||
fontSize: 14
|
||||
}
|
||||
},
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.8)',
|
||||
toolbox: {
|
||||
feature: {
|
||||
dataZoom: {
|
||||
yAxisIndex: 'none'
|
||||
},
|
||||
restore: {},
|
||||
saveAsImage: {}
|
||||
}
|
||||
},
|
||||
dataZoom: [
|
||||
{
|
||||
start: 0,
|
||||
end: 100
|
||||
}
|
||||
],
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
boundaryGap: false
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
boundaryGap: false
|
||||
},
|
||||
series: [],
|
||||
},
|
||||
chartOnOff: true,
|
||||
},
|
||||
mounted() {
|
||||
this.renderChart();
|
||||
this.parseMonitorInfo(monitorInfo);
|
||||
},
|
||||
methods: {
|
||||
getFontLogoClass(str) {
|
||||
if (["almalinux",
|
||||
"alpine",
|
||||
"aosc",
|
||||
"apple",
|
||||
"archlinux",
|
||||
"archlabs",
|
||||
"artix",
|
||||
"budgie",
|
||||
"centos",
|
||||
"coreos",
|
||||
"debian",
|
||||
"deepin",
|
||||
"devuan",
|
||||
"docker",
|
||||
"elementary",
|
||||
"fedora",
|
||||
"ferris",
|
||||
"flathub",
|
||||
"freebsd",
|
||||
"gentoo",
|
||||
"gnu-guix",
|
||||
"illumos",
|
||||
"kali-linux",
|
||||
"linuxmint",
|
||||
"mageia",
|
||||
"mandriva",
|
||||
"manjaro",
|
||||
"nixos",
|
||||
"openbsd",
|
||||
"opensuse",
|
||||
"pop-os",
|
||||
"raspberry-pi",
|
||||
"redhat",
|
||||
"rocky-linux",
|
||||
"sabayon",
|
||||
"slackware",
|
||||
"snappy",
|
||||
"solus",
|
||||
"tux",
|
||||
"ubuntu",
|
||||
"void",
|
||||
"zorin"].indexOf(str)
|
||||
> -1) {
|
||||
return str;
|
||||
}
|
||||
if (['openwrt', 'linux', "immortalwrt"].indexOf(str) > -1) {
|
||||
return 'tux';
|
||||
}
|
||||
if (str == 'amazon') {
|
||||
return 'redhat';
|
||||
}
|
||||
if (str == 'arch') {
|
||||
return 'archlinux';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
redirectNetwork(id) {
|
||||
this.getMonitorHistory(id)
|
||||
.then(function(monitorInfo) {
|
||||
var vm = app.__vue__;
|
||||
vm.parseMonitorInfo(monitorInfo);
|
||||
})
|
||||
.catch(function(error){
|
||||
window.location.href = "/404";
|
||||
})
|
||||
},
|
||||
getMonitorHistory(id) {
|
||||
return $.ajax({
|
||||
url: "/api/v1/monitor/"+id,
|
||||
method: "GET"
|
||||
});
|
||||
},
|
||||
parseMonitorInfo(monitorInfo) {
|
||||
let tSeries = [];
|
||||
let tLegendData = [];
|
||||
for (let i = 0; i < monitorInfo.result.length; i++) {
|
||||
let loss = 0;
|
||||
let data = [];
|
||||
for (let j = 0; j < monitorInfo.result[i].created_at.length; j++) {
|
||||
avgDelay = Math.round(monitorInfo.result[i].avg_delay[j]);
|
||||
if (avgDelay > 0.9 * MaxTCPPingValue) {
|
||||
loss += 1
|
||||
}
|
||||
if (avgDelay > 0) {
|
||||
data.push([monitorInfo.result[i].created_at[j], avgDelay]);
|
||||
}
|
||||
}
|
||||
lossRate = ((loss / monitorInfo.result[i].created_at.length) * 100).toFixed(1);
|
||||
legendName = monitorInfo.result[i].monitor_name +" "+ lossRate + "%";
|
||||
tLegendData.push(legendName);
|
||||
tSeries.push({
|
||||
name: legendName,
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
data: data,
|
||||
markPoint: {
|
||||
data: [
|
||||
{ type: 'max', symbol: 'pin', name: 'Max', itemStyle: { color: '#f00' } },
|
||||
{ type: 'min', symbol: 'pin', name: 'Min', itemStyle: { color: '#0f0' } }
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
this.option.title.text = monitorInfo.result[0].server_name;
|
||||
this.option.series = tSeries;
|
||||
this.option.legend.data = tLegendData;
|
||||
this.myChart.clear();
|
||||
this.myChart.setOption(this.option);
|
||||
},
|
||||
isWindowsPlatform(str) {
|
||||
return str.includes('Windows')
|
||||
},
|
||||
renderChart() {
|
||||
this.myChart = echarts.init(this.$refs.chartDom);
|
||||
this.myChart.setOption(this.option);
|
||||
},
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.myChart.dispose();
|
||||
this.myChart = null;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
+4
-4
@@ -9,7 +9,7 @@
|
||||
<link rel="shortcut icon" type="image/png" href="/static/logo.svg?v20210804" />
|
||||
|
||||
<!-- MDUI CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/mdui/1.0.2/css/mdui.min.css"/>
|
||||
<link rel="stylesheet" href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/mdui/1.0.2/css/mdui.min.css"/>
|
||||
<link rel="stylesheet" href="/static/theme-mdui/mdui.css" type="text/css">
|
||||
{{if ts .CustomCode}}
|
||||
{{.CustomCode|safe}}
|
||||
@@ -116,9 +116,9 @@
|
||||
{{template "theme-mdui/footer" .}}
|
||||
|
||||
<script src="/static/theme-mdui/mdui.js"></script>
|
||||
<script src="https://cdn.staticfile.org/mdui/1.0.2/js/mdui.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/mdui/1.0.2/js/mdui.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/vue/2.6.14/vue.min.js"></script>
|
||||
<script>
|
||||
var container=document.querySelector("#container");
|
||||
container.style.minHeight=window.innerHeight-document.body.clientHeight+container.clientHeight+'px';
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@
|
||||
<title>{{.Title}}</title>
|
||||
|
||||
<!-- MDUI CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/mdui/1.0.2/css/mdui.min.css"/>
|
||||
<link rel="stylesheet" href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/mdui/1.0.2/css/mdui.min.css"/>
|
||||
<link rel="stylesheet" href="/static/theme-mdui/mdui.css" type="text/css">
|
||||
{{if ts .CustomCode}}
|
||||
{{.CustomCode|safe}}
|
||||
@@ -34,8 +34,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.staticfile.org/mdui/1.0.2/js/mdui.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/mdui/1.0.2/js/mdui.min.js"></script>
|
||||
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script>
|
||||
var $input = mdui.$('#container').find('.mdui-textfield-input');
|
||||
var $dialog = new mdui.Dialog(mdui.$('.mdui-dialog'));
|
||||
|
||||
+14
-2
@@ -1,8 +1,20 @@
|
||||
{{define "theme-server-status/content-footer"}}
|
||||
<footer class="container" style="padding-bottom: 2rem;">
|
||||
<p style="text-align: center; font-size: 10px;">
|
||||
{{ .Conf.Site.Brand }} | Theme <a href="https://github.com/cppla/ServerStatus">ServerStatus</a> | Powered by <a
|
||||
href="https://github.com/naiba/nezha">{{tr "NezhaMonitoring"}}</a> {{.Version}}
|
||||
{{ .Conf.Site.Brand }} | Theme ServerStatus | Powered by <a target="_blank" href="https://github.com/naiba/nezha">{{tr "NezhaMonitoring"}}</a> {{.Version}}
|
||||
</p>
|
||||
</footer>
|
||||
<aside class="toolbox">
|
||||
<span class="toggleView">
|
||||
<i v-if="showGroup" @click="toggleView" class="show-nogroup bi bi-justify"></i>
|
||||
<i v-else @click="toggleView" class="show-group bi bi-view-stacked"></i>
|
||||
</span>
|
||||
<span class="setTheme">
|
||||
<i v-if="theme === 'light'" @click="setTheme('dark', true)" class="setTheme-dark bi bi-moon-fill"></i>
|
||||
<i v-else @click="setTheme('light', true)" class="setTheme-light bi bi-brightness-high-fill"></i>
|
||||
</span>
|
||||
<span v-if="showGoTop" class="showGoTop">
|
||||
<i @click="goTop" class="goTop bi bi-arrow-up"></i>
|
||||
</span>
|
||||
</aside>
|
||||
{{end}}
|
||||
+56
-42
@@ -1,47 +1,61 @@
|
||||
{{define "theme-server-status/content-nav"}}
|
||||
<div role="navigation" class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container pl-md-unset">
|
||||
<div class="navbar-header">
|
||||
<button data-target=".navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a href="/" class="navbar-brand pl-md-unset">
|
||||
<img src="/static/logo.svg?v20210804" style="height: 2rem;display: inline-block;">
|
||||
{{.Conf.Site.Brand}}
|
||||
</a>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="/">{{tr "Home" }}</a></li>
|
||||
<li><a href="/service">{{tr "Services" }}</a></li>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<header role="navigation" class="navbar navbar-inverse navbar-fixed-top" style="z-index:99999999;">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button data-target=".navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a href="/" class="navbar-brand">
|
||||
<img src="/static/logo.svg" style="height: 2rem;display: inline-block;">
|
||||
{{.Conf.Site.Brand}}
|
||||
</a>
|
||||
</div>
|
||||
<nav id="navbar" class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="/"><i class="home icon"></i>{{tr "Home" }}</a></li>
|
||||
<template v-if="isMobile">
|
||||
<li class="dropdown">
|
||||
<a data-toggle="dropdown" href="#">{{tr "Menu" }}<b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
{{if .Admin}}
|
||||
<li><a href="/server">{{tr "AdminPanel" }} ({{.Admin.Name}})</a></li>
|
||||
{{else}}
|
||||
<li><a href="/login">{{tr "Login" }}</a></li>
|
||||
{{end}}
|
||||
<li><a href="#" @click="setSystemTheme">{{tr "FollowSystem" }}
|
||||
<span style="color: #fff" v-if="isSystemTheme"> ✔️</span></a>
|
||||
</li>
|
||||
<li><a href="#" @click="setTheme('dark', true)">{{tr "DarkMode" }}
|
||||
<span v-if="theme === 'dark' && !isSystemTheme"> ✔️</span></a>
|
||||
</li>
|
||||
<li><a href="#" @click="setTheme('light', true)">{{tr "LightMode" }}
|
||||
<span v-if="theme === 'light' && !isSystemTheme"> ✔️</span></a>
|
||||
</li>
|
||||
<a data-toggle="dropdown"><i class="bi bi-gear-wide-connected" style="position:relative;top:1px;margin-right:3px;font-size:1.1rem;"></i>{{tr "Feature" }}<b class="caret"></b></a>
|
||||
<ul class="dropdown-menu" style="min-width:100px;">
|
||||
<li><a href="/service"><i class="rss icon"></i>{{tr "Services" }}</a></li>
|
||||
<li><a href="/network"><i class="bi bi-hdd-network icon"></i>{{tr "NetworkSpiter"}}</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<li><a href="/service"><i class="rss icon"></i>{{tr "Services" }}</a></li>
|
||||
<li><a href="/network"><i class="bi bi-hdd-network icon"></i>{{tr "NetworkSpiter"}}</a></li>
|
||||
</template>
|
||||
<li class="dropdown">
|
||||
<a data-toggle="dropdown"><i class="bi bi-incognito" style="position:relative;top:1px;margin-right:3px;font-size:1.2rem;vertical-align:top;"></i>{{tr "Template" }}<b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li v-for="(value, key) in templates" :key="key">
|
||||
<a @click="toggleTemplate(key)">
|
||||
<i class="list icon"></i>@#value#@
|
||||
<i class="check icon" v-if="preferredTemplate === key"></i>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
{{if .Admin}}
|
||||
<li class="dropdown">
|
||||
<a data-toggle="dropdown"><i class="user icon"></i>{{.Admin.Name}}<b class="caret"></b></a>
|
||||
<ul class="dropdown-menu" style="margin-bottom:20px;">
|
||||
<li><a href="/server"><i class="terminal icon"></i>{{tr "AdminPanel" }}</a></li>
|
||||
<li><a @click="logOut({{.Admin.ID}})"><i class="logout icon"></i>{{tr "Logout"}}</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{{else}}
|
||||
<li><a href="/login"><i class="sign-in icon"></i>{{tr "Login" }}</a></li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</header>
|
||||
{{end}}
|
||||
|
||||
|
||||
+13
-13
@@ -1,20 +1,21 @@
|
||||
{{define "theme-server-status/header"}}
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{.Conf.Language}}">
|
||||
|
||||
<head>
|
||||
<title>{{ .Title }}</title>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="/static/theme-server-status/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="/static/theme-server-status/css/bootstrap-theme.min.css">
|
||||
<link rel="stylesheet" href="/static/theme-server-status/css/main.css?v20231109">
|
||||
<link rel="stylesheet" href="/static/theme-server-status/css/main.css?v20240225">
|
||||
<link rel="stylesheet" href="/static/theme-server-status/css/dark.css">
|
||||
<link rel="stylesheet" href="/static/theme-server-status/css/light.css">
|
||||
<link href="https://cdn.staticfile.org/font-logos/0.17/font-logos.min.css" type="text/css" rel="stylesheet" />
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/semantic-ui/2.4.1/semantic.min.css">
|
||||
<link rel="shortcut icon" type="image/png" href="/static/logo.svg?v20210804" />
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/assets/font-logos.css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lipis/[email protected]/css/flag-icons.min.css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css">
|
||||
<link rel="shortcut icon" type="image/png" href="/static/logo.svg" />
|
||||
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="/static/theme-server-status/js/html5shiv.js"></script>
|
||||
@@ -23,12 +24,11 @@
|
||||
{{if ts .CustomCode}}
|
||||
{{.CustomCode|safe}}
|
||||
{{end}}
|
||||
|
||||
<script src="/static/theme-server-status/js/jquery.min.js"></script>
|
||||
<script src="/static/theme-server-status/js/bootstrap.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
|
||||
<script src="/static/theme-server-status/js/mixin.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js"></script>
|
||||
<script src="/static/theme-server-status/js/mixin.js?v20240225"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{{end}}
|
||||
{{end}}
|
||||
@@ -0,0 +1,134 @@
|
||||
{{define "theme-server-status/home-group-false"}}
|
||||
<table class="table table-striped table-condensed table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="node-cell status center">{{tr "Status"}}</th>
|
||||
<th class="node-cell name center">{{tr "Name"}}</th>
|
||||
<th class="node-cell os center">{{tr "Platform"}}</th>
|
||||
<th class="node-cell location center">{{tr "Location"}}</th>
|
||||
<th class="node-cell uptime center">{{tr "Uptime"}}</th>
|
||||
<th class="node-cell load center">{{tr "Load"}}</th>
|
||||
<th class="node-cell network center">{{tr "NetSpeed"}}↓|↑</th>
|
||||
<th class="node-cell traffic center">{{tr "NetTransfer"}}↓|↑</th>
|
||||
<th class="node-cell cpu center">{{tr "CpuUsed"}}</th>
|
||||
<th class="node-cell memory center">{{tr "MemUsed"}}</th>
|
||||
<th class="node-cell hdd center">{{tr "DiskUsed"}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="servers">
|
||||
<template v-for="(node,index) in nodesNoTag">
|
||||
<tr :id="'r'+node.ID" data-toggle="collapse" :data-target="'#rt'+node.ID" class="accordion-toggle" :class="index % 2 === 0 ? 'odd': 'even'"
|
||||
aria-expanded="false" @click="showCharts($event, node.ID)">
|
||||
<td class="node-cell status center">
|
||||
<div class="status-container">
|
||||
<div v-if="node.online" class="status-icon online"></div>
|
||||
<div v-else class="status-icon offline"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell name center">@#node.name#@</td>
|
||||
<td class="node-cell os center">
|
||||
<i v-if='node.os == "darwin"' class="apple icon"></i>
|
||||
<i v-else-if='isWindowsPlatform(node.host.Platform)' class="windows icon"></i>
|
||||
<i v-else :class="'fl-' + getFontLogoClass(node.host.Platform)"></i>
|
||||
<span class="node-cell-os-text">@#node.os#@</span>
|
||||
</td>
|
||||
<td style="text-align: center;" class="node-cell location">
|
||||
<i :class="'fi fi-' + node.location"></i>
|
||||
<span class="node-cell-location-text text-uppercase">@#node.location#@</span>
|
||||
</td>
|
||||
<td style="text-align: center;" class="node-cell uptime">@#node.uptime#@</td>
|
||||
<td style="text-align: center;" class="node-cell load">@#node.load#@</td>
|
||||
<td style="text-align: center;" class="node-cell network">@#node.network#@</td>
|
||||
<td style="text-align: center;" class="node-cell traffic">@#node.traffic#@</td>
|
||||
<td class="node-cell cpu">
|
||||
<div :class="['progress', node.online ? 'progress-online' : 'progress-offline']">
|
||||
<div :style="node.cpu.style" :class="node.cpu.class"><small>@#node.cpu.percent#@%</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell memory">
|
||||
<div :class="['progress', node.online ? 'progress-online' : 'progress-offline']">
|
||||
<div :style="node.memory.style" :class="node.memory.class">
|
||||
<small>@#node.memory.percent#@%</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell hdd">
|
||||
<div :class="['progress', node.online ? 'progress-online' : 'progress-offline']">
|
||||
<div :style="node.hdd.style" :class="node.hdd.class"><small>@#node.hdd.percent#@%</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="expandRow" :class="index % 2 === 0 ? 'odd': 'even'">
|
||||
<td colspan="16">
|
||||
<div class="accordian-body collapse" :id="'rt'+node.ID">
|
||||
<div style="display: flex;left-items: center;justify-content: center;flex-direction: column; max-width: 89vw">
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "Platform"}}:</span>
|
||||
@#node.host.Platform#@-@#node.host.PlatformVersion#@
|
||||
[<span v-if="node.host.Virtualization">@#node.host.Virtualization#@:</span>@#node.host.Arch#@]
|
||||
</span>
|
||||
<span class="node-cell-expand" v-if="node.host.CPU">
|
||||
<span class="node-cell-expand-label">CPU:</span>
|
||||
@#node.host.CPU.join(",")#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "DiskUsed"}}:</span>
|
||||
@#formatByteSize(node.state.DiskUsed)#@ / @#formatByteSize(node.host.DiskTotal)#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "MemUsed"}}:</span>
|
||||
@#formatByteSize(node.state.MemUsed)#@ / @#formatByteSize(node.host.MemTotal)#@(@#toFixed2(node.state.MemUsed / node.host.MemTotal * 100)#@%)
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "SwapUsed"}}:</span>
|
||||
@#formatByteSize(node.state.SwapUsed)#@ / @#formatByteSize(node.host.SwapTotal)#@
|
||||
<span v-if="node.host.SwapTotal">(@#toFixed2(node.state.SwapUsed / node.host.SwapTotal * 100)#@%)</span>
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "NetTransfer"}}:</span>
|
||||
<i class="arrow alternate circle down outline icon"
|
||||
style="margin: 0"></i>@#formatByteSize(node.state.NetInTransfer)#@
|
||||
<i class="arrow alternate circle up outline icon"
|
||||
style="margin: 0"></i>@#formatByteSize(node.state.NetOutTransfer)#@
|
||||
</span>
|
||||
<span class="node-cell-expand load">
|
||||
<span class="node-cell-expand-label">{{tr "Load"}}:</span>
|
||||
@#toFixed2(node.state.Load1)#@ / @#toFixed2(node.state.Load5)#@ / @#toFixed2(node.state.Load15)#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "ProcessCount"}}:</span>
|
||||
@#node.state.ProcessCount#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "ConnCount"}}:</span>
|
||||
TCP @#node.state.TcpConnCount#@ / UDP @#node.state.UdpConnCount#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "BootTime"}}:</span>
|
||||
@#formatTimestamp(node.host.BootTime)#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "LastActive"}}:</span>
|
||||
@#new Date(node.lastActive).toLocaleString()#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "Uptime"}}:</span>
|
||||
@#node.uptime#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "Version"}}:</span>
|
||||
@#node.host.Version#@
|
||||
</span>
|
||||
<span class="node-echarts-expand">
|
||||
<div class="chartbox" chartbox-show="0" :key="node.ID" :ref="`chart${node.ID}`" style="width: 100%; height: auto;"></div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
@@ -0,0 +1,137 @@
|
||||
{{define "theme-server-status/home-group-true"}}
|
||||
<table class="table table-striped table-condensed table-hover">
|
||||
<thead>
|
||||
<tr class="node-group-tag">
|
||||
<th colspan="16" style="border:none;">@#(group.Tag!==''?group.Tag:'{{tr "Default"}}')#@</th>
|
||||
</tr>
|
||||
<tr class="node-group-cell">
|
||||
<th class="node-cell status center">{{tr "Status"}}</th>
|
||||
<th class="node-cell name center">{{tr "Name"}}</th>
|
||||
<th class="node-cell os center">{{tr "Platform"}}</th>
|
||||
<th class="node-cell location center">{{tr "Location"}}</th>
|
||||
<th class="node-cell uptime center">{{tr "Uptime"}}</th>
|
||||
<th class="node-cell load center">{{tr "Load"}}</th>
|
||||
<th class="node-cell network center">{{tr "NetSpeed"}}↓|↑</th>
|
||||
<th class="node-cell traffic center">{{tr "NetTransfer"}}↓|↑</th>
|
||||
<th class="node-cell cpu center">{{tr "CpuUsed"}}</th>
|
||||
<th class="node-cell memory center">{{tr "MemUsed"}}</th>
|
||||
<th class="node-cell hdd center">{{tr "DiskUsed"}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="servers">
|
||||
<template v-for="(node,index) in group.data">
|
||||
<tr :id="'r'+node.ID" data-toggle="collapse" :data-target="'#rt'+node.ID" class="accordion-toggle"
|
||||
:class="index % 2 === 0 ? 'odd': 'even'" aria-expanded="false" @click="showCharts($event, node.ID)">
|
||||
<td class="node-cell status center">
|
||||
<div class="status-container">
|
||||
<div v-if="node.online" class="status-icon online"></div>
|
||||
<div v-else class="status-icon offline"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell name center">@#node.name#@</td>
|
||||
<td class="node-cell os center">
|
||||
<i v-if='node.os == "darwin"' class="apple icon"></i>
|
||||
<i v-else-if='isWindowsPlatform(node.host.Platform)' class="windows icon"></i>
|
||||
<i v-else :class="'fl-' + getFontLogoClass(node.host.Platform)"></i>
|
||||
<span class="node-cell-os-text">@#node.os#@</span>
|
||||
</td>
|
||||
<td style="text-align: center;" class="node-cell location">
|
||||
<i :class="'fi fi-' + node.location"></i>
|
||||
<span class="node-cell-location-text text-uppercase"> @#node.location#@</span>
|
||||
</td>
|
||||
<td style="text-align: center;" class="node-cell uptime">@#node.uptime#@</td>
|
||||
<td style="text-align: center;" class="node-cell load">@#node.load#@</td>
|
||||
<td style="text-align: center;" class="node-cell network">@#node.network#@</td>
|
||||
<td style="text-align: center;" class="node-cell traffic">@#node.traffic#@</td>
|
||||
<td class="node-cell cpu">
|
||||
<div :class="['progress', node.online ? 'progress-online' : 'progress-offline']">
|
||||
<div :style="node.cpu.style" :class="node.cpu.class"><small>@#node.cpu.percent#@%</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell memory">
|
||||
<div :class="['progress', node.online ? 'progress-online' : 'progress-offline']">
|
||||
<div :style="node.memory.style" :class="node.memory.class">
|
||||
<small>@#node.memory.percent#@%</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell hdd">
|
||||
<div :class="['progress', node.online ? 'progress-online' : 'progress-offline']">
|
||||
<div :style="node.hdd.style" :class="node.hdd.class"><small>@#node.hdd.percent#@%</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="expandRow" :class="index % 2 === 0 ? 'odd': 'even'">
|
||||
<td colspan="16">
|
||||
<div class="accordian-body collapse" :id="'rt'+node.ID">
|
||||
<div style="display: flex;left-items: center;justify-content: center;flex-direction: column; max-width: 89vw">
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "Platform"}}:</span>
|
||||
@#node.host.Platform#@-@#node.host.PlatformVersion#@
|
||||
[<span v-if="node.host.Virtualization">@#node.host.Virtualization#@:</span>@#node.host.Arch#@]
|
||||
</span>
|
||||
<span class="node-cell-expand" v-if="node.host.CPU">
|
||||
<span class="node-cell-expand-label">CPU:</span>
|
||||
@#node.host.CPU.join(",")#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "DiskUsed"}}:</span>
|
||||
@#formatByteSize(node.state.DiskUsed)#@ / @#formatByteSize(node.host.DiskTotal)#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "MemUsed"}}:</span>
|
||||
@#formatByteSize(node.state.MemUsed)#@ / @#formatByteSize(node.host.MemTotal)#@(@#toFixed2(node.state.MemUsed / node.host.MemTotal * 100)#@%)
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "SwapUsed"}}:</span>
|
||||
@#formatByteSize(node.state.SwapUsed)#@ / @#formatByteSize(node.host.SwapTotal)#@
|
||||
<span v-if="node.host.SwapTotal">(@#toFixed2(node.state.SwapUsed / node.host.SwapTotal * 100)#@%)</span>
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "NetTransfer"}}:</span>
|
||||
<i class="arrow alternate circle down outline icon"
|
||||
style="margin: 0"></i>@#formatByteSize(node.state.NetInTransfer)#@
|
||||
<i class="arrow alternate circle up outline icon"
|
||||
style="margin: 0"></i>@#formatByteSize(node.state.NetOutTransfer)#@
|
||||
</span>
|
||||
<span class="node-cell-expand load">
|
||||
<span class="node-cell-expand-label">{{tr "Load"}}:</span>
|
||||
@#toFixed2(node.state.Load1)#@ / @#toFixed2(node.state.Load5)#@ / @#toFixed2(node.state.Load15)#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "ProcessCount"}}:</span>
|
||||
@#node.state.ProcessCount#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "ConnCount"}}:</span>
|
||||
TCP @#node.state.TcpConnCount#@ / UDP @#node.state.UdpConnCount#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "BootTime"}}:</span>
|
||||
@#formatTimestamp(node.host.BootTime)#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "LastActive"}}:</span>
|
||||
@#new Date(node.lastActive).toLocaleString()#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "Uptime"}}:</span>
|
||||
@#node.uptime#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "Version"}}:</span>
|
||||
@#node.host.Version#@
|
||||
</span>
|
||||
<span class="node-echarts-expand">
|
||||
<div class="chartbox" chartbox-show="0" :key="node.ID" :ref="`chart${node.ID}`" style="width: 100%; height: auto;"></div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
+200
-150
@@ -1,141 +1,19 @@
|
||||
{{define "theme-server-status/home"}}
|
||||
{{template "theme-server-status/header" .}}
|
||||
<div id="app">
|
||||
{{template "theme-server-status/content-nav" .}}
|
||||
<div class="container table-responsive content" style="max-width: 95vw">
|
||||
<table class="table table-striped table-condensed table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="node-cell status center">🍀 {{tr "Status"}}</th>
|
||||
<th class="node-cell name">🚀 {{tr "Name"}}</th>
|
||||
<th class="node-cell os">🗂 {{tr "Platform"}}</th>
|
||||
<th class="node-cell location center">🌍 {{tr "Location"}}</th>
|
||||
<th class="node-cell uptime center">⏱️ {{tr "Uptime"}}</th>
|
||||
<th class="node-cell load center">📋{{tr "Load"}}</th>
|
||||
<th class="node-cell network center">🚦 {{tr "NetSpeed"}}↓|↑</th>
|
||||
<th class="node-cell traffic center">📊 {{tr "NetTransfer"}}↓|↑</th>
|
||||
<th class="node-cell cpu center">🎯 {{tr "CpuUsed"}}</th>
|
||||
<th class="node-cell ram center">⚡ {{tr "MemUsed"}}</th>
|
||||
<th class="node-cell hdd center">💾 {{tr "DiskUsed"}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="servers">
|
||||
<template v-for="(node,index) in nodes">
|
||||
<tr :id="'r'+index" data-toggle="collapse" :data-target="'#rt'+index" class="accordion-toggle"
|
||||
:class="index % 2 === 0 ? 'odd': 'even'">
|
||||
<td class="node-cell status center">
|
||||
<div class="status-container">
|
||||
<div v-if="node.online" class="status-icon online"></div>
|
||||
<div v-else class="status-icon offline"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell name">@#node.name#@</td>
|
||||
<td class="node-cell os">
|
||||
<i v-if='node.os == "darwin"' class="apple icon"></i>
|
||||
<i v-else-if='isWindowsPlatform(node.host.Platform)' class="windows icon"></i>
|
||||
<i v-else :class="'fl-' + getFontLogoClass(node.host.Platform)"></i>
|
||||
@#node.os#@
|
||||
</td>
|
||||
<td style="text-align: center;" class="node-cell location">
|
||||
<i :class="node.location + ' flag'"></i>
|
||||
<span class="text-uppercase">@#node.location#@</span>
|
||||
</td>
|
||||
<td style="text-align: center;" class="node-cell uptime">@#node.uptime#@</td>
|
||||
<td style="text-align: center;" class="node-cell load">@#node.load#@</td>
|
||||
<td style="text-align: center;" class="node-cell network">@#node.network#@</td>
|
||||
<td style="text-align: center;" class="node-cell traffic">@#node.traffic#@</td>
|
||||
<td class="node-cell cpu">
|
||||
<div class="progress">
|
||||
<div :style="node.cpu.style" :class="node.cpu.class"><small>@#node.cpu.percent#@%</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell memory">
|
||||
<div class="progress">
|
||||
<div :style="node.memory.style" :class="node.memory.class">
|
||||
<small>@#node.memory.percent#@%</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell hdd">
|
||||
<div class="progress">
|
||||
<div :style="node.hdd.style" :class="node.hdd.class"><small>@#node.hdd.percent#@%</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="expandRow" :class="index % 2 === 0 ? 'odd': 'even'">
|
||||
<td colspan="16">
|
||||
<div class="accordian-body collapse" :id="'rt'+index">
|
||||
<div style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
|
||||
<div style="display: flex;align-items: flex-start;justify-content: center;flex-direction: column; width: 450px;max-width: 90vw">
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "Platform"}}:</span>
|
||||
@#node.host.Platform#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "Location"}}:</span>
|
||||
<i :class="node.location + ' flag'"></i>
|
||||
</span>
|
||||
<span class="node-cell-expand" v-if="node.host.CPU">
|
||||
<span class="node-cell-expand-label">CPU:</span>
|
||||
@#node.host.CPU.join(",")#@
|
||||
</span>
|
||||
<span class="node-cell-expand load">
|
||||
<span class="node-cell-expand-label">{{tr "Load"}}:</span>
|
||||
@#toFixed2(node.state.Load1)#@ / @#toFixed2(node.state.Load5)#@ /@#toFixed2(node.state.Load15)#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "DiskUsed"}}:</span>
|
||||
@#formatByteSize(node.state.DiskUsed)#@ / @#formatByteSize(node.host.DiskTotal)#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "MemUsed"}}:</span>
|
||||
@#formatByteSize(node.state.MemUsed)#@ / @#formatByteSize(node.host.MemTotal)#@(@#toFixed2(node.state.MemUsed / node.host.MemTotal * 100)#@%)
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "NetTransfer"}}:</span>
|
||||
<i class="arrow alternate circle down outline icon"
|
||||
style="margin: 0"></i>@#formatByteSize(node.state.NetInTransfer)#@
|
||||
<i class="arrow alternate circle up outline icon"
|
||||
style="margin: 0"></i>@#formatByteSize(node.state.NetOutTransfer)#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "SwapUsed"}}:</span>
|
||||
@#formatByteSize(node.state.SwapUsed)#@ / @#formatByteSize(node.host.SwapTotal)#@
|
||||
<span v-if="node.host.SwapTotal">(@#toFixed2(node.state.SwapUsed / node.host.SwapTotal * 100)#@%)</span>
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "BootTime"}}:</span>
|
||||
@#formatTimestamp(node.host.BootTime)#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "LastActive"}}:</span>
|
||||
@#new Date(node.lastActive).toLocaleString()#@
|
||||
</span>
|
||||
<span class="node-cell-expand" v-if="node.host.Virtualization">
|
||||
<span class="node-cell-expand-label">{{tr "Virtualization"}}:</span>
|
||||
@#node.host.Virtualization#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "ProcessCount"}}:</span>
|
||||
@#node.state.ProcessCount#@
|
||||
</span>
|
||||
<span class="node-cell-expand">
|
||||
<span class="node-cell-expand-label">{{tr "ConnCount"}}:</span>
|
||||
TCP @#node.state.TcpConnCount#@ / UDP @#node.state.UdpConnCount#@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<br/>
|
||||
</div>
|
||||
{{template "theme-server-status/content-nav" .}}
|
||||
<!-- showGroup true -->
|
||||
<template v-if="showGroup">
|
||||
<section class="container table-responsive content" style="max-width: 95vw" v-for="group in nodesTag">
|
||||
{{template "theme-server-status/home-group-true" .}}
|
||||
</section>
|
||||
</template>
|
||||
<!-- showGroup false -->
|
||||
<template v-else>
|
||||
<section class="container table-responsive content" style="max-width: 95vw">
|
||||
{{template "theme-server-status/home-group-false" .}}
|
||||
</section>
|
||||
</template>
|
||||
{{template "theme-server-status/content-footer" .}}
|
||||
</div>
|
||||
<script>
|
||||
@@ -143,13 +21,20 @@
|
||||
el: '#app',
|
||||
delimiters: ['@#', '#@'],
|
||||
data: {
|
||||
nodes: [],
|
||||
page: 'index',
|
||||
templates: {{.Themes}},
|
||||
nodesTag: [],
|
||||
nodesNoTag: [],
|
||||
chartDataList: []
|
||||
},
|
||||
mixins: [mixinsVue],
|
||||
created() {
|
||||
const initData = JSON.parse('{{.Servers}}').servers;
|
||||
this.nodes = this.handleNodes(initData);
|
||||
this.initTheme()
|
||||
initData = JSON.parse('{{.Servers}}').servers;
|
||||
if(this.showGroup) {
|
||||
this.nodesTag = this.groupingData(this.handleNodes(initData),"Tag");
|
||||
} else {
|
||||
this.nodesNoTag = this.handleNodes(initData);
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.connect();
|
||||
@@ -233,17 +118,22 @@
|
||||
return x !== "NaN undefined" ? x : '0B'
|
||||
},
|
||||
formatPercent(live, used, total) {
|
||||
const percent = live ? (this.toFixed2(used / total * 100) || 0) : 1
|
||||
return this.formatPercents(percent)
|
||||
//const percent = live ? (this.toFixed2(used / total * 100) || 0) : 0
|
||||
const percent = (this.toFixed2(used / total * 100) || 0)
|
||||
return this.formatPercents(live,percent)
|
||||
},
|
||||
formatPercents(percent) {
|
||||
formatPercents(live,percent) {
|
||||
//if(!live) { percent = 0; }
|
||||
if (percent <= 0) {
|
||||
percent = 1;
|
||||
percent = 0;
|
||||
}
|
||||
if (percent >= 100) {
|
||||
percent = 100;
|
||||
}
|
||||
if (!this.cache[percent]) {
|
||||
this.cache[percent] = {
|
||||
class: 'progress-bar progress-bar-success',
|
||||
style: `width: ${parseInt(percent)}%`,
|
||||
style: `width: ${parseInt(percent)+1}%`,
|
||||
percent,
|
||||
}
|
||||
if (percent < 80) {
|
||||
@@ -282,7 +172,11 @@
|
||||
data.servers[i].live = data.now - lastActive <= 10 * 1000;
|
||||
}
|
||||
}
|
||||
this.nodes = this.handleNodes(data.servers)
|
||||
if(this.showGroup) {
|
||||
this.nodesTag = this.groupingData(this.handleNodes(data.servers),"Tag");
|
||||
} else {
|
||||
this.nodesNoTag = this.handleNodes(data.servers);
|
||||
}
|
||||
}
|
||||
ws.onclose = () => {
|
||||
setTimeout(function () {
|
||||
@@ -296,13 +190,14 @@
|
||||
handleNodes(servers) {
|
||||
let nodes = []
|
||||
servers?.forEach(server => {
|
||||
let platform = server.Host.Platform
|
||||
if (this.isWindowsPlatform(server.Host.Platform)) {
|
||||
let platform = server.Host.Platform;
|
||||
if (this.isWindowsPlatform(platform)) {
|
||||
platform = "windows"
|
||||
}else if (platform === "immortalwrt") {
|
||||
platform = "openwrt"
|
||||
}
|
||||
let node = {
|
||||
ID: server.ID,
|
||||
name: server.Name,
|
||||
os: platform,
|
||||
location: server.Host.CountryCode,
|
||||
@@ -310,13 +205,14 @@
|
||||
load: this.toFixed2(server.State.Load1),
|
||||
network: this.getNetworkSpeed(server.State.NetInSpeed, server.State.NetOutSpeed),
|
||||
traffic: this.formatByteSize(server.State.NetInTransfer) + ' | ' + this.formatByteSize(server.State.NetOutTransfer),
|
||||
cpu: this.formatPercents(this.toFixed2(server.State.CPU)),
|
||||
cpu: this.formatPercents(server.live, this.toFixed2(server.State.CPU)),
|
||||
memory: this.formatPercent(server.live, server.State.MemUsed, server.Host.MemTotal),
|
||||
hdd: this.formatPercent(server.live, server.State.DiskUsed, server.Host.DiskTotal),
|
||||
online: server.live,
|
||||
state: server.State,
|
||||
host: server.Host,
|
||||
lastActive: server.LastActive,
|
||||
Tag: server.Tag,
|
||||
}
|
||||
nodes.push(node)
|
||||
})
|
||||
@@ -324,10 +220,164 @@
|
||||
},
|
||||
getNetworkSpeed(netInSpeed, netOutSpeed) {
|
||||
return this.formatByteSize(netInSpeed) + ' | ' + this.formatByteSize(netOutSpeed)
|
||||
},
|
||||
showCharts(event, id) {
|
||||
const chartContainer = this.$refs[`chart${id}`][0];
|
||||
const chartboxShow = chartContainer.getAttribute('chartbox-show');
|
||||
chartContainer.setAttribute('chartbox-show', chartboxShow === '0' ? '1' : '0');
|
||||
const isAriaExpandedFalse = event.currentTarget.getAttribute('aria-expanded') === 'false';
|
||||
if (!isAriaExpandedFalse) return;
|
||||
// 发起数据请求
|
||||
const url = `/api/v1/monitor/${id}`;
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.result) { // 数据请求成功,更新数据并渲染图表
|
||||
this.chartDataList[id - 1] = data.result;
|
||||
this.$nextTick(() => {
|
||||
this.renderCharts(id);
|
||||
});
|
||||
} else {
|
||||
console.log('this agent (id:'+ id + ') has no monitor.');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching data:', error);
|
||||
});
|
||||
},
|
||||
renderCharts(id, reload = false) {
|
||||
if (!this.chartDataList[id - 1]) return;
|
||||
const chartData = this.chartDataList[id - 1];
|
||||
const chartContainer = this.$refs[`chart${id}`][0];
|
||||
if (reload) { //点击切换亮色/暗色风格模式时,重新载入echarts图表的逻辑,
|
||||
// 第一步,查找已经渲染出的图表容器,并销毁它
|
||||
const existingChart = echarts.getInstanceByDom(chartContainer);
|
||||
if (existingChart) existingChart.dispose();
|
||||
// 第二步,如果图表容器处于不可见状态chartboxShow=0,不重新渲染出新的图表,
|
||||
// 如果图表容器处于可见状态chartboxShow=1,重新渲染出新的图表
|
||||
const chartboxShow = chartContainer.getAttribute('chartbox-show');
|
||||
if ( chartboxShow === '0' ) return;
|
||||
}
|
||||
// 定义图表参数值
|
||||
const MaxTCPPingValue = {{.MaxTCPPingValue}} ? {{.MaxTCPPingValue}} : 300;
|
||||
const isMobile = this.checkIsMobile();
|
||||
const fontSize = isMobile ? 10 : 14;
|
||||
const gridLeft = isMobile ? 25 : 36;
|
||||
const gridRight = isMobile ? 5 : 20;
|
||||
const legendLeft = isMobile ? 'center' : 'center';
|
||||
const legendTop = isMobile ? 5 : 5;
|
||||
const legendPadding= isMobile ? [5,0,5,0] : [5,0,5,0];
|
||||
const systemDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
const theme = localStorage.getItem("theme") ? localStorage.getItem("theme") : systemDarkMode;
|
||||
const chartTheme = theme == "dark" ? "dark" : "default";
|
||||
const fontColor = theme == "dark" ? "#f1f1f1" : "#000000";
|
||||
const backgroundColor = theme == "dark" ? "#1C1D26" : '';
|
||||
const tooltipBackgroundColor = theme == "dark" ? "#1C1D26" : '#ffffff';
|
||||
const tooltipBorderColor = theme == "dark" ? "#31363B" : "#ffffff";
|
||||
// 渲染图表
|
||||
const chart = echarts.init(chartContainer, chartTheme, {
|
||||
renderer: 'canvas',
|
||||
useDirtyRect: false,
|
||||
width: 'auto',
|
||||
height: 300,
|
||||
});
|
||||
const xAxisData = chartData[0].created_at.map(time => new Date(time).toLocaleString());
|
||||
const seriesData = chartData.map(item => {
|
||||
let loss = 0;
|
||||
const data = item.avg_delay.map((avgDelay, index) => {
|
||||
if (avgDelay > 0.9 * MaxTCPPingValue) {
|
||||
loss += 1;
|
||||
}
|
||||
return [new Date(item.created_at[index]).toLocaleString(), avgDelay];
|
||||
});
|
||||
const lossRate = ((loss / item.created_at.length) * 100).toFixed(1);
|
||||
if (!item.monitor_name.includes("%")) {
|
||||
item.monitor_name = item.monitor_name + " " + lossRate + "%";
|
||||
}
|
||||
return {
|
||||
name: item.monitor_name,
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
data: data
|
||||
};
|
||||
});
|
||||
const option = {
|
||||
backgroundColor: backgroundColor,
|
||||
title: {
|
||||
show: false
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
backgroundColor: tooltipBackgroundColor,
|
||||
borderColor: tooltipBorderColor,
|
||||
textStyle: {
|
||||
fontSize: fontSize,
|
||||
color: fontColor
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
data: chartData.map(item => item.monitor_name),
|
||||
show: true,
|
||||
textStyle: {
|
||||
fontSize: fontSize,
|
||||
color: fontColor
|
||||
},
|
||||
top: legendTop,
|
||||
bottom: 0,
|
||||
left: legendLeft,
|
||||
padding: legendPadding
|
||||
},
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
data: xAxisData,
|
||||
axisLabel: {
|
||||
textStyle: {
|
||||
fontSize: fontSize
|
||||
}
|
||||
}
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
axisLabel: {
|
||||
textStyle: {
|
||||
fontSize: fontSize
|
||||
}
|
||||
}
|
||||
},
|
||||
dataZoom: [
|
||||
{
|
||||
type: 'slider',
|
||||
start: 0,
|
||||
end: 100
|
||||
}
|
||||
],
|
||||
series: seriesData,
|
||||
textStyle: {
|
||||
fontSize: fontSize,
|
||||
color: fontColor
|
||||
},
|
||||
grid: {
|
||||
top: '40',
|
||||
left: gridLeft,
|
||||
right: gridRight
|
||||
}
|
||||
};
|
||||
chart.setOption(option);
|
||||
},
|
||||
reloadCharts() { // 重新加载所有图表
|
||||
const data = JSON.parse('{{.Servers}}').servers;
|
||||
data.forEach(node => {
|
||||
const id = node.ID;
|
||||
const chartData = this.chartDataList[id - 1];
|
||||
if (chartData) {
|
||||
this.renderCharts(id,true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
</script>
|
||||
{{template "theme-server-status/footer" .}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
{{define "theme-server-status/network"}}
|
||||
{{template "theme-server-status/header" .}}
|
||||
<div id="app">
|
||||
{{template "theme-server-status/content-nav" .}}
|
||||
<div class="container table-responsive content" style="max-width: 95vw">
|
||||
<table class="table table-striped table-condensed table-hover">
|
||||
<button class="ui nezha-primary-btn button"
|
||||
v-for="server in servers"
|
||||
style="margin-top: 3px"
|
||||
@click="redirectNetwork(server.ID)">
|
||||
@#server.Name#@ <i :class="'fi fi-' + server.Host.CountryCode"></i><span class="node-cell-location-text text-uppercase"> @#server.Host.CountryCode#@</span>
|
||||
</button>
|
||||
</table>
|
||||
</div>
|
||||
<div class="container table-responsive content" style="max-width: 95vw">
|
||||
<div ref="chartDom" style="border-radius: 28px; margin-top: 15px;height: 520px;max-width: 1400px;overflow: hidden"></div>
|
||||
</div>
|
||||
{{template "theme-server-status/content-footer" .}}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const monitorInfo = JSON.parse('{{.MonitorInfos}}');
|
||||
const initData = JSON.parse('{{.Servers}}').servers;
|
||||
let MaxTCPPingValue = {{.MaxTCPPingValue}};
|
||||
if (MaxTCPPingValue == null) {
|
||||
MaxTCPPingValue = 1000;
|
||||
}
|
||||
new Vue({
|
||||
el: '#app',
|
||||
delimiters: ['@#', '#@'],
|
||||
data: {
|
||||
page: 'network',
|
||||
templates: {{.Themes}},
|
||||
servers: initData,
|
||||
option: {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
position: function (pt) {
|
||||
return [pt[0], '10%'];
|
||||
},
|
||||
formatter: function(params){
|
||||
let result = params[0].axisValueLabel + "<br />";
|
||||
params.forEach(function(item){
|
||||
result += item.marker + item.seriesName + ": " + item.value[1].toFixed(2) + " ms<br />";
|
||||
})
|
||||
return result;
|
||||
},
|
||||
confine: true,
|
||||
transitionDuration: 0
|
||||
},
|
||||
title: {
|
||||
left: 'center',
|
||||
text: "",
|
||||
textStyle: {}
|
||||
},
|
||||
legend: {
|
||||
top: '5%',
|
||||
data: [],
|
||||
textStyle: {
|
||||
fontSize: 14
|
||||
}
|
||||
},
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.8)',
|
||||
toolbox: {
|
||||
feature: {
|
||||
dataZoom: {
|
||||
yAxisIndex: 'none'
|
||||
},
|
||||
restore: {},
|
||||
saveAsImage: {}
|
||||
}
|
||||
},
|
||||
dataZoom: [
|
||||
{
|
||||
start: 0,
|
||||
end: 100
|
||||
}
|
||||
],
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
boundaryGap: false
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
boundaryGap: false
|
||||
},
|
||||
series: [],
|
||||
},
|
||||
chartOnOff: true,
|
||||
},
|
||||
mixins: [mixinsVue],
|
||||
mounted() {
|
||||
this.renderChart();
|
||||
this.parseMonitorInfo(monitorInfo);
|
||||
},
|
||||
methods: {
|
||||
getFontLogoClass(str) {
|
||||
if (["almalinux",
|
||||
"alpine",
|
||||
"aosc",
|
||||
"apple",
|
||||
"archlinux",
|
||||
"archlabs",
|
||||
"artix",
|
||||
"budgie",
|
||||
"centos",
|
||||
"coreos",
|
||||
"debian",
|
||||
"deepin",
|
||||
"devuan",
|
||||
"docker",
|
||||
"elementary",
|
||||
"fedora",
|
||||
"ferris",
|
||||
"flathub",
|
||||
"freebsd",
|
||||
"gentoo",
|
||||
"gnu-guix",
|
||||
"illumos",
|
||||
"kali-linux",
|
||||
"linuxmint",
|
||||
"mageia",
|
||||
"mandriva",
|
||||
"manjaro",
|
||||
"nixos",
|
||||
"openbsd",
|
||||
"opensuse",
|
||||
"pop-os",
|
||||
"raspberry-pi",
|
||||
"redhat",
|
||||
"rocky-linux",
|
||||
"sabayon",
|
||||
"slackware",
|
||||
"snappy",
|
||||
"solus",
|
||||
"tux",
|
||||
"ubuntu",
|
||||
"void",
|
||||
"zorin"].indexOf(str)
|
||||
> -1) {
|
||||
return str;
|
||||
}
|
||||
if (['openwrt', 'linux', "immortalwrt"].indexOf(str) > -1) {
|
||||
return 'tux';
|
||||
}
|
||||
if (str == 'amazon') {
|
||||
return 'redhat';
|
||||
}
|
||||
if (str == 'arch') {
|
||||
return 'archlinux';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
redirectNetwork(id) {
|
||||
this.getMonitorHistory(id)
|
||||
.then(function(monitorInfo) {
|
||||
var vm = app.__vue__;
|
||||
vm.parseMonitorInfo(monitorInfo);
|
||||
})
|
||||
.catch(function(error){
|
||||
window.location.href = "/404";
|
||||
})
|
||||
},
|
||||
getMonitorHistory(id) {
|
||||
return $.ajax({
|
||||
url: "/api/v1/monitor/"+id,
|
||||
method: "GET"
|
||||
});
|
||||
},
|
||||
parseMonitorInfo(monitorInfo) {
|
||||
let tSeries = [];
|
||||
let tLegendData = [];
|
||||
for (let i = 0; i < monitorInfo.result.length; i++) {
|
||||
let loss = 0;
|
||||
let data = [];
|
||||
for (let j = 0; j < monitorInfo.result[i].created_at.length; j++) {
|
||||
avgDelay = Math.round(monitorInfo.result[i].avg_delay[j]);
|
||||
if (avgDelay > 0.9 * MaxTCPPingValue) {
|
||||
loss += 1
|
||||
}
|
||||
if (avgDelay > 0) {
|
||||
data.push([monitorInfo.result[i].created_at[j], avgDelay]);
|
||||
}
|
||||
}
|
||||
lossRate = ((loss / monitorInfo.result[i].created_at.length) * 100).toFixed(1);
|
||||
legendName = monitorInfo.result[i].monitor_name +" "+ lossRate + "%";
|
||||
tLegendData.push(legendName);
|
||||
tSeries.push({
|
||||
name: legendName,
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
data: data,
|
||||
markPoint: {
|
||||
data: [
|
||||
{ type: 'max', symbol: 'pin', name: 'Max', itemStyle: { color: '#f00' } },
|
||||
{ type: 'min', symbol: 'pin', name: 'Min', itemStyle: { color: '#0f0' } }
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
this.option.title.text = monitorInfo.result[0].server_name;
|
||||
this.option.series = tSeries;
|
||||
this.option.legend.data = tLegendData;
|
||||
this.myChart.clear();
|
||||
this.myChart.setOption(this.option);
|
||||
},
|
||||
isWindowsPlatform(str) {
|
||||
return str.includes('Windows')
|
||||
},
|
||||
renderChart() {
|
||||
this.myChart = echarts.init(this.$refs.chartDom);
|
||||
this.myChart.setOption(this.option);
|
||||
},
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.myChart.dispose();
|
||||
this.myChart = null;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
{{template "theme-server-status/footer" .}}
|
||||
{{end}}
|
||||
@@ -0,0 +1,46 @@
|
||||
{{define "theme-server-status/service-group-false"}}
|
||||
<table class="table table-striped table-condensed table-hover service-status">
|
||||
<thead>
|
||||
<tr class="node-group-tag">
|
||||
<th colspan="16" style="border:none;">
|
||||
{{tr "ServicesManagement"}}
|
||||
</th>
|
||||
</tr>
|
||||
<tr class="node-group-cell">
|
||||
<th class="node-cell center service-status-th">{{tr "Status"}}</th>
|
||||
<th class="node-cell center service-name-th">{{tr "Name"}}</th>
|
||||
<th class="node-cell center service-details-th">{{tr "Details"}}</th>
|
||||
<th class="node-cell center service-averagelatency-th">{{tr "AverageLatency"}}</th>
|
||||
<th class="node-cell center service-30daysonline-th">{{tr "30DaysOnline"}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-for="service in servicesNoTag">
|
||||
<tr>
|
||||
<td class="node-cell center">
|
||||
<div class="delay-today">
|
||||
<i class="delay-today-icon" :class="service.health.className"></i>
|
||||
<span class="delay-today-text">@#service.health.text#@</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell center">@#service.name#@</td>
|
||||
<td class="node-cell center service-details-td">
|
||||
<template v-for="(item,index) in service.dayDetail">
|
||||
<div data-toggle="tooltip" data-placement="top" class="service-day-status-icon" :class="item.className"
|
||||
:title="item.text">
|
||||
</div>
|
||||
</template>
|
||||
</td>
|
||||
<td class="node-cell center">@#service.avgDelay#@</td>
|
||||
<td class="node-cell center">
|
||||
<div class="progress">
|
||||
<div :style="service.totalUpTime.style" :class="service.totalUpTime.className">
|
||||
<small>@#service.totalUpTime.percent#@%</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
@@ -0,0 +1,51 @@
|
||||
{{define "theme-server-status/service-group-true"}}
|
||||
<table class="table table-striped table-condensed table-hover service-status">
|
||||
<thead>
|
||||
<tr class="node-group-tag">
|
||||
<th colspan="16" style="border:none;">
|
||||
<span v-if="group.type == 1">HTTP-GET</span>
|
||||
<span v-if="group.type == 2">ICMP-Ping</span>
|
||||
<span v-if="group.type == 3">TCP-Ping</span>
|
||||
</th>
|
||||
</tr>
|
||||
<tr class="node-group-cell">
|
||||
<th class="node-cell center service-status-th">{{tr "Status"}}</th>
|
||||
<th class="node-cell center service-name-th">{{tr "Name"}}</th>
|
||||
<th class="node-cell center service-details-th">{{tr "Details"}}</th>
|
||||
<th class="node-cell center service-averagelatency-th">{{tr "AverageLatency"}}</th>
|
||||
<th class="node-cell center service-30daysonline-th">{{tr "30DaysOnline"}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-for="service in group.data">
|
||||
<tr>
|
||||
<td class="node-cell center">
|
||||
<div class="delay-today">
|
||||
<i class="delay-today-icon" :class="service.health.className"></i>
|
||||
<span class="delay-today-text">@#service.health.text#@</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell center">@#service.name#@</td>
|
||||
<td class="node-cell center service-details-td">
|
||||
<template v-for="(item,index) in service.dayDetail">
|
||||
<div data-toggle="tooltip" data-placement="top" class="service-day-status-icon" :class="item.className"
|
||||
:title="item.text">
|
||||
</div>
|
||||
</template>
|
||||
</td>
|
||||
<td class="node-cell center">@#service.avgDelay#@</td>
|
||||
<td class="node-cell center">
|
||||
<div class="progress">
|
||||
<div :style="service.totalUpTime.style" :class="service.totalUpTime.className">
|
||||
<small>@#service.totalUpTime.percent#@%</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
|
||||
|
||||
|
||||
+63
-83
@@ -2,110 +2,88 @@
|
||||
{{template "theme-server-status/header" .}}
|
||||
<div id="app">
|
||||
{{template "theme-server-status/content-nav" .}}
|
||||
<div class="container content" style="max-width: 95vw">
|
||||
<table class="table table-striped table-condensed service-status">
|
||||
<!-- showGroup true -->
|
||||
<template v-if="showGroup">
|
||||
<section class="container content" style="max-width: 95vw; min-height: .01%;overflow-x: auto;" v-for="group in servicesTag">
|
||||
{{template "theme-server-status/service-group-true" .}}
|
||||
</section>
|
||||
</template>
|
||||
<!-- showGroup false -->
|
||||
<template v-else>
|
||||
<section class="container content" style="max-width: 95vw; min-height: .01%;overflow-x: auto;">
|
||||
{{template "theme-server-status/service-group-false" .}}
|
||||
</section>
|
||||
</template>
|
||||
<section class="container content table-responsive" style="max-width: 95vw">
|
||||
{{if .CycleTransferStats}}
|
||||
<table class="table table-striped table-condensed table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="node-cell" style="min-width: 60px">🍀 {{tr "Status"}}</th>
|
||||
<th class="node-cell" style="min-width: 60px">🚀 {{tr "Name"}}</th>
|
||||
<th class="node-cell center">🗂 {{tr "Details"}}</th>
|
||||
<th class="node-cell center" style="min-width: 80px">⚡️{{tr "AverageLatency"}}</th>
|
||||
<th class="node-cell center" style="min-width: 80px">⏱️ {{tr "30DaysOnline"}}</th>
|
||||
</tr>
|
||||
<tr class="node-group-tag">
|
||||
<th colspan="16" style="border:none;">
|
||||
{{tr "CycleTransferStats"}}
|
||||
</th>
|
||||
</tr>
|
||||
<tr class="node-group-cell">
|
||||
<th class="node-cell center">ID</th>
|
||||
<th class="node-cell center">{{tr "Rules"}}</th>
|
||||
<th class="node-cell center">{{tr "Server"}}</th>
|
||||
<th class="node-cell center">{{tr "From"}}</th>
|
||||
<th class="node-cell center">{{tr "To"}}</th>
|
||||
<th class="node-cell center">MAX</th>
|
||||
<th class="node-cell center">MIN</th>
|
||||
<th class="node-cell center">{{tr "NextCheck"}}</th>
|
||||
<th class="node-cell center">{{tr "CurrentUsage"}}</th>
|
||||
<th class="node-cell center">{{tr "Transleft"}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="servers">
|
||||
<template v-for="service in services">
|
||||
<tbody>
|
||||
{{range $id, $stats := .CycleTransferStats}}
|
||||
{{range $innerId, $transfer := $stats.Transfer}}
|
||||
{{$TransLeftPercent := TransLeftPercent (UintToFloat $transfer) (UintToFloat $stats.Max)}}
|
||||
<tr>
|
||||
<td style="text-align: left" class="node-cell">
|
||||
<div class="delay-today">
|
||||
<i class="delay-today" :class="service.health.className"></i>
|
||||
@#service.health.text#@
|
||||
</div>
|
||||
</td>
|
||||
<td class="node-cell">@#service.name#@</td>
|
||||
<td class="node-cell center">
|
||||
<template v-for="(item,index) in service.dayDetail">
|
||||
<div class="service-day-status-icon" :class="item.className"
|
||||
:data-tooltip="item.text">
|
||||
</div>
|
||||
</template>
|
||||
</td>
|
||||
<td class="node-cell center">@#service.avgDelay#@</td>
|
||||
<td class="node-cell center">{{$id}}</td>
|
||||
<td class="node-cell center">{{$stats.Name}}</td>
|
||||
<td class="node-cell center">{{index $stats.ServerName $innerId}}</td>
|
||||
<td class="node-cell center">{{$stats.From|tf}}</td>
|
||||
<td class="node-cell center">{{$stats.To|tf}}</td>
|
||||
<td class="node-cell center">{{$stats.Max|bf}}</td>
|
||||
<td class="node-cell center">{{$stats.Min|bf}}</td>
|
||||
<td class="node-cell center">{{(index $stats.NextUpdate $innerId)|sft}}</td>
|
||||
<td class="node-cell center">{{$transfer|bf}}</td>
|
||||
<td class="node-cell center">
|
||||
<div class="progress">
|
||||
<div :style="service.totalUpTime.style" :class="service.totalUpTime.className">
|
||||
<small>@#service.totalUpTime.percent#@%</small>
|
||||
<div style="width: {{$TransLeftPercent}}%" :class="'progress-bar progress-bar-' + toSSBar('{{TransClassName $TransLeftPercent}}')">
|
||||
<small style="display: inline-block;width: max-content;">{{TransLeft $stats.Max $transfer}} / {{$TransLeftPercent}} %</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="container" style="margin-bottom: 20px;padding:unset;max-width: 95vw">
|
||||
{{if .CycleTransferStats}}
|
||||
<h4 style="text-align: center;">{{tr "CycleTransferStats"}}</h4>
|
||||
<div class="table-responsive content">
|
||||
<table class="table table-striped table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="node-cell center">ID</th>
|
||||
<th class="node-cell center">{{tr "Rules"}}</th>
|
||||
<th class="node-cell center">{{tr "Server"}}</th>
|
||||
<th class="node-cell center">{{tr "From"}}</th>
|
||||
<th class="node-cell center">{{tr "To"}}</th>
|
||||
<th class="node-cell center">MAX</th>
|
||||
<th class="node-cell center">MIN</th>
|
||||
<th class="node-cell center">{{tr "NextCheck"}}</th>
|
||||
<th class="node-cell center">{{tr "CurrentUsage"}}</th>
|
||||
<th class="node-cell center">{{tr "Transleft"}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $id, $stats := .CycleTransferStats}}
|
||||
{{range $innerId, $transfer := $stats.Transfer}}
|
||||
{{$TransLeftPercent := TransLeftPercent (UintToFloat $transfer) (UintToFloat $stats.Max)}}
|
||||
<tr>
|
||||
<td class="node-cell center">{{$id}}</td>
|
||||
<td class="node-cell center">{{$stats.Name}}</td>
|
||||
<td class="node-cell center">{{index $stats.ServerName $innerId}}</td>
|
||||
<td class="node-cell center">{{$stats.From|tf}}</td>
|
||||
<td class="node-cell center">{{$stats.To|tf}}</td>
|
||||
<td class="node-cell center">{{$stats.Max|bf}}</td>
|
||||
<td class="node-cell center">{{$stats.Min|bf}}</td>
|
||||
<td class="node-cell center">{{(index $stats.NextUpdate $innerId)|sft}}</td>
|
||||
<td class="node-cell center">{{$transfer|bf}}</td>
|
||||
<td class="node-cell center">
|
||||
<div class="progress">
|
||||
<div style="width: {{$TransLeftPercent}}%" :class="'progress-bar progress-bar-' + toSSBar('{{TransClassName $TransLeftPercent}}')">
|
||||
<small style="display: inline-block;width: max-content;">{{TransLeft $stats.Max $transfer}} / {{$TransLeftPercent}} %</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</section>
|
||||
{{template "theme-server-status/content-footer" .}}
|
||||
</div>
|
||||
<script>
|
||||
|
||||
// 初始化 Tooltip
|
||||
$(document).ready(function(){
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
delimiters: ['@#', '#@'],
|
||||
data: {
|
||||
services: []
|
||||
page: 'service',
|
||||
templates: {{.Themes}},
|
||||
servicesTag: [],
|
||||
servicesNoTag: [],
|
||||
},
|
||||
created() {
|
||||
this.initData()
|
||||
this.initData();
|
||||
},
|
||||
mounted() {
|
||||
},
|
||||
@@ -129,6 +107,7 @@
|
||||
const services = []
|
||||
{{range $service := .Services}}
|
||||
services.push({
|
||||
type: '{{$service.Monitor.Type}}',
|
||||
name: '{{$service.Monitor.Name}}',
|
||||
currentUp: parseInt('{{$service.CurrentUp}}'),
|
||||
currentDown: parseInt('{{$service.CurrentDown}}'),
|
||||
@@ -147,7 +126,8 @@
|
||||
service.dayDetail = this.getDayTails(service)
|
||||
service.totalUpTime = this.getProgressInfo(this.getPercent(service.totalUp, service.totalDown))
|
||||
}
|
||||
this.services = services
|
||||
this.servicesTag = this.groupingData(services,"type");
|
||||
this.servicesNoTag = services;
|
||||
},
|
||||
getPercent(up, down) {
|
||||
if (!up) {
|
||||
@@ -241,4 +221,4 @@
|
||||
})
|
||||
</script>
|
||||
{{template "theme-server-status/footer" .}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
@@ -12,3 +12,13 @@ site:
|
||||
brand: "nz_site_title"
|
||||
cookiename: "nezha-dashboard" #浏览器 Cookie 字段名,可不改
|
||||
theme: "default"
|
||||
ddns:
|
||||
enable: false
|
||||
provider: "webhook"
|
||||
accessid: ""
|
||||
accesssecret: ""
|
||||
webhookmethod: ""
|
||||
webhookurl: ""
|
||||
webhookrequestbody: ""
|
||||
webhookheaders: ""
|
||||
maxretries: 3
|
||||
|
||||
@@ -6,10 +6,9 @@ services:
|
||||
restart: always
|
||||
volumes:
|
||||
- ./data:/dashboard/data
|
||||
- ./static-custom/static:/dashboard/resource/static/custom:ro
|
||||
- ./theme-custom/template:/dashboard/resource/template/theme-custom:ro
|
||||
- ./theme-custom/static:/dashboard/resource/static/theme-custom:ro
|
||||
- ./dashboard-custom/template:/dashboard/resource/template/dashboard-custom:ro
|
||||
- ./dashboard-custom/static:/dashboard/resource/static/dashboard-custom:ro
|
||||
ports:
|
||||
- nz_site_port:80
|
||||
- nz_grpc_port:nz_grpc_port
|
||||
|
||||
+2
-2
@@ -38,8 +38,8 @@ $download = "https://github.com/$agentrepo/releases/download/$agenttag/$file"
|
||||
$nssmdownload="https://github.com/$nssmrepo/releases/download/$nssmtag/nssm.zip"
|
||||
Write-Host "Location:$region,connect directly!" -BackgroundColor DarkRed -ForegroundColor Green
|
||||
}else{
|
||||
$download = "https://dn-dao-github-mirror.daocloud.io/$agentrepo/releases/download/$agenttag/$file"
|
||||
$nssmdownload="https://dn-dao-github-mirror.daocloud.io/$nssmrepo/releases/download/$nssmtag/nssm.zip"
|
||||
$download = "https://kkgithub.com/$agentrepo/releases/download/$agenttag/$file"
|
||||
$nssmdownload="https://kkgithub.com/$nssmrepo/releases/download/$nssmtag/nssm.zip"
|
||||
Write-Host "Location:CN,use mirror address" -BackgroundColor DarkRed -ForegroundColor Green
|
||||
}
|
||||
echo $download
|
||||
|
||||
+565
-117
@@ -11,7 +11,10 @@ NZ_BASE_PATH="/opt/nezha"
|
||||
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
|
||||
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
||||
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
|
||||
NZ_VERSION="v0.15.0"
|
||||
NZ_AGENT_SERVICERC="/etc/init.d/nezha-agent"
|
||||
NZ_DASHBOARD_SERVICE="/etc/systemd/system/nezha-dashboard.service"
|
||||
NZ_DASHBOARD_SERVICERC="/etc/init.d/nezha-dashboard"
|
||||
NZ_VERSION="v0.15.8"
|
||||
|
||||
red='\033[0;31m'
|
||||
green='\033[0;32m'
|
||||
@@ -31,15 +34,15 @@ pre_check() {
|
||||
## os_arch
|
||||
if [[ $(uname -m | grep 'x86_64') != "" ]]; then
|
||||
os_arch="amd64"
|
||||
elif [[ $(uname -m | grep 'i386\|i686') != "" ]]; then
|
||||
elif [[ $(uname -m | grep 'i386\|i686') != "" ]]; then
|
||||
os_arch="386"
|
||||
elif [[ $(uname -m | grep 'aarch64\|armv8b\|armv8l') != "" ]]; then
|
||||
elif [[ $(uname -m | grep 'aarch64\|armv8b\|armv8l') != "" ]]; then
|
||||
os_arch="arm64"
|
||||
elif [[ $(uname -m | grep 'arm') != "" ]]; then
|
||||
elif [[ $(uname -m | grep 'arm') != "" ]]; then
|
||||
os_arch="arm"
|
||||
elif [[ $(uname -m | grep 's390x') != "" ]]; then
|
||||
elif [[ $(uname -m | grep 's390x') != "" ]]; then
|
||||
os_arch="s390x"
|
||||
elif [[ $(uname -m | grep 'riscv64') != "" ]]; then
|
||||
elif [[ $(uname -m | grep 'riscv64') != "" ]]; then
|
||||
os_arch="riscv64"
|
||||
fi
|
||||
|
||||
@@ -47,37 +50,57 @@ pre_check() {
|
||||
if [[ -z "${CN}" ]]; then
|
||||
if [[ $(curl -m 10 -s https://ipapi.co/json | grep 'China') != "" ]]; then
|
||||
echo "根据ipapi.co提供的信息,当前IP可能在中国"
|
||||
read -e -r -p "是否选用中国镜像完成安装? [Y/n] " input
|
||||
read -e -r -p "是否选用中国镜像完成安装? [Y/n] (自定义镜像输入 3):" input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
;;
|
||||
|
||||
[nN][oO] | [nN])
|
||||
echo "不使用中国镜像"
|
||||
[nN][oO] | [nN])
|
||||
echo "不使用中国镜像"
|
||||
;;
|
||||
|
||||
[3])
|
||||
echo "使用自定义镜像"
|
||||
read -e -r -p "请输入自定义镜像 (例如:dn-dao-github-mirror.daocloud.io),留空为不使用: " input
|
||||
case $input in
|
||||
*)
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
CUSTOM_MIRROR=$input
|
||||
;;
|
||||
esac
|
||||
|
||||
;;
|
||||
*)
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "${CN}" ]]; then
|
||||
GITHUB_RAW_URL="raw.githubusercontent.com/naiba/nezha/master"
|
||||
GITHUB_URL="github.com"
|
||||
if [[ -n "${CUSTOM_MIRROR}" ]]; then
|
||||
GITHUB_RAW_URL="gitee.com/naibahq/nezha/raw/master"
|
||||
GITHUB_URL=$CUSTOM_MIRROR
|
||||
Get_Docker_URL="get.docker.com"
|
||||
Get_Docker_Argu=" "
|
||||
Docker_IMG="ghcr.io\/naiba\/nezha-dashboard"
|
||||
else
|
||||
GITHUB_RAW_URL="jihulab.com/nezha/dashboard/-/raw/master"
|
||||
GITHUB_URL="dn-dao-github-mirror.daocloud.io"
|
||||
Get_Docker_URL="get.daocloud.io/docker"
|
||||
Get_Docker_Argu=" -s docker --mirror Aliyun"
|
||||
Docker_IMG="registry.cn-shanghai.aliyuncs.com\/naibahq\/nezha-dashboard"
|
||||
else
|
||||
if [[ -z "${CN}" ]]; then
|
||||
GITHUB_RAW_URL="raw.githubusercontent.com/naiba/nezha/master"
|
||||
GITHUB_URL="github.com"
|
||||
Get_Docker_URL="get.docker.com"
|
||||
Get_Docker_Argu=" "
|
||||
Docker_IMG="ghcr.io\/naiba\/nezha-dashboard"
|
||||
else
|
||||
GITHUB_RAW_URL="gitee.com/naibahq/nezha/raw/master"
|
||||
GITHUB_URL="kkgithub.com"
|
||||
Get_Docker_URL="get.docker.com"
|
||||
Get_Docker_Argu=" -s docker --mirror Aliyun"
|
||||
Docker_IMG="registry.cn-shanghai.aliyuncs.com\/naibahq\/nezha-dashboard"
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
confirm() {
|
||||
@@ -122,38 +145,39 @@ before_show_menu() {
|
||||
|
||||
install_base() {
|
||||
(command -v git >/dev/null 2>&1 && command -v curl >/dev/null 2>&1 && command -v wget >/dev/null 2>&1 && command -v unzip >/dev/null 2>&1 && command -v getenforce >/dev/null 2>&1) ||
|
||||
(install_soft curl wget git unzip)
|
||||
(install_soft curl wget git unzip)
|
||||
}
|
||||
install_arch(){
|
||||
|
||||
install_arch() {
|
||||
echo -e "${green}提示: ${plain} Arch安装libselinux需添加nezha-agent用户,安装完会自动删除,建议手动检查一次\n"
|
||||
read -e -r -p "是否安装libselinux? [Y/n] " input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
useradd -m nezha-agent
|
||||
sed -i "$ a\nezha-agent ALL=(ALL ) NOPASSWD:ALL" /etc/sudoers
|
||||
sudo -iu nezha-agent bash -c 'gpg --keyserver keys.gnupg.net --recv-keys BE22091E3EF62275;
|
||||
[yY][eE][sS] | [yY])
|
||||
useradd -m nezha-agent
|
||||
sed -i "$ a\nezha-agent ALL=(ALL ) NOPASSWD:ALL" /etc/sudoers
|
||||
sudo -iu nezha-agent bash -c 'gpg --keyserver keys.gnupg.net --recv-keys BE22091E3EF62275;
|
||||
cd /tmp; git clone https://aur.archlinux.org/libsepol.git; cd libsepol; makepkg -si --noconfirm --asdeps; cd ..;
|
||||
git clone https://aur.archlinux.org/libselinux.git; cd libselinux; makepkg -si --noconfirm; cd ..;
|
||||
rm -rf libsepol libselinux'
|
||||
sed -i '/nezha-agent/d' /etc/sudoers && sleep 30s && killall -u nezha-agent&&userdel nezha-agent
|
||||
echo -e "${red}提示: ${plain}已删除用户nezha-agent,请务必手动核查一遍!\n"
|
||||
sed -i '/nezha-agent/d' /etc/sudoers && sleep 30s && killall -u nezha-agent && userdel -r nezha-agent
|
||||
echo -e "${red}提示: ${plain}已删除用户nezha-agent,请务必手动核查一遍!\n"
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "不安装libselinux"
|
||||
[nN][oO] | [nN])
|
||||
echo "不安装libselinux"
|
||||
;;
|
||||
*)
|
||||
echo "不安装libselinux"
|
||||
exit 0
|
||||
*)
|
||||
echo "不安装libselinux"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
install_soft() {
|
||||
(command -v yum >/dev/null 2>&1 && yum makecache && yum install $* selinux-policy -y) ||
|
||||
(command -v apt >/dev/null 2>&1 && apt update && apt install $* selinux-utils -y) ||
|
||||
(command -v pacman >/dev/null 2>&1 && pacman -Syu $* base-devel --noconfirm && install_arch) ||
|
||||
(command -v apt-get >/dev/null 2>&1 && apt-get update && apt-get install $* selinux-utils -y) ||
|
||||
(command -v apk >/dev/null 2>&1 && apk update && apk add $* -f)
|
||||
(command -v apt >/dev/null 2>&1 && apt update && apt install $* selinux-utils -y) ||
|
||||
(command -v pacman >/dev/null 2>&1 && pacman -Syu $* base-devel --noconfirm && install_arch) ||
|
||||
(command -v apt-get >/dev/null 2>&1 && apt-get update && apt-get install $* selinux-utils -y) ||
|
||||
(command -v apk >/dev/null 2>&1 && apk update && apk add $* -f)
|
||||
}
|
||||
|
||||
install_dashboard() {
|
||||
@@ -162,22 +186,22 @@ install_dashboard() {
|
||||
echo -e "> 安装面板"
|
||||
|
||||
# 哪吒监控文件夹
|
||||
if [ ! -d "${NZ_DASHBOARD_PATH}" ]; then
|
||||
if [ ! -d "${NZ_DASHBOARD_PATH}/docker-compose.yaml" ]; then
|
||||
mkdir -p $NZ_DASHBOARD_PATH
|
||||
else
|
||||
echo "您可能已经安装过面板端,重复安装会覆盖数据,请注意备份。"
|
||||
read -e -r -p "是否退出安装? [Y/n] " input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "退出安装"
|
||||
exit 0
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "退出安装"
|
||||
exit 0
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "继续安装"
|
||||
[nN][oO] | [nN])
|
||||
echo "继续安装"
|
||||
;;
|
||||
*)
|
||||
echo "退出安装"
|
||||
exit 0
|
||||
*)
|
||||
echo "退出安装"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
@@ -204,11 +228,51 @@ install_dashboard() {
|
||||
fi
|
||||
}
|
||||
|
||||
selinux(){
|
||||
install_dashboard_standalone() {
|
||||
install_base
|
||||
|
||||
echo -e "> 安装面板"
|
||||
|
||||
# 哪吒监控文件夹
|
||||
if [ ! -d "${NZ_DASHBOARD_PATH}/app" ]; then
|
||||
mkdir -p $NZ_DASHBOARD_PATH
|
||||
else
|
||||
echo "您可能已经安装过面板端,重复安装会覆盖数据,请注意备份。"
|
||||
read -e -r -p "是否退出安装? [Y/n] " input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "退出安装"
|
||||
exit 0
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "继续安装"
|
||||
;;
|
||||
*)
|
||||
echo "退出安装"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ ! -d "${NZ_DASHBOARD_PATH}/resource/template/theme-custom" ] || [ ! -d "${NZ_DASHBOARD_PATH}/resource/static/custom" ]; then
|
||||
mkdir -p "${NZ_DASHBOARD_PATH}/resource/template/theme-custom" "${NZ_DASHBOARD_PATH}/resource/static/custom" >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
chmod 777 -R $NZ_DASHBOARD_PATH
|
||||
|
||||
modify_dashboard_config_standalone 0
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
selinux() {
|
||||
#判断当前的状态
|
||||
if [ "$os_alpine" != 1 ];then
|
||||
command -v getenforce >/dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
getenforce | grep '[Ee]nfor'
|
||||
if [ $? -eq 0 ];then
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "SELinux是开启状态,正在关闭!"
|
||||
setenforce 0 &>/dev/null
|
||||
find_key="SELINUX="
|
||||
@@ -252,8 +316,8 @@ install_agent() {
|
||||
fi
|
||||
|
||||
unzip -qo nezha-agent_linux_${os_arch}.zip &&
|
||||
mv nezha-agent $NZ_AGENT_PATH &&
|
||||
rm -rf nezha-agent_linux_${os_arch}.zip README.md
|
||||
mv nezha-agent $NZ_AGENT_PATH &&
|
||||
rm -rf nezha-agent_linux_${os_arch}.zip README.md
|
||||
|
||||
if [ $# -ge 3 ]; then
|
||||
modify_agent_config "$@"
|
||||
@@ -269,21 +333,28 @@ install_agent() {
|
||||
modify_agent_config() {
|
||||
echo -e "> 修改Agent配置"
|
||||
|
||||
if [ "$os_alpine" != 1 ];then
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
wget -t 2 -T 10 -O $NZ_AGENT_SERVICE https://${GITHUB_RAW_URL}/script/nezha-agent.service >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}文件下载失败,请检查本机能否连接 ${GITHUB_RAW_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
wget -t 2 -T 10 -O $NZ_AGENT_SERVICERC https://${GITHUB_RAW_URL}/script/nezha-agent >/dev/null 2>&1
|
||||
chmod +x $NZ_AGENT_SERVICERC
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}Fail to download service, please check if the network can link ${GITHUB_RAW_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $# -lt 3 ]; then
|
||||
echo "请先在管理面板上添加Agent,记录下密钥" &&
|
||||
read -ep "请输入一个解析到面板所在IP的域名(不可套CDN): " nz_grpc_host &&
|
||||
read -ep "请输入面板RPC端口 (默认值 5555): " nz_grpc_port &&
|
||||
read -ep "请输入Agent 密钥: " nz_client_secret &&
|
||||
read -ep "是否启用针对 gRPC 端口的 SSL/TLS加密 (--tls),需要请按 [y],默认是不需要,不理解用户可回车跳过: " nz_grpc_proxy
|
||||
grep -qiw 'Y' <<< "${nz_grpc_proxy}" && args='--tls'
|
||||
read -ep "请输入一个解析到面板所在IP的域名(不可套CDN): " nz_grpc_host &&
|
||||
read -ep "请输入面板RPC端口 (默认值 5555): " nz_grpc_port &&
|
||||
read -ep "请输入Agent 密钥: " nz_client_secret &&
|
||||
read -ep "是否启用针对 gRPC 端口的 SSL/TLS加密 (--tls),需要请按 [y],默认是不需要,不理解用户可回车跳过: " nz_grpc_proxy
|
||||
grep -qiw 'Y' <<<"${nz_grpc_proxy}" && args='--tls'
|
||||
if [[ -z "${nz_grpc_host}" || -z "${nz_client_secret}" ]]; then
|
||||
echo -e "${red}所有选项都不能为空${plain}"
|
||||
before_show_menu
|
||||
@@ -302,29 +373,32 @@ modify_agent_config() {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$os_alpine" != 1 ];then
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICE}
|
||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICE}
|
||||
sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICE}
|
||||
[ -n "${args}" ] && sed -i "/ExecStart/ s/$/ ${args}/" ${NZ_AGENT_SERVICE}
|
||||
else
|
||||
echo "@reboot ${NZ_AGENT_PATH}/nezha-agent -s ${nz_grpc_host}:${nz_grpc_port} -p ${nz_client_secret} ${args}" >> /etc/crontabs/root
|
||||
crond
|
||||
sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICERC}
|
||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICERC}
|
||||
sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICERC}
|
||||
[ -n "${args}" ] && sed -i "/command_args/ s/\"$/ ${args}\"/" ${NZ_AGENT_SERVICERC}
|
||||
fi
|
||||
|
||||
echo -e "Agent配置 ${green}修改成功,请稍等重启生效${plain}"
|
||||
|
||||
if [ "$os_alpine" != 1 ];then
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl daemon-reload
|
||||
systemctl enable nezha-agent
|
||||
systemctl restart nezha-agent
|
||||
else
|
||||
nohup ${NZ_AGENT_PATH}/nezha-agent -s ${nz_grpc_host}:${nz_grpc_port} -p ${nz_client_secret} ${args} >/dev/null 2>&1 &
|
||||
rc-update add nezha-agent
|
||||
rc-service nezha-agent restart
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
#if [[ $# == 0 ]]; then
|
||||
# before_show_menu
|
||||
#fi
|
||||
}
|
||||
|
||||
modify_dashboard_config() {
|
||||
@@ -344,14 +418,14 @@ modify_dashboard_config() {
|
||||
fi
|
||||
|
||||
echo "关于 GitHub Oauth2 应用:在 https://github.com/settings/developers 创建,无需审核,Callback 填 http(s)://域名或IP/oauth2/callback" &&
|
||||
echo "关于 Gitee Oauth2 应用:在 https://gitee.com/oauth/applications 创建,无需审核,Callback 填 http(s)://域名或IP/oauth2/callback" &&
|
||||
read -ep "请输入 OAuth2 提供商(github/gitlab/jihulab/gitee,默认 github): " nz_oauth2_type &&
|
||||
read -ep "请输入 Oauth2 应用的 Client ID: " nz_github_oauth_client_id &&
|
||||
read -ep "请输入 Oauth2 应用的 Client Secret: " nz_github_oauth_client_secret &&
|
||||
read -ep "请输入 GitHub/Gitee 登录名作为管理员,多个以逗号隔开: " nz_admin_logins &&
|
||||
read -ep "请输入站点标题: " nz_site_title &&
|
||||
read -ep "请输入站点访问端口: (默认 8008)" nz_site_port &&
|
||||
read -ep "请输入用于 Agent 接入的 RPC 端口: (默认 5555)" nz_grpc_port
|
||||
echo "关于 Gitee Oauth2 应用:在 https://gitee.com/oauth/applications 创建,无需审核,Callback 填 http(s)://域名或IP/oauth2/callback" &&
|
||||
read -ep "请输入 OAuth2 提供商(github/gitlab/jihulab/gitee,默认 github): " nz_oauth2_type &&
|
||||
read -ep "请输入 Oauth2 应用的 Client ID: " nz_github_oauth_client_id &&
|
||||
read -ep "请输入 Oauth2 应用的 Client Secret: " nz_github_oauth_client_secret &&
|
||||
read -ep "请输入 GitHub/Gitee 登录名作为管理员,多个以逗号隔开: " nz_admin_logins &&
|
||||
read -ep "请输入站点标题: " nz_site_title &&
|
||||
read -ep "请输入站点访问端口: (默认 8008)" nz_site_port &&
|
||||
read -ep "请输入用于 Agent 接入的 RPC 端口: (默认 5555)" nz_grpc_port
|
||||
|
||||
if [[ -z "${nz_admin_logins}" || -z "${nz_github_oauth_client_id}" || -z "${nz_github_oauth_client_secret}" || -z "${nz_site_title}" ]]; then
|
||||
echo -e "${red}所有选项都不能为空${plain}"
|
||||
@@ -393,6 +467,77 @@ modify_dashboard_config() {
|
||||
fi
|
||||
}
|
||||
|
||||
modify_dashboard_config_standalone() {
|
||||
echo -e "> 修改面板配置"
|
||||
|
||||
echo -e "正在下载配置模板"
|
||||
|
||||
wget -t 2 -T 10 -O /tmp/nezha-config.yaml https://${GITHUB_RAW_URL}/script/config.yaml >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}下载文件失败,请检查本机能否连接 ${GITHUB_RAW_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "关于 GitHub Oauth2 应用:在 https://github.com/settings/developers 创建,无需审核,Callback 填 http(s)://域名或IP/oauth2/callback" &&
|
||||
echo "关于 Gitee Oauth2 应用:在 https://gitee.com/oauth/applications 创建,无需审核,Callback 填 http(s)://域名或IP/oauth2/callback" &&
|
||||
read -ep "请输入 OAuth2 提供商(github/gitlab/jihulab/gitee,默认 github): " nz_oauth2_type &&
|
||||
read -ep "请输入 Oauth2 应用的 Client ID: " nz_github_oauth_client_id &&
|
||||
read -ep "请输入 Oauth2 应用的 Client Secret: " nz_github_oauth_client_secret &&
|
||||
read -ep "请输入 GitHub/Gitee 登录名作为管理员,多个以逗号隔开: " nz_admin_logins &&
|
||||
read -ep "请输入站点标题: " nz_site_title &&
|
||||
read -ep "请输入站点访问端口: (默认 8008)" nz_site_port &&
|
||||
read -ep "请输入用于 Agent 接入的 RPC 端口: (默认 5555)" nz_grpc_port
|
||||
|
||||
if [[ -z "${nz_admin_logins}" || -z "${nz_github_oauth_client_id}" || -z "${nz_github_oauth_client_secret}" || -z "${nz_site_title}" ]]; then
|
||||
echo -e "${red}所有选项都不能为空${plain}"
|
||||
before_show_menu
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -z "${nz_site_port}" ]]; then
|
||||
nz_site_port=8008
|
||||
fi
|
||||
if [[ -z "${nz_grpc_port}" ]]; then
|
||||
nz_grpc_port=5555
|
||||
fi
|
||||
if [[ -z "${nz_oauth2_type}" ]]; then
|
||||
nz_oauth2_type=github
|
||||
fi
|
||||
|
||||
sed -i "s/nz_oauth2_type/${nz_oauth2_type}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_admin_logins/${nz_admin_logins}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_github_oauth_client_id/${nz_github_oauth_client_id}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_github_oauth_client_secret/${nz_github_oauth_client_secret}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_language/zh-CN/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_site_title/${nz_site_title}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/80/${nz_site_port}/" /tmp/nezha-config.yaml
|
||||
|
||||
mkdir -p $NZ_DASHBOARD_PATH/data
|
||||
mv -f /tmp/nezha-config.yaml ${NZ_DASHBOARD_PATH}/data/config.yaml
|
||||
|
||||
echo -e "正在下载服务文件"
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
wget -t 2 -T 10 -O $NZ_DASHBOARD_SERVICE https://${GITHUB_RAW_URL}/script/nezha-dashboard.service >/dev/null 2>&1
|
||||
else
|
||||
wget -t 2 -T 10 -O $NZ_DASHBOARD_SERVICERC https://${GITHUB_RAW_URL}/script/nezha-dashboard >/dev/null 2>&1
|
||||
chmod +x $NZ_DASHBOARD_SERVICERC
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}文件下载失败,请检查本机能否连接 ${GITHUB_RAW_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "面板配置 ${green}修改成功,请稍等重启生效${plain}"
|
||||
|
||||
restart_and_update_standalone
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
restart_and_update() {
|
||||
echo -e "> 重启并更新面板"
|
||||
|
||||
@@ -421,6 +566,40 @@ restart_and_update() {
|
||||
fi
|
||||
}
|
||||
|
||||
restart_and_update_standalone() {
|
||||
echo -e "> 重启并更新面板"
|
||||
|
||||
cd $NZ_DASHBOARD_PATH
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl stop nezha-dashboard
|
||||
else
|
||||
rc-service nezha-dashboard stop
|
||||
fi
|
||||
|
||||
wget -qO app.zip https://${GITHUB_URL}/naiba/nezha/releases/latest/download/dashboard-linux-$os_arch.zip >/dev/null 2>&1 && unzip -qq app.zip && mv dist/dashboard-linux-$os_arch app && rm -r app.zip dist
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl daemon-reload
|
||||
systemctl enable nezha-dashboard
|
||||
systemctl restart nezha-dashboard
|
||||
else
|
||||
rc-update add nezha-dashboard
|
||||
rc-service nezha-dashboard restart
|
||||
fi
|
||||
|
||||
if [[ $? == 0 ]]; then
|
||||
echo -e "${green}哪吒监控 重启成功${plain}"
|
||||
echo -e "默认管理面板地址:${yellow}域名:站点访问端口${plain}"
|
||||
else
|
||||
echo -e "${red}重启失败,可能是因为启动时间超过了两秒,请稍后查看日志信息${plain}"
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
start_dashboard() {
|
||||
echo -e "> 启动面板"
|
||||
|
||||
@@ -442,6 +621,26 @@ start_dashboard() {
|
||||
fi
|
||||
}
|
||||
|
||||
start_dashboard_standalone() {
|
||||
echo -e "> 启动面板"
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl start nezha-dashboard
|
||||
else
|
||||
rc-service nezha-dashboard start
|
||||
fi
|
||||
|
||||
if [[ $? == 0 ]]; then
|
||||
echo -e "${green}哪吒监控 启动成功${plain}"
|
||||
else
|
||||
echo -e "${red}启动失败,请稍后查看日志信息${plain}"
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
stop_dashboard() {
|
||||
echo -e "> 停止面板"
|
||||
|
||||
@@ -463,6 +662,26 @@ stop_dashboard() {
|
||||
fi
|
||||
}
|
||||
|
||||
stop_dashboard_standalone() {
|
||||
echo -e "> 停止面板"
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl stop nezha-dashboard
|
||||
else
|
||||
rc-service nezha-dashboard stop
|
||||
fi
|
||||
|
||||
if [[ $? == 0 ]]; then
|
||||
echo -e "${green}哪吒监控 停止成功${plain}"
|
||||
else
|
||||
echo -e "${red}停止失败,请稍后查看日志信息${plain}"
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
show_dashboard_log() {
|
||||
echo -e "> 获取面板日志"
|
||||
|
||||
@@ -478,6 +697,20 @@ show_dashboard_log() {
|
||||
fi
|
||||
}
|
||||
|
||||
show_dashboard_log_standalone() {
|
||||
echo -e "> 获取面板日志"
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
journalctl -xf -u nezha-dashboard.service
|
||||
else
|
||||
echo "很抱歉,OpenRC 无此功能"
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
uninstall_dashboard() {
|
||||
echo -e "> 卸载管理面板"
|
||||
|
||||
@@ -489,8 +722,32 @@ uninstall_dashboard() {
|
||||
fi
|
||||
|
||||
rm -rf $NZ_DASHBOARD_PATH
|
||||
docker rmi -f ghcr.io/naiba/nezha-dashboard > /dev/null 2>&1
|
||||
docker rmi -f registry.cn-shanghai.aliyuncs.com/naibahq/nezha-dashboard > /dev/null 2>&1
|
||||
docker rmi -f ghcr.io/naiba/nezha-dashboard >/dev/null 2>&1
|
||||
docker rmi -f registry.cn-shanghai.aliyuncs.com/naibahq/nezha-dashboard >/dev/null 2>&1
|
||||
clean_all
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
uninstall_dashboard_standalone() {
|
||||
echo -e "> 卸载管理面板"
|
||||
|
||||
rm -rf $NZ_DASHBOARD_PATH
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl stop nezha-dashboard
|
||||
else
|
||||
rc-service nezha-dashboard stop
|
||||
fi
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
rm $NZ_DASHBOARD_SERVICE
|
||||
else
|
||||
rm $NZ_DASHBOARD_SERVICERC
|
||||
fi
|
||||
|
||||
clean_all
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
@@ -501,7 +758,11 @@ uninstall_dashboard() {
|
||||
show_agent_log() {
|
||||
echo -e "> 获取Agent日志"
|
||||
|
||||
journalctl -xf -u nezha-agent.service
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
journalctl -xf -u nezha-agent.service
|
||||
else
|
||||
echo "很抱歉,OpenRC 无此功能"
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
@@ -511,14 +772,15 @@ show_agent_log() {
|
||||
uninstall_agent() {
|
||||
echo -e "> 卸载Agent"
|
||||
|
||||
if [ "$os_alpine" != 1 ];then
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl disable nezha-agent.service
|
||||
systemctl stop nezha-agent.service
|
||||
rm -rf $NZ_AGENT_SERVICE
|
||||
systemctl daemon-reload
|
||||
else
|
||||
grep -q 'nezha-agent' /var/spool/cron/crontabs/root && sed -i "/nezha-agent/d" /var/spool/cron/crontabs/root
|
||||
pkill nezha-agent
|
||||
rc-update del nezha-agent
|
||||
rc-service nezha-agent stop
|
||||
rm -rf $NZ_AGENT_SERVICERC
|
||||
fi
|
||||
|
||||
rm -rf $NZ_AGENT_PATH
|
||||
@@ -532,7 +794,11 @@ uninstall_agent() {
|
||||
restart_agent() {
|
||||
echo -e "> 重启Agent"
|
||||
|
||||
systemctl restart nezha-agent.service
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl restart nezha-agent.service
|
||||
else
|
||||
rc-service nezha-agent restart
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
@@ -545,6 +811,59 @@ clean_all() {
|
||||
fi
|
||||
}
|
||||
|
||||
select_version() {
|
||||
DOCKER_COMPOSE_COMMAND=""
|
||||
if docker compose version >/dev/null 2>&1; then
|
||||
DOCKER_COMPOSE_COMMAND="docker compose"
|
||||
if $DOCKER_COMPOSE_COMMAND ls | grep -qw "$NZ_DASHBOARD_PATH/docker-compose.yaml" >/dev/null 2>&1; then
|
||||
NEZHA_IMAGES=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep -w "nezha-dashboard")
|
||||
if [ -n "$NEZHA_IMAGES" ]; then
|
||||
echo "存在带有 nezha-dashboard 仓库的 Docker 镜像:"
|
||||
echo "$NEZHA_IMAGES"
|
||||
IS_DOCKER_NEZHA=1
|
||||
return
|
||||
else
|
||||
echo "未找到带有 nezha-dashboard 仓库的 Docker 镜像。"
|
||||
fi
|
||||
fi
|
||||
elif command -v docker-compose >/dev/null 2>&1; then
|
||||
DOCKER_COMPOSE_COMMAND="docker-compose"
|
||||
if $DOCKER_COMPOSE_COMMAND -f "$NZ_DASHBOARD_PATH/docker-compose.yaml" config >/dev/null 2>&1; then
|
||||
NEZHA_IMAGES=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep -w "nezha-dashboard")
|
||||
if [ -n "$NEZHA_IMAGES" ]; then
|
||||
echo "存在带有 nezha-dashboard 仓库的 Docker 镜像:"
|
||||
echo "$NEZHA_IMAGES"
|
||||
IS_DOCKER_NEZHA=1
|
||||
return
|
||||
else
|
||||
echo "未找到带有 nezha-dashboard 仓库的 Docker 镜像。"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -f $NZ_DASHBOARD_PATH/app ]]; then
|
||||
IS_DOCKER_NEZHA=0
|
||||
else
|
||||
echo -e "${yellow}请自行选择您的安装方式(如果你是安装Agent,输入哪个都是一样的):\n1. Docker\n2. 独立安装${plain}"
|
||||
while true; do
|
||||
read -e -r -p "请输入数字 [1-2]:" option
|
||||
case "${option}" in
|
||||
1)
|
||||
IS_DOCKER_NEZHA=1
|
||||
break
|
||||
;;
|
||||
2)
|
||||
IS_DOCKER_NEZHA=0
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "输入有误,请重新输入"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
show_usage() {
|
||||
echo "哪吒监控 管理脚本使用方法: "
|
||||
echo "--------------------------------------------------------"
|
||||
@@ -589,81 +908,133 @@ show_menu() {
|
||||
${green}0.${plain} 退出脚本
|
||||
"
|
||||
echo && read -ep "请输入选择 [0-13]: " num
|
||||
|
||||
case "${num}" in
|
||||
if [[ $IS_DOCKER_NEZHA == 1 ]]; then
|
||||
case "${num}" in
|
||||
0)
|
||||
exit 0
|
||||
;;
|
||||
;;
|
||||
1)
|
||||
install_dashboard
|
||||
;;
|
||||
;;
|
||||
2)
|
||||
modify_dashboard_config
|
||||
;;
|
||||
;;
|
||||
3)
|
||||
start_dashboard
|
||||
;;
|
||||
;;
|
||||
4)
|
||||
stop_dashboard
|
||||
;;
|
||||
;;
|
||||
5)
|
||||
restart_and_update
|
||||
;;
|
||||
;;
|
||||
6)
|
||||
show_dashboard_log
|
||||
;;
|
||||
;;
|
||||
7)
|
||||
uninstall_dashboard
|
||||
;;
|
||||
;;
|
||||
8)
|
||||
install_agent
|
||||
;;
|
||||
;;
|
||||
9)
|
||||
modify_agent_config
|
||||
;;
|
||||
;;
|
||||
10)
|
||||
show_agent_log
|
||||
;;
|
||||
;;
|
||||
11)
|
||||
uninstall_agent
|
||||
;;
|
||||
;;
|
||||
12)
|
||||
restart_agent
|
||||
;;
|
||||
;;
|
||||
13)
|
||||
update_script
|
||||
;;
|
||||
;;
|
||||
*)
|
||||
echo -e "${red}请输入正确的数字 [0-13]${plain}"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
elif [[ $IS_DOCKER_NEZHA == 0 ]]; then
|
||||
case "${num}" in
|
||||
0)
|
||||
exit 0
|
||||
;;
|
||||
1)
|
||||
install_dashboard_standalone
|
||||
;;
|
||||
2)
|
||||
modify_dashboard_config_standalone
|
||||
;;
|
||||
3)
|
||||
start_dashboard_standalone
|
||||
;;
|
||||
4)
|
||||
stop_dashboard_standalone
|
||||
;;
|
||||
5)
|
||||
restart_and_update_standalone
|
||||
;;
|
||||
6)
|
||||
show_dashboard_log_standalone
|
||||
;;
|
||||
7)
|
||||
uninstall_dashboard_standalone
|
||||
;;
|
||||
8)
|
||||
install_agent
|
||||
;;
|
||||
9)
|
||||
modify_agent_config
|
||||
;;
|
||||
10)
|
||||
show_agent_log
|
||||
;;
|
||||
11)
|
||||
uninstall_agent
|
||||
;;
|
||||
12)
|
||||
restart_agent
|
||||
;;
|
||||
13)
|
||||
update_script
|
||||
;;
|
||||
*)
|
||||
echo -e "${red}请输入正确的数字 [0-13]${plain}"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
select_version
|
||||
fi
|
||||
}
|
||||
|
||||
pre_check
|
||||
|
||||
if [[ $# > 0 ]]; then
|
||||
case $1 in
|
||||
if [[ $IS_DOCKER_NEZHA == 1 ]]; then
|
||||
case $1 in
|
||||
"install_dashboard")
|
||||
install_dashboard 0
|
||||
;;
|
||||
;;
|
||||
"modify_dashboard_config")
|
||||
modify_dashboard_config 0
|
||||
;;
|
||||
;;
|
||||
"start_dashboard")
|
||||
start_dashboard 0
|
||||
;;
|
||||
;;
|
||||
"stop_dashboard")
|
||||
stop_dashboard 0
|
||||
;;
|
||||
;;
|
||||
"restart_and_update")
|
||||
restart_and_update 0
|
||||
;;
|
||||
;;
|
||||
"show_dashboard_log")
|
||||
show_dashboard_log 0
|
||||
;;
|
||||
;;
|
||||
"uninstall_dashboard")
|
||||
uninstall_dashboard 0
|
||||
;;
|
||||
;;
|
||||
"install_agent")
|
||||
shift
|
||||
if [ $# -ge 3 ]; then
|
||||
@@ -671,24 +1042,101 @@ if [[ $# > 0 ]]; then
|
||||
else
|
||||
install_agent 0
|
||||
fi
|
||||
;;
|
||||
;;
|
||||
"modify_agent_config")
|
||||
modify_agent_config 0
|
||||
;;
|
||||
;;
|
||||
"show_agent_log")
|
||||
show_agent_log 0
|
||||
;;
|
||||
;;
|
||||
"uninstall_agent")
|
||||
uninstall_agent 0
|
||||
;;
|
||||
;;
|
||||
"restart_agent")
|
||||
restart_agent 0
|
||||
;;
|
||||
;;
|
||||
"update_script")
|
||||
update_script 0
|
||||
;;
|
||||
;;
|
||||
*) show_usage ;;
|
||||
esac
|
||||
esac
|
||||
elif [[ $IS_DOCKER_NEZHA == 0 ]]; then
|
||||
case $1 in
|
||||
"install_dashboard")
|
||||
install_dashboard_standalone 0
|
||||
;;
|
||||
"modify_dashboard_config")
|
||||
modify_dashboard_config_standalone 0
|
||||
;;
|
||||
"start_dashboard")
|
||||
start_dashboard_standalone 0
|
||||
;;
|
||||
"stop_dashboard")
|
||||
stop_dashboard_standalone 0
|
||||
;;
|
||||
"restart_and_update")
|
||||
restart_and_update_standalone 0
|
||||
;;
|
||||
"show_dashboard_log")
|
||||
show_dashboard_log_standalone 0
|
||||
;;
|
||||
"uninstall_dashboard")
|
||||
uninstall_dashboard_standalone 0
|
||||
;;
|
||||
"install_agent")
|
||||
shift
|
||||
if [ $# -ge 3 ]; then
|
||||
install_agent "$@"
|
||||
else
|
||||
install_agent 0
|
||||
fi
|
||||
;;
|
||||
"modify_agent_config")
|
||||
modify_agent_config 0
|
||||
;;
|
||||
"show_agent_log")
|
||||
show_agent_log 0
|
||||
;;
|
||||
"uninstall_agent")
|
||||
uninstall_agent 0
|
||||
;;
|
||||
"restart_agent")
|
||||
restart_agent 0
|
||||
;;
|
||||
"update_script")
|
||||
update_script 0
|
||||
;;
|
||||
*) show_usage ;;
|
||||
esac
|
||||
else
|
||||
case $1 in
|
||||
"install_agent")
|
||||
shift
|
||||
if [ $# -ge 3 ]; then
|
||||
install_agent "$@"
|
||||
else
|
||||
install_agent 0
|
||||
fi
|
||||
;;
|
||||
"modify_agent_config")
|
||||
modify_agent_config 0
|
||||
;;
|
||||
"show_agent_log")
|
||||
show_agent_log 0
|
||||
;;
|
||||
"uninstall_agent")
|
||||
uninstall_agent 0
|
||||
;;
|
||||
"restart_agent")
|
||||
restart_agent 0
|
||||
;;
|
||||
"update_script")
|
||||
update_script 0
|
||||
;;
|
||||
*) show_usage ;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
select_version
|
||||
show_menu
|
||||
fi
|
||||
fi
|
||||
|
||||
+564
-119
@@ -11,7 +11,10 @@ NZ_BASE_PATH="/opt/nezha"
|
||||
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
|
||||
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
||||
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
|
||||
NZ_VERSION="v0.15.0"
|
||||
NZ_AGENT_SERVICERC="/etc/init.d/nezha-agent"
|
||||
NZ_DASHBOARD_SERVICE="/etc/systemd/system/nezha-dashboard.service"
|
||||
NZ_DASHBOARD_SERVICERC="/etc/init.d/nezha-dashboard"
|
||||
NZ_VERSION="v0.15.8"
|
||||
|
||||
red='\033[0;31m'
|
||||
green='\033[0;32m'
|
||||
@@ -31,15 +34,15 @@ pre_check() {
|
||||
## os_arch
|
||||
if [[ $(uname -m | grep 'x86_64') != "" ]]; then
|
||||
os_arch="amd64"
|
||||
elif [[ $(uname -m | grep 'i386\|i686') != "" ]]; then
|
||||
elif [[ $(uname -m | grep 'i386\|i686') != "" ]]; then
|
||||
os_arch="386"
|
||||
elif [[ $(uname -m | grep 'aarch64\|armv8b\|armv8l') != "" ]]; then
|
||||
elif [[ $(uname -m | grep 'aarch64\|armv8b\|armv8l') != "" ]]; then
|
||||
os_arch="arm64"
|
||||
elif [[ $(uname -m | grep 'arm') != "" ]]; then
|
||||
elif [[ $(uname -m | grep 'arm') != "" ]]; then
|
||||
os_arch="arm"
|
||||
elif [[ $(uname -m | grep 's390x') != "" ]]; then
|
||||
elif [[ $(uname -m | grep 's390x') != "" ]]; then
|
||||
os_arch="s390x"
|
||||
elif [[ $(uname -m | grep 'riscv64') != "" ]]; then
|
||||
elif [[ $(uname -m | grep 'riscv64') != "" ]]; then
|
||||
os_arch="riscv64"
|
||||
fi
|
||||
|
||||
@@ -47,41 +50,60 @@ pre_check() {
|
||||
if [[ -z "${CN}" ]]; then
|
||||
if [[ $(curl -m 10 -s https://ipapi.co/json | grep 'China') != "" ]]; then
|
||||
echo "According to the information provided by ipapi.co, the current IP may be in China"
|
||||
read -e -r -p "Is the installation done with a Chinese Mirror? [Y/n] " input
|
||||
read -e -r -p "Is the installation done with a Chinese Mirror? [Y/n] (Custom Mirror Input 3):" input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "Use Chinese Mirror"
|
||||
CN=true
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "Use Chinese Mirror"
|
||||
CN=true
|
||||
;;
|
||||
|
||||
[nN][oO] | [nN])
|
||||
echo "No Use Chinese Mirror"
|
||||
[nN][oO] | [nN])
|
||||
echo "No Use Chinese Mirror"
|
||||
;;
|
||||
|
||||
[3])
|
||||
echo "Use Custom Mirror"
|
||||
read -e -r -p "Please enter a custom image (e.g. :dn-dao-github-mirror.daocloud.io), leave blank to nouse: " input
|
||||
case $input in
|
||||
*)
|
||||
echo "No Use Chinese Mirror"
|
||||
CUSTOM_MIRROR=$input
|
||||
;;
|
||||
esac
|
||||
|
||||
;;
|
||||
*)
|
||||
echo "No Use Chinese Mirror"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "${CN}" ]]; then
|
||||
GITHUB_RAW_URL="raw.githubusercontent.com/naiba/nezha/master"
|
||||
GITHUB_URL="github.com"
|
||||
if [[ -n "${CUSTOM_MIRROR}" ]]; then
|
||||
GITHUB_RAW_URL="gitee.com/naibahq/nezha/raw/master"
|
||||
GITHUB_URL=$CUSTOM_MIRROR
|
||||
Get_Docker_URL="get.docker.com"
|
||||
Get_Docker_Argu=" "
|
||||
Docker_IMG="ghcr.io\/naiba\/nezha-dashboard"
|
||||
else
|
||||
GITHUB_RAW_URL="jihulab.com/nezha/dashboard/-/raw/master"
|
||||
GITHUB_URL="dn-dao-github-mirror.daocloud.io"
|
||||
Get_Docker_URL="get.daocloud.io/docker"
|
||||
Get_Docker_Argu=" -s docker --mirror Aliyun"
|
||||
Docker_IMG="registry.cn-shanghai.aliyuncs.com\/naibahq\/nezha-dashboard"
|
||||
else
|
||||
if [[ -z "${CN}" ]]; then
|
||||
GITHUB_RAW_URL="raw.githubusercontent.com/naiba/nezha/master"
|
||||
GITHUB_URL="github.com"
|
||||
Get_Docker_URL="get.docker.com"
|
||||
Get_Docker_Argu=" "
|
||||
Docker_IMG="ghcr.io\/naiba\/nezha-dashboard"
|
||||
else
|
||||
GITHUB_RAW_URL="gitee.com/naibahq/nezha/raw/master"
|
||||
GITHUB_URL="kkgithub.com"
|
||||
Get_Docker_URL="get.docker.com"
|
||||
Get_Docker_Argu=" -s docker --mirror Aliyun"
|
||||
Docker_IMG="registry.cn-shanghai.aliyuncs.com\/naibahq\/nezha-dashboard"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
confirm() {
|
||||
if [[ $# > 1 ]]; then
|
||||
echo && read -e -p "$1 [Default$2]: " temp
|
||||
echo && read -e -p "$1 [默认$2]: " temp
|
||||
if [[ x"${temp}" == x"" ]]; then
|
||||
temp=$2
|
||||
fi
|
||||
@@ -101,7 +123,7 @@ update_script() {
|
||||
curl -sL https://${GITHUB_RAW_URL}/script/install_en.sh -o /tmp/nezha.sh
|
||||
new_version=$(cat /tmp/nezha.sh | grep "NZ_VERSION" | head -n 1 | awk -F "=" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
|
||||
if [ ! -n "$new_version" ]; then
|
||||
echo -e "Script failed to get, please check if the network can link https://${GITHUB_RAW_URL}/script/install_en.sh"
|
||||
echo -e "Script failed to get, please check if the network can link https://${GITHUB_RAW_URL}/script/install.sh"
|
||||
return 1
|
||||
fi
|
||||
echo -e "The current latest version is: ${new_version}"
|
||||
@@ -121,39 +143,39 @@ before_show_menu() {
|
||||
|
||||
install_base() {
|
||||
(command -v git >/dev/null 2>&1 && command -v curl >/dev/null 2>&1 && command -v wget >/dev/null 2>&1 && command -v unzip >/dev/null 2>&1 && command -v getenforce >/dev/null 2>&1) ||
|
||||
(install_soft curl wget git unzip)
|
||||
(install_soft curl wget git unzip tzdata)
|
||||
}
|
||||
install_arch(){
|
||||
|
||||
install_arch() {
|
||||
echo -e "${green}Info: ${plain} Archlinux needs to add nezha-agent user to install libselinux. It will be deleted automatically after installation. It is recommended to check manually\n"
|
||||
read -e -r -p "Do you need to install libselinux? [Y/n] " input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
useradd -m nezha-agent
|
||||
sed -i "$ a\nezha-agent ALL=(ALL ) NOPASSWD:ALL" /etc/sudoers
|
||||
sudo -iu nezha-agent bash -c 'gpg --keyserver keys.gnupg.net --recv-keys BE22091E3EF62275;
|
||||
[yY][eE][sS] | [yY])
|
||||
useradd -m nezha-agent
|
||||
sed -i "$ a\nezha-agent ALL=(ALL ) NOPASSWD:ALL" /etc/sudoers
|
||||
sudo -iu nezha-agent bash -c 'gpg --keyserver keys.gnupg.net --recv-keys BE22091E3EF62275;
|
||||
cd /tmp; git clone https://aur.archlinux.org/libsepol.git; cd libsepol; makepkg -si --noconfirm --asdeps; cd ..;
|
||||
git clone https://aur.archlinux.org/libselinux.git; cd libselinux; makepkg -si --noconfirm; cd ..;
|
||||
rm -rf libsepol libselinux'
|
||||
sed -i '/nezha-agent/d' /etc/sudoers && sleep 30s && killall -u nezha-agent&&userdel nezha-agent
|
||||
echo -e "${red}Info: ${plain}user nezha-agent has been deleted, Be sure to check it manually!\n"
|
||||
sed -i '/nezha-agent/d' /etc/sudoers && sleep 30s && killall -u nezha-agent && userdel -r nezha-agent
|
||||
echo -e "${red}Info: ${plain}user nezha-agent has been deleted, Be sure to check it manually!\n"
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "Libselinux will not be installed"
|
||||
[nN][oO] | [nN])
|
||||
echo "Libselinux will not be installed"
|
||||
;;
|
||||
*)
|
||||
echo "Libselinux will not be installed"
|
||||
exit 0
|
||||
*)
|
||||
echo "Libselinux will not be installed"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
install_soft() {
|
||||
(command -v yum >/dev/null 2>&1 && yum makecache && yum install $* selinux-policy -y) ||
|
||||
(command -v apt >/dev/null 2>&1 && apt update && apt install $* selinux-utils -y) ||
|
||||
(command -v pacman >/dev/null 2>&1 && pacman -Syu $* base-devel --noconfirm && install_arch) ||
|
||||
(command -v apt-get >/dev/null 2>&1 && apt-get update && apt-get install $* selinux-utils -y) ||
|
||||
(command -v apk >/dev/null 2>&1 && apk update && apk add $* -f)
|
||||
(command -v apt >/dev/null 2>&1 && apt update && apt install $* selinux-utils -y) ||
|
||||
(command -v pacman >/dev/null 2>&1 && pacman -Syu $* base-devel --noconfirm && install_arch) ||
|
||||
(command -v apt-get >/dev/null 2>&1 && apt-get update && apt-get install $* selinux-utils -y) ||
|
||||
(command -v apk >/dev/null 2>&1 && apk update && apk add $* -f)
|
||||
}
|
||||
|
||||
install_dashboard() {
|
||||
@@ -162,22 +184,22 @@ install_dashboard() {
|
||||
echo -e "> Install Panel"
|
||||
|
||||
# Nezha Monitoring Folder
|
||||
if [ ! -d "${NZ_DASHBOARD_PATH}" ]; then
|
||||
if [ ! -d "${NZ_DASHBOARD_PATH}/docker-compose.yaml" ]; then
|
||||
mkdir -p $NZ_DASHBOARD_PATH
|
||||
else
|
||||
echo "You may have already installed the dashboard, repeated installation will overwrite the data, please pay attention to backup."
|
||||
read -e -r -p "Exit the installation? [Y/n] " input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "Exit the installation."
|
||||
exit 0
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "Exit the installation."
|
||||
exit 0
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "Continue."
|
||||
[nN][oO] | [nN])
|
||||
echo "Continue."
|
||||
;;
|
||||
*)
|
||||
echo "Exit the installation."
|
||||
exit 0
|
||||
*)
|
||||
echo "Exit the installation."
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
@@ -203,11 +225,51 @@ install_dashboard() {
|
||||
fi
|
||||
}
|
||||
|
||||
selinux(){
|
||||
install_dashboard_standalone() {
|
||||
install_base
|
||||
|
||||
echo -e "> Install Panel"
|
||||
|
||||
# Nezha Monitoring Folder
|
||||
if [ ! -d "${NZ_DASHBOARD_PATH}/app" ]; then
|
||||
mkdir -p $NZ_DASHBOARD_PATH
|
||||
else
|
||||
echo "You may have already installed the dashboard, repeated installation will overwrite the data, please pay attention to backup."
|
||||
read -e -r -p "Exit the installation? [Y/n] " input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "Exit the installation."
|
||||
exit 0
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "Continue."
|
||||
;;
|
||||
*)
|
||||
echo "Exit the installation."
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ ! -d "${NZ_DASHBOARD_PATH}/resource/template/theme-custom" ] || [ ! -d "${NZ_DASHBOARD_PATH}/resource/static/custom" ]; then
|
||||
mkdir -p "${NZ_DASHBOARD_PATH}/resource/template/theme-custom" "${NZ_DASHBOARD_PATH}/resource/static/custom" >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
chmod 777 -R $NZ_DASHBOARD_PATH
|
||||
|
||||
modify_dashboard_config_standalone 0
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
selinux() {
|
||||
#Check SELinux
|
||||
if [ "$os_alpine" != 1 ];then
|
||||
command -v getenforce >/dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
getenforce | grep '[Ee]nfor'
|
||||
if [ $? -eq 0 ];then
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "SELinux running,closing now!"
|
||||
setenforce 0 &>/dev/null
|
||||
find_key="SELINUX="
|
||||
@@ -251,8 +313,8 @@ install_agent() {
|
||||
fi
|
||||
|
||||
unzip -qo nezha-agent_linux_${os_arch}.zip &&
|
||||
mv nezha-agent $NZ_AGENT_PATH &&
|
||||
rm -rf nezha-agent_linux_${os_arch}.zip README.md
|
||||
mv nezha-agent $NZ_AGENT_PATH &&
|
||||
rm -rf nezha-agent_linux_${os_arch}.zip README.md
|
||||
|
||||
if [ $# -ge 3 ]; then
|
||||
modify_agent_config "$@"
|
||||
@@ -268,21 +330,28 @@ install_agent() {
|
||||
modify_agent_config() {
|
||||
echo -e "> Modify Agent Configuration"
|
||||
|
||||
if [ "$os_alpine" != 1 ];then
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
wget -t 2 -T 10 -O $NZ_AGENT_SERVICE https://${GITHUB_RAW_URL}/script/nezha-agent.service >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}Fail to download service, please check if the network can link ${GITHUB_RAW_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
wget -t 2 -T 10 -O $NZ_AGENT_SERVICERC https://${GITHUB_RAW_URL}/script/nezha-agent >/dev/null 2>&1
|
||||
chmod +x $NZ_AGENT_SERVICERC
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}Fail to download service, please check if the network can link ${GITHUB_RAW_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $# -lt 3 ]; then
|
||||
echo "Please add Agent in the admin panel first, record the secret" &&
|
||||
read -ep "Please enter a domain that resolves to the IP where the panel is located (no CDN sets): " nz_grpc_host &&
|
||||
read -ep "Please enter the panel RPC port (default 5555): " nz_grpc_port &&
|
||||
read -ep "Please enter the Agent secret: " nz_client_secret &&
|
||||
read -ep "Do you want to enable SSL/TLS encryption for the gRPC port (--tls)? Press [y] if yes, the default is not required, and users can press Enter to skip if you don't understand: " nz_grpc_proxy
|
||||
grep -qiw 'Y' <<< "${nz_grpc_proxy}" && args='--tls'
|
||||
read -ep "Please enter a domain that resolves to the IP where the panel is located (no CDN sets): " nz_grpc_host &&
|
||||
read -ep "Please enter the panel RPC port (default 5555): " nz_grpc_port &&
|
||||
read -ep "Please enter the Agent secret: " nz_client_secret &&
|
||||
read -ep "Do you want to enable SSL/TLS encryption for the gRPC port (--tls)? Press [y] if yes, the default is not required, and users can press Enter to skip if you don't understand: " nz_grpc_proxy
|
||||
grep -qiw 'Y' <<<"${nz_grpc_proxy}" && args='--tls'
|
||||
if [[ -z "${nz_grpc_host}" || -z "${nz_client_secret}" ]]; then
|
||||
echo -e "${red}All options cannot be empty${plain}"
|
||||
before_show_menu
|
||||
@@ -301,29 +370,32 @@ modify_agent_config() {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$os_alpine" != 1 ];then
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICE}
|
||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICE}
|
||||
sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICE}
|
||||
[ -n "${args}" ] && sed -i "/ExecStart/ s/$/ ${args}/" ${NZ_AGENT_SERVICE}
|
||||
else
|
||||
echo "@reboot ${NZ_AGENT_PATH}/nezha-agent -s ${nz_grpc_host}:${nz_grpc_port} -p ${nz_client_secret} ${args}" >> /etc/crontabs/root
|
||||
crond
|
||||
sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICERC}
|
||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICERC}
|
||||
sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICERC}
|
||||
[ -n "${args}" ] && sed -i "/command_args/ s/\"$/ ${args}\"/" ${NZ_AGENT_SERVICERC}
|
||||
fi
|
||||
|
||||
echo -e "Agent configuration ${green} modified successfully, please wait for agent self-restart to take effect${plain}"
|
||||
|
||||
if [ "$os_alpine" != 1 ];then
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl daemon-reload
|
||||
systemctl enable nezha-agent
|
||||
systemctl restart nezha-agent
|
||||
else
|
||||
nohup ${NZ_AGENT_PATH}/nezha-agent -s ${nz_grpc_host}:${nz_grpc_port} -p ${nz_client_secret} ${args} >/dev/null 2>&1 &
|
||||
rc-update add nezha-agent
|
||||
rc-service nezha-agent restart
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
#if [[ $# == 0 ]]; then
|
||||
# before_show_menu
|
||||
#fi
|
||||
}
|
||||
|
||||
modify_dashboard_config() {
|
||||
@@ -343,14 +415,14 @@ modify_dashboard_config() {
|
||||
fi
|
||||
|
||||
echo "About the GitHub Oauth2 application: create it at https://github.com/settings/developers, no review required, and fill in the http(s)://domain_or_IP/oauth2/callback" &&
|
||||
echo "(Not recommended) About the Gitee Oauth2 application: create it at https://gitee.com/oauth/applications, no auditing required, and fill in the http(s)://domain_or_IP/oauth2/callback" &&
|
||||
read -ep "Please enter the OAuth2 provider (github/gitlab/jihulab/gitee, default github): " nz_oauth2_type &&
|
||||
read -ep "Please enter the Client ID of the Oauth2 application: " nz_github_oauth_client_id &&
|
||||
read -ep "Please enter the Client Secret of the Oauth2 application: " nz_github_oauth_client_secret &&
|
||||
read -ep "Please enter your GitHub/Gitee login name as the administrator, separated by commas: " nz_admin_logins &&
|
||||
read -ep "Please enter the site title: " nz_site_title &&
|
||||
read -ep "Please enter the site access port: (default 8008)" nz_site_port &&
|
||||
read -ep "Please enter the RPC port to be used for Agent access: (default 5555)" nz_grpc_port
|
||||
echo "(Not recommended) About the Gitee Oauth2 application: create it at https://gitee.com/oauth/applications, no auditing required, and fill in the http(s)://domain_or_IP/oauth2/callback" &&
|
||||
read -ep "Please enter the OAuth2 provider (github/gitlab/jihulab/gitee, default github): " nz_oauth2_type &&
|
||||
read -ep "Please enter the Client ID of the Oauth2 application: " nz_github_oauth_client_id &&
|
||||
read -ep "Please enter the Client Secret of the Oauth2 application: " nz_github_oauth_client_secret &&
|
||||
read -ep "Please enter your GitHub/Gitee login name as the administrator, separated by commas: " nz_admin_logins &&
|
||||
read -ep "Please enter the site title: " nz_site_title &&
|
||||
read -ep "Please enter the site access port: (default 8008)" nz_site_port &&
|
||||
read -ep "Please enter the RPC port to be used for Agent access: (default 5555)" nz_grpc_port
|
||||
|
||||
if [[ -z "${nz_admin_logins}" || -z "${nz_github_oauth_client_id}" || -z "${nz_github_oauth_client_secret}" || -z "${nz_site_title}" ]]; then
|
||||
echo -e "${red}All options cannot be empty${plain}"
|
||||
@@ -392,6 +464,77 @@ modify_dashboard_config() {
|
||||
fi
|
||||
}
|
||||
|
||||
modify_dashboard_config_standalone() {
|
||||
echo -e "> Modify Panel Configuration"
|
||||
|
||||
echo -e "Download configuration template"
|
||||
|
||||
wget -t 2 -T 10 -O /tmp/nezha-config.yaml https://${GITHUB_RAW_URL}/script/config.yaml >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}File failed to get, please check if the network can link ${GITHUB_RAW_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "About the GitHub Oauth2 application: create it at https://github.com/settings/developers, no review required, and fill in the http(s)://domain_or_IP/oauth2/callback" &&
|
||||
echo "(Not recommended) About the Gitee Oauth2 application: create it at https://gitee.com/oauth/applications, no auditing required, and fill in the http(s)://domain_or_IP/oauth2/callback" &&
|
||||
read -ep "Please enter the OAuth2 provider (github/gitlab/jihulab/gitee, default github): " nz_oauth2_type &&
|
||||
read -ep "Please enter the Client ID of the Oauth2 application: " nz_github_oauth_client_id &&
|
||||
read -ep "Please enter the Client Secret of the Oauth2 application: " nz_github_oauth_client_secret &&
|
||||
read -ep "Please enter your GitHub/Gitee login name as the administrator, separated by commas: " nz_admin_logins &&
|
||||
read -ep "Please enter the site title: " nz_site_title &&
|
||||
read -ep "Please enter the site access port: (default 8008)" nz_site_port &&
|
||||
read -ep "Please enter the RPC port to be used for Agent access: (default 5555)" nz_grpc_port
|
||||
|
||||
if [[ -z "${nz_admin_logins}" || -z "${nz_github_oauth_client_id}" || -z "${nz_github_oauth_client_secret}" || -z "${nz_site_title}" ]]; then
|
||||
echo -e "${red}All options cannot be empty${plain}"
|
||||
before_show_menu
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -z "${nz_site_port}" ]]; then
|
||||
nz_site_port=8008
|
||||
fi
|
||||
if [[ -z "${nz_grpc_port}" ]]; then
|
||||
nz_grpc_port=5555
|
||||
fi
|
||||
if [[ -z "${nz_oauth2_type}" ]]; then
|
||||
nz_oauth2_type=github
|
||||
fi
|
||||
|
||||
sed -i "s/nz_oauth2_type/${nz_oauth2_type}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_admin_logins/${nz_admin_logins}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_github_oauth_client_id/${nz_github_oauth_client_id}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_github_oauth_client_secret/${nz_github_oauth_client_secret}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_language/zh-CN/" /tmp/nezha-config.yaml
|
||||
sed -i "s/nz_site_title/${nz_site_title}/" /tmp/nezha-config.yaml
|
||||
sed -i "s/80/${nz_site_port}/" /tmp/nezha-config.yaml
|
||||
|
||||
mkdir -p $NZ_DASHBOARD_PATH/data
|
||||
mv -f /tmp/nezha-config.yaml ${NZ_DASHBOARD_PATH}/data/config.yaml
|
||||
|
||||
echo -e "Downloading service file"
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
wget -t 2 -T 10 -O $NZ_DASHBOARD_SERVICE https://${GITHUB_RAW_URL}/script/nezha-dashboard.service >/dev/null 2>&1
|
||||
else
|
||||
wget -t 2 -T 10 -O $NZ_DASHBOARD_SERVICERC https://${GITHUB_RAW_URL}/script/nezha-dashboard >/dev/null 2>&1
|
||||
chmod +x $NZ_DASHBOARD_SERVICERC
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}File failed to get, please check if the network can link ${GITHUB_RAW_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "Dashboard configuration ${green} modified successfully, please wait for Dashboard self-restart to take effect${plain}"
|
||||
|
||||
restart_and_update_standalone
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
restart_and_update() {
|
||||
echo -e "> Restart and Update the Panel"
|
||||
|
||||
@@ -420,6 +563,40 @@ restart_and_update() {
|
||||
fi
|
||||
}
|
||||
|
||||
restart_and_update_standalone() {
|
||||
echo -e "> Restart and Update the Panel"
|
||||
|
||||
cd $NZ_DASHBOARD_PATH
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl stop nezha-dashboard
|
||||
else
|
||||
rc-service nezha-dashboard stop
|
||||
fi
|
||||
|
||||
wget -qO app.zip https://${GITHUB_URL}/naiba/nezha/releases/latest/download/dashboard-linux-$os_arch.zip >/dev/null 2>&1 && unzip -qq app.zip && mv dist/dashboard-linux-$os_arch app && rm -r app.zip dist
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl daemon-reload
|
||||
systemctl enable nezha-dashboard
|
||||
systemctl restart nezha-dashboard
|
||||
else
|
||||
rc-update add nezha-dashboard
|
||||
rc-service nezha-dashboard restart
|
||||
fi
|
||||
|
||||
if [[ $? == 0 ]]; then
|
||||
echo -e "${green}Nezha Monitoring Restart Successful${plain}"
|
||||
echo -e "Default panel address: ${yellow}domain:Site_access_port${plain}"
|
||||
else
|
||||
echo -e "${red}The restart failed, probably because the boot time exceeded two seconds, please check the log information later${plain}"
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
start_dashboard() {
|
||||
echo -e "> Start Panel"
|
||||
|
||||
@@ -441,6 +618,26 @@ start_dashboard() {
|
||||
fi
|
||||
}
|
||||
|
||||
start_dashboard_standalone() {
|
||||
echo -e "> Start Panel"
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl start nezha-dashboard
|
||||
else
|
||||
rc-service nezha-dashboard start
|
||||
fi
|
||||
|
||||
if [[ $? == 0 ]]; then
|
||||
echo -e "${green}Nezha Monitoring Start Successful${plain}"
|
||||
else
|
||||
echo -e "${red}Failed to start, please check the log message later${plain}"
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
stop_dashboard() {
|
||||
echo -e "> Stop Panel"
|
||||
|
||||
@@ -462,6 +659,26 @@ stop_dashboard() {
|
||||
fi
|
||||
}
|
||||
|
||||
stop_dashboard_standalone() {
|
||||
echo -e "> Stop Panel"
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl stop nezha-dashboard
|
||||
else
|
||||
rc-service nezha-dashboard stop
|
||||
fi
|
||||
|
||||
if [[ $? == 0 ]]; then
|
||||
echo -e "${green}Nezha Monitoring Stop Successful${plain}"
|
||||
else
|
||||
echo -e "${red}Failed to stop, please check the log message later${plain}"
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
show_dashboard_log() {
|
||||
echo -e "> View Panel Log"
|
||||
|
||||
@@ -477,6 +694,20 @@ show_dashboard_log() {
|
||||
fi
|
||||
}
|
||||
|
||||
show_dashboard_log_standalone() {
|
||||
echo -e "> View Panel Log"
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
journalctl -xf -u nezha-dashboard.service
|
||||
else
|
||||
echo "Sorry, OpenRC do not have this feature yet."
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
uninstall_dashboard() {
|
||||
echo -e "> Uninstall Panel"
|
||||
|
||||
@@ -488,7 +719,32 @@ uninstall_dashboard() {
|
||||
fi
|
||||
|
||||
rm -rf $NZ_DASHBOARD_PATH
|
||||
docker rmi -f ghcr.io/naiba/nezha-dashboard > /dev/null 2>&1
|
||||
docker rmi -f ghcr.io/naiba/nezha-dashboard >/dev/null 2>&1
|
||||
docker rmi -f registry.cn-shanghai.aliyuncs.com/naibahq/nezha-dashboard >/dev/null 2>&1
|
||||
clean_all
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
uninstall_dashboard_standalone() {
|
||||
echo -e "> Uninstall Panel"
|
||||
|
||||
rm -rf $NZ_DASHBOARD_PATH
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl stop nezha-dashboard
|
||||
else
|
||||
rc-service nezha-dashboard stop
|
||||
fi
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
rm $NZ_DASHBOARD_SERVICE
|
||||
else
|
||||
rm $NZ_DASHBOARD_SERVICERC
|
||||
fi
|
||||
|
||||
clean_all
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
@@ -497,9 +753,13 @@ uninstall_dashboard() {
|
||||
}
|
||||
|
||||
show_agent_log() {
|
||||
echo -e "> View Agent Log"
|
||||
echo -e "> > View Agent Log"
|
||||
|
||||
journalctl -xf -u nezha-agent.service
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
journalctl -xf -u nezha-agent.service
|
||||
else
|
||||
echo "Sorry, OpenRC do not have this feature yet."
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
@@ -509,14 +769,15 @@ show_agent_log() {
|
||||
uninstall_agent() {
|
||||
echo -e "> Uninstall Agent"
|
||||
|
||||
if [ "$os_alpine" != 1 ];then
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl disable nezha-agent.service
|
||||
systemctl stop nezha-agent.service
|
||||
rm -rf $NZ_AGENT_SERVICE
|
||||
systemctl daemon-reload
|
||||
else
|
||||
grep -q 'nezha-agent' /var/spool/cron/crontabs/root && sed -i "/nezha-agent/d" /var/spool/cron/crontabs/root
|
||||
pkill nezha-agent
|
||||
rc-update del nezha-agent
|
||||
rc-service nezha-agent stop
|
||||
rm -rf $NZ_AGENT_SERVICERC
|
||||
fi
|
||||
|
||||
rm -rf $NZ_AGENT_PATH
|
||||
@@ -530,7 +791,11 @@ uninstall_agent() {
|
||||
restart_agent() {
|
||||
echo -e "> Restart Agent"
|
||||
|
||||
systemctl restart nezha-agent.service
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
systemctl restart nezha-agent.service
|
||||
else
|
||||
rc-service nezha-agent restart
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
@@ -543,6 +808,59 @@ clean_all() {
|
||||
fi
|
||||
}
|
||||
|
||||
select_version() {
|
||||
DOCKER_COMPOSE_COMMAND=""
|
||||
if docker compose version >/dev/null 2>&1; then
|
||||
DOCKER_COMPOSE_COMMAND="docker compose"
|
||||
if $DOCKER_COMPOSE_COMMAND ls | grep -qw "$NZ_DASHBOARD_PATH/docker-compose.yaml" >/dev/null 2>&1; then
|
||||
NEZHA_IMAGES=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep -w "nezha-dashboard")
|
||||
if [ -n "$NEZHA_IMAGES" ]; then
|
||||
echo "Docker image with nezha-dashboard repository exists:"
|
||||
echo "$NEZHA_IMAGES"
|
||||
IS_DOCKER_NEZHA=1
|
||||
return
|
||||
else
|
||||
echo "No Docker images with the nezha-dashboard repository were found."
|
||||
fi
|
||||
fi
|
||||
elif command -v docker-compose >/dev/null 2>&1; then
|
||||
DOCKER_COMPOSE_COMMAND="docker-compose"
|
||||
if $DOCKER_COMPOSE_COMMAND -f "$NZ_DASHBOARD_PATH/docker-compose.yaml" config >/dev/null 2>&1; then
|
||||
NEZHA_IMAGES=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep -w "nezha-dashboard")
|
||||
if [ -n "$NEZHA_IMAGES" ]; then
|
||||
echo "Docker image with nezha-dashboard repository exists:"
|
||||
echo "$NEZHA_IMAGES"
|
||||
IS_DOCKER_NEZHA=1
|
||||
return
|
||||
else
|
||||
echo "No Docker images with the nezha-dashboard repository were found."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -f $NZ_DASHBOARD_PATH/app ]]; then
|
||||
IS_DOCKER_NEZHA=0
|
||||
else
|
||||
echo -e "${yellow}Select your installation method(Input anything is ok if you are installing agent):\n1. Docker\n2. Standalone${plain}"
|
||||
while true; do
|
||||
read -e -r -p "Input a number [1-2]: " option
|
||||
case "${option}" in
|
||||
1)
|
||||
IS_DOCKER_NEZHA=1
|
||||
break
|
||||
;;
|
||||
2)
|
||||
IS_DOCKER_NEZHA=0
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Wrong input, try again"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
show_usage() {
|
||||
echo "Nezha Monitor Management Script Usage: "
|
||||
echo "--------------------------------------------------------"
|
||||
@@ -587,81 +905,131 @@ show_menu() {
|
||||
${green}0.${plain} Exit Script
|
||||
"
|
||||
echo && read -ep "Please enter [0-13]: " num
|
||||
|
||||
case "${num}" in
|
||||
if [[ $IS_DOCKER_NEZHA == 1 ]]; then
|
||||
case "${num}" in
|
||||
0)
|
||||
exit 0
|
||||
;;
|
||||
;;
|
||||
1)
|
||||
install_dashboard
|
||||
;;
|
||||
;;
|
||||
2)
|
||||
modify_dashboard_config
|
||||
;;
|
||||
;;
|
||||
3)
|
||||
start_dashboard
|
||||
;;
|
||||
;;
|
||||
4)
|
||||
stop_dashboard
|
||||
;;
|
||||
;;
|
||||
5)
|
||||
restart_and_update
|
||||
;;
|
||||
;;
|
||||
6)
|
||||
show_dashboard_log
|
||||
;;
|
||||
;;
|
||||
7)
|
||||
uninstall_dashboard
|
||||
;;
|
||||
;;
|
||||
8)
|
||||
install_agent
|
||||
;;
|
||||
;;
|
||||
9)
|
||||
modify_agent_config
|
||||
;;
|
||||
;;
|
||||
10)
|
||||
show_agent_log
|
||||
;;
|
||||
;;
|
||||
11)
|
||||
uninstall_agent
|
||||
;;
|
||||
;;
|
||||
12)
|
||||
restart_agent
|
||||
;;
|
||||
;;
|
||||
13)
|
||||
update_script
|
||||
;;
|
||||
;;
|
||||
*)
|
||||
echo -e "${red}Please enter the correct number [0-13]${plain}"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
elif [[ $IS_DOCKER_NEZHA == 0 ]]; then
|
||||
case "${num}" in
|
||||
0)
|
||||
exit 0
|
||||
;;
|
||||
1)
|
||||
install_dashboard_standalone
|
||||
;;
|
||||
2)
|
||||
modify_dashboard_config_standalone
|
||||
;;
|
||||
3)
|
||||
start_dashboard_standalone
|
||||
;;
|
||||
4)
|
||||
stop_dashboard_standalone
|
||||
;;
|
||||
5)
|
||||
restart_and_update_standalone
|
||||
;;
|
||||
6)
|
||||
show_dashboard_log_standalone
|
||||
;;
|
||||
7)
|
||||
uninstall_dashboard_standalone
|
||||
;;
|
||||
8)
|
||||
install_agent
|
||||
;;
|
||||
9)
|
||||
modify_agent_config
|
||||
;;
|
||||
10)
|
||||
show_agent_log
|
||||
;;
|
||||
11)
|
||||
uninstall_agent
|
||||
;;
|
||||
12)
|
||||
restart_agent
|
||||
;;
|
||||
13)
|
||||
update_script
|
||||
;;
|
||||
*)
|
||||
echo -e "${red}Please enter the correct number [0-13]${plain}"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
pre_check
|
||||
|
||||
if [[ $# > 0 ]]; then
|
||||
case $1 in
|
||||
if [[ $IS_DOCKER_NEZHA == 1 ]]; then
|
||||
case $1 in
|
||||
"install_dashboard")
|
||||
install_dashboard 0
|
||||
;;
|
||||
;;
|
||||
"modify_dashboard_config")
|
||||
modify_dashboard_config 0
|
||||
;;
|
||||
;;
|
||||
"start_dashboard")
|
||||
start_dashboard 0
|
||||
;;
|
||||
;;
|
||||
"stop_dashboard")
|
||||
stop_dashboard 0
|
||||
;;
|
||||
;;
|
||||
"restart_and_update")
|
||||
restart_and_update 0
|
||||
;;
|
||||
;;
|
||||
"show_dashboard_log")
|
||||
show_dashboard_log 0
|
||||
;;
|
||||
;;
|
||||
"uninstall_dashboard")
|
||||
uninstall_dashboard 0
|
||||
;;
|
||||
;;
|
||||
"install_agent")
|
||||
shift
|
||||
if [ $# -ge 3 ]; then
|
||||
@@ -669,24 +1037,101 @@ if [[ $# > 0 ]]; then
|
||||
else
|
||||
install_agent 0
|
||||
fi
|
||||
;;
|
||||
;;
|
||||
"modify_agent_config")
|
||||
modify_agent_config 0
|
||||
;;
|
||||
;;
|
||||
"show_agent_log")
|
||||
show_agent_log 0
|
||||
;;
|
||||
;;
|
||||
"uninstall_agent")
|
||||
uninstall_agent 0
|
||||
;;
|
||||
;;
|
||||
"restart_agent")
|
||||
restart_agent 0
|
||||
;;
|
||||
;;
|
||||
"update_script")
|
||||
update_script 0
|
||||
;;
|
||||
;;
|
||||
*) show_usage ;;
|
||||
esac
|
||||
esac
|
||||
elif [[ $IS_DOCKER_NEZHA == 0 ]]; then
|
||||
case $1 in
|
||||
"install_dashboard")
|
||||
install_dashboard_standalone 0
|
||||
;;
|
||||
"modify_dashboard_config")
|
||||
modify_dashboard_config_standalone 0
|
||||
;;
|
||||
"start_dashboard")
|
||||
start_dashboard_standalone 0
|
||||
;;
|
||||
"stop_dashboard")
|
||||
stop_dashboard_standalone 0
|
||||
;;
|
||||
"restart_and_update")
|
||||
restart_and_update_standalone 0
|
||||
;;
|
||||
"show_dashboard_log")
|
||||
show_dashboard_log_standalone 0
|
||||
;;
|
||||
"uninstall_dashboard")
|
||||
uninstall_dashboard_standalone 0
|
||||
;;
|
||||
"install_agent")
|
||||
shift
|
||||
if [ $# -ge 3 ]; then
|
||||
install_agent "$@"
|
||||
else
|
||||
install_agent 0
|
||||
fi
|
||||
;;
|
||||
"modify_agent_config")
|
||||
modify_agent_config 0
|
||||
;;
|
||||
"show_agent_log")
|
||||
show_agent_log 0
|
||||
;;
|
||||
"uninstall_agent")
|
||||
uninstall_agent 0
|
||||
;;
|
||||
"restart_agent")
|
||||
restart_agent 0
|
||||
;;
|
||||
"update_script")
|
||||
update_script 0
|
||||
;;
|
||||
*) show_usage ;;
|
||||
esac
|
||||
else
|
||||
case $1 in
|
||||
"install_agent")
|
||||
shift
|
||||
if [ $# -ge 3 ]; then
|
||||
install_agent "$@"
|
||||
else
|
||||
install_agent 0
|
||||
fi
|
||||
;;
|
||||
"modify_agent_config")
|
||||
modify_agent_config 0
|
||||
;;
|
||||
"show_agent_log")
|
||||
show_agent_log 0
|
||||
;;
|
||||
"uninstall_agent")
|
||||
uninstall_agent 0
|
||||
;;
|
||||
"restart_agent")
|
||||
restart_agent 0
|
||||
;;
|
||||
"update_script")
|
||||
update_script 0
|
||||
;;
|
||||
*) show_usage ;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
select_version
|
||||
show_menu
|
||||
fi
|
||||
fi
|
||||
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/sbin/openrc-run
|
||||
supervisor=supervise-daemon
|
||||
name=nezha-agent
|
||||
supervise_daemon_args="--stdout /var/log/${name}.log --stderr /var/log/${name}.err"
|
||||
SERVER="nz_grpc_host:nz_grpc_port" #Dashboard 地址 ip:port
|
||||
SECRET="nz_client_secret" #SECRET
|
||||
NZ_BASE_PATH="/opt/nezha"
|
||||
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
||||
pidfile="/run/${RC_SVCNAME}.pid"
|
||||
command="/opt/nezha/agent/nezha-agent"
|
||||
command_args="-s ${SERVER} -p ${SECRET}"
|
||||
command_background=true
|
||||
depend() {
|
||||
need net
|
||||
}
|
||||
checkconfig() {
|
||||
GITHUB_URL="github.com"
|
||||
if [ ! -f "${NZ_AGENT_PATH}/nezha-agent" ]; then
|
||||
if [[ $(uname -m | grep 'x86_64') != "" ]]; then
|
||||
os_arch="amd64"
|
||||
elif [[ $(uname -m | grep 'i386\|i686') != "" ]]; then
|
||||
os_arch="386"
|
||||
elif [[ $(uname -m | grep 'aarch64\|armv8b\|armv8l') != "" ]]; then
|
||||
os_arch="arm64"
|
||||
elif [[ $(uname -m | grep 'arm') != "" ]]; then
|
||||
os_arch="arm"
|
||||
elif [[ $(uname -m | grep 's390x') != "" ]]; then
|
||||
os_arch="s390x"
|
||||
elif [[ $(uname -m | grep 'riscv64') != "" ]]; then
|
||||
os_arch="riscv64"
|
||||
fi
|
||||
local version=$(curl -m 10 -sL "https://api.github.com/repos/nezhahq/agent/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
|
||||
if [ ! -n "$version" ]; then
|
||||
version=$(curl -m 10 -sL "https://fastly.jsdelivr.net/gh/nezhahq/agent/" | grep "option\.value" | awk -F "'" '{print $2}' | sed 's/nezhahq\/agent@/v/g')
|
||||
fi
|
||||
if [ ! -n "$version" ]; then
|
||||
version=$(curl -m 10 -sL "https://gcore.jsdelivr.net/gh/nezhahq/agent/" | grep "option\.value" | awk -F "'" '{print $2}' | sed 's/nezhahq\/agent@/v/g')
|
||||
fi
|
||||
if [ ! -n "$version" ]; then
|
||||
echo -e "获取版本号失败,请检查本机能否链接 https://api.github.com/repos/nezhahq/agent/releases/latest"
|
||||
return 0
|
||||
else
|
||||
echo -e "当前最新版本为: ${version}"
|
||||
fi
|
||||
wget -t 2 -T 10 -O nezha-agent_linux_${os_arch}.zip https://${GITHUB_URL}/nezhahq/agent/releases/download/${version}/nezha-agent_linux_${os_arch}.zip >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "Release 下载失败,请检查本机能否连接 ${GITHUB_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
mkdir -p $NZ_AGENT_PATH
|
||||
chmod 755 -R $NZ_AGENT_PATH
|
||||
unzip -qo nezha-agent_linux_${os_arch}.zip && mv nezha-agent $NZ_AGENT_PATH && rm -rf nezha-agent_linux_${os_arch}.zip README.md
|
||||
fi
|
||||
if [ ! -x "${NZ_AGENT_PATH}/nezha-agent" ]; then
|
||||
chmod +x ${NZ_AGENT_PATH}/nezha-agent
|
||||
fi
|
||||
}
|
||||
start_pre() {
|
||||
if [ "${RC_CMD}" != "restart" ]; then
|
||||
checkconfig || return $?
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/sbin/openrc-run
|
||||
pidfile="/run/${RC_SVCNAME}.pid"
|
||||
command="/opt/nezha/dashboard/app"
|
||||
command_args=""
|
||||
command_background=true
|
||||
directory="/opt/nezha/dashboard"
|
||||
|
||||
depend() {
|
||||
need net
|
||||
}
|
||||
|
||||
reload() {
|
||||
ebegin "Reloading ${RC_SVCNAME}"
|
||||
start-stop-daemon --signal HUP --pidfile "${pidfile}"
|
||||
eend $?
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description=Nezha Dashborad
|
||||
Description=Nezha Dashboard
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
After=mariadb.service mysqld.service postgresql.service memcached.service redis.service
|
||||
@@ -14,8 +14,8 @@ After=mariadb.service mysqld.service postgresql.service memcached.service redis.
|
||||
Type=simple
|
||||
#User=root
|
||||
#Group=root
|
||||
WorkingDirectory=/root/nezha/dashboard/
|
||||
ExecStart=/root/nezha/dashboard/nezha-dashboard-linux-amd64
|
||||
WorkingDirectory=/opt/nezha/dashboard/
|
||||
ExecStart=/opt/nezha/dashboard/app
|
||||
Restart=always
|
||||
#Environment=DEBUG=true
|
||||
|
||||
@@ -27,4 +27,4 @@ PrivateTmp=yes
|
||||
NoNewPrivileges=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
WantedBy=multi-user.target
|
||||
|
||||
@@ -3,6 +3,8 @@ package rpc
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
@@ -110,6 +112,36 @@ func (s *NezhaHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rece
|
||||
host := model.PB2Host(r)
|
||||
singleton.ServerLock.RLock()
|
||||
defer singleton.ServerLock.RUnlock()
|
||||
|
||||
// 检查并更新DDNS
|
||||
if singleton.Conf.DDNS.Enable &&
|
||||
singleton.ServerList[clientID].EnableDDNS &&
|
||||
singleton.ServerList[clientID].Host != nil &&
|
||||
host.IP != "" &&
|
||||
singleton.ServerList[clientID].Host.IP != host.IP {
|
||||
|
||||
serverDomain := singleton.ServerList[clientID].DDNSDomain
|
||||
provider, err := singleton.GetDDNSProviderFromString(singleton.Conf.DDNS.Provider)
|
||||
if err == nil && serverDomain != "" {
|
||||
ipv4, ipv6, _ := utils.SplitIPAddr(host.IP)
|
||||
maxRetries := int(singleton.Conf.DDNS.MaxRetries)
|
||||
config := &singleton.DDNSDomainConfig{
|
||||
EnableIPv4: true,
|
||||
EnableIpv6: true,
|
||||
FullDomain: serverDomain,
|
||||
Ipv4Addr: ipv4,
|
||||
Ipv6Addr: ipv6,
|
||||
}
|
||||
go singleton.RetryableUpdateDomain(provider, config, maxRetries)
|
||||
|
||||
} else {
|
||||
// 虽然会在启动时panic, 可以断言不会走这个分支, 但是考虑到动态加载配置或者其它情况, 这里输出一下方便检查奇奇怪怪的BUG
|
||||
log.Printf("NEZHA>> 未找到对应的DDNS提供者(%s), 请前往config.yml检查你的设置\n", singleton.Conf.DDNS.Provider)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 发送IP变动通知
|
||||
if singleton.Conf.EnableIPChangeNotification &&
|
||||
((singleton.Conf.Cover == model.ConfigCoverAll && !singleton.Conf.IgnoredIPNotificationServerIDs[clientID]) ||
|
||||
(singleton.Conf.Cover == model.ConfigCoverIgnoreAll && singleton.Conf.IgnoredIPNotificationServerIDs[clientID])) &&
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package singleton
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -11,7 +13,10 @@ var (
|
||||
UserIDToApiTokenList = make(map[uint64][]string)
|
||||
ApiLock sync.RWMutex
|
||||
|
||||
ServerAPI = &ServerAPIService{}
|
||||
ServerAPI = &ServerAPIService{}
|
||||
MonitorAPI = &MonitorAPIService{}
|
||||
|
||||
once = &sync.Once{}
|
||||
)
|
||||
|
||||
type ServerAPIService struct{}
|
||||
@@ -51,6 +56,23 @@ type ServerInfoResponse struct {
|
||||
Result []*CommonServerInfo `json:"result"`
|
||||
}
|
||||
|
||||
type MonitorAPIService struct {
|
||||
}
|
||||
|
||||
type MonitorInfoResponse struct {
|
||||
CommonResponse
|
||||
Result []*MonitorInfo `json:"result"`
|
||||
}
|
||||
|
||||
type MonitorInfo struct {
|
||||
MonitorID uint64 `json:"monitor_id"`
|
||||
ServerID uint64 `json:"server_id"`
|
||||
MonitorName string `json:"monitor_name"`
|
||||
ServerName string `json:"server_name"`
|
||||
CreatedAt []int64 `json:"created_at"`
|
||||
AvgDelay []float32 `json:"avg_delay"`
|
||||
}
|
||||
|
||||
func InitAPI() {
|
||||
ApiTokenList = make(map[string]*model.ApiToken)
|
||||
UserIDToApiTokenList = make(map[uint64][]string)
|
||||
@@ -203,3 +225,45 @@ func (s *ServerAPIService) GetAllList() *ServerInfoResponse {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (m *MonitorAPIService) GetMonitorHistories(query map[string]any) *MonitorInfoResponse {
|
||||
var (
|
||||
resultMap = make(map[uint64]*MonitorInfo)
|
||||
monitorHistories []*model.MonitorHistory
|
||||
sortedMonitorIDs []uint64
|
||||
)
|
||||
res := &MonitorInfoResponse{
|
||||
CommonResponse: CommonResponse{
|
||||
Code: 0,
|
||||
Message: "success",
|
||||
},
|
||||
}
|
||||
if err := DB.Model(&model.MonitorHistory{}).Select("monitor_id, created_at, server_id, avg_delay").
|
||||
Where(query).Where("created_at >= ?", time.Now().Add(-24*time.Hour)).Order("monitor_id, created_at").
|
||||
Scan(&monitorHistories).Error; err != nil {
|
||||
res.CommonResponse = CommonResponse{
|
||||
Code: 500,
|
||||
Message: err.Error(),
|
||||
}
|
||||
} else {
|
||||
for _, history := range monitorHistories {
|
||||
infos, ok := resultMap[history.MonitorID]
|
||||
if !ok {
|
||||
infos = &MonitorInfo{
|
||||
MonitorID: history.MonitorID,
|
||||
ServerID: history.ServerID,
|
||||
MonitorName: ServiceSentinelShared.monitors[history.MonitorID].Name,
|
||||
ServerName: ServerList[history.ServerID].Name,
|
||||
}
|
||||
resultMap[history.MonitorID] = infos
|
||||
sortedMonitorIDs = append(sortedMonitorIDs, history.MonitorID)
|
||||
}
|
||||
infos.CreatedAt = append(infos.CreatedAt, history.CreatedAt.Truncate(time.Minute).Unix()*1000)
|
||||
infos.AvgDelay = append(infos.AvgDelay, history.AvgDelay)
|
||||
}
|
||||
for _, monitorID := range sortedMonitorIDs {
|
||||
res.Result = append(res.Result, resultMap[monitorID])
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -0,0 +1,302 @@
|
||||
package singleton
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DDNSDomainConfig struct {
|
||||
EnableIPv4 bool
|
||||
EnableIpv6 bool
|
||||
FullDomain string
|
||||
Ipv4Addr string
|
||||
Ipv6Addr string
|
||||
}
|
||||
|
||||
type DDNSProvider interface {
|
||||
// UpdateDomain Return is updated
|
||||
UpdateDomain(domainConfig *DDNSDomainConfig) bool
|
||||
}
|
||||
|
||||
type DDNSProviderWebHook struct {
|
||||
URL string
|
||||
RequestMethod string
|
||||
RequestBody string
|
||||
RequestHeader string
|
||||
}
|
||||
|
||||
func (provider DDNSProviderWebHook) UpdateDomain(domainConfig *DDNSDomainConfig) bool {
|
||||
if domainConfig == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if domainConfig.FullDomain == "" {
|
||||
log.Println("NEZHA>> Failed to update an empty domain")
|
||||
return false
|
||||
}
|
||||
updated := false
|
||||
client := &http.Client{}
|
||||
if domainConfig.EnableIPv4 && domainConfig.Ipv4Addr != "" {
|
||||
url := provider.FormatWebhookString(provider.URL, domainConfig, "ipv4")
|
||||
body := provider.FormatWebhookString(provider.RequestBody, domainConfig, "ipv4")
|
||||
header := provider.FormatWebhookString(provider.RequestHeader, domainConfig, "ipv4")
|
||||
headers := strings.Split(header, "\n")
|
||||
req, err := http.NewRequest(provider.RequestMethod, url, bytes.NewBufferString(body))
|
||||
if err == nil && req != nil {
|
||||
SetStringHeadersToRequest(req, headers)
|
||||
if _, err := client.Do(req); err != nil {
|
||||
log.Printf("NEZHA>> Failed to update a domain: %s. Cause by: %s\n", domainConfig.FullDomain, err.Error())
|
||||
}
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
if domainConfig.EnableIpv6 && domainConfig.Ipv6Addr != "" {
|
||||
url := provider.FormatWebhookString(provider.URL, domainConfig, "ipv6")
|
||||
body := provider.FormatWebhookString(provider.RequestBody, domainConfig, "ipv6")
|
||||
header := provider.FormatWebhookString(provider.RequestHeader, domainConfig, "ipv6")
|
||||
headers := strings.Split(header, "\n")
|
||||
req, err := http.NewRequest(provider.RequestMethod, url, bytes.NewBufferString(body))
|
||||
if err == nil && req != nil {
|
||||
SetStringHeadersToRequest(req, headers)
|
||||
if _, err := client.Do(req); err != nil {
|
||||
log.Printf("NEZHA>> Failed to update a domain: %s. Cause by: %s\n", domainConfig.FullDomain, err.Error())
|
||||
}
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
return updated
|
||||
}
|
||||
|
||||
type DDNSProviderDummy struct{}
|
||||
|
||||
func (provider DDNSProviderDummy) UpdateDomain(domainConfig *DDNSDomainConfig) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type DDNSProviderCloudflare struct {
|
||||
Secret string
|
||||
}
|
||||
|
||||
func (provider DDNSProviderCloudflare) UpdateDomain(domainConfig *DDNSDomainConfig) bool {
|
||||
if domainConfig == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
zoneID, err := provider.getZoneID(domainConfig.FullDomain)
|
||||
if err != nil {
|
||||
log.Printf("无法获取 zone ID: %s\n", err)
|
||||
return false
|
||||
}
|
||||
|
||||
record, err := provider.findDNSRecord(zoneID, domainConfig.FullDomain)
|
||||
if err != nil {
|
||||
log.Printf("查找 DNS 记录时出错: %s\n", err)
|
||||
return false
|
||||
}
|
||||
|
||||
if record == nil {
|
||||
// 添加 DNS 记录
|
||||
return provider.createDNSRecord(zoneID, domainConfig)
|
||||
} else {
|
||||
// 更新 DNS 记录
|
||||
return provider.updateDNSRecord(zoneID, record["id"].(string), domainConfig)
|
||||
}
|
||||
}
|
||||
|
||||
func (provider DDNSProviderCloudflare) getZoneID(domain string) (string, error) {
|
||||
_, realDomain := SplitDomain(domain)
|
||||
url := fmt.Sprintf("https://api.cloudflare.com/client/v4/zones?name=%s", realDomain)
|
||||
body, err := provider.sendRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var res map[string]interface{}
|
||||
err = json.Unmarshal(body, &res)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := res["result"].([]interface{})
|
||||
if len(result) > 0 {
|
||||
zoneID := result[0].(map[string]interface{})["id"].(string)
|
||||
return zoneID, nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("找不到 Zone ID")
|
||||
}
|
||||
|
||||
func (provider DDNSProviderCloudflare) findDNSRecord(zoneID string, domain string) (map[string]interface{}, error) {
|
||||
url := fmt.Sprintf("https://api.cloudflare.com/client/v4/zones/%s/dns_records?type=A&name=%s", zoneID, domain)
|
||||
body, err := provider.sendRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var res map[string]interface{}
|
||||
err = json.Unmarshal(body, &res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := res["result"].([]interface{})
|
||||
if len(result) > 0 {
|
||||
return result[0].(map[string]interface{}), nil
|
||||
}
|
||||
|
||||
return nil, nil // 没有找到 DNS 记录
|
||||
}
|
||||
|
||||
func (provider DDNSProviderCloudflare) createDNSRecord(zoneID string, domainConfig *DDNSDomainConfig) bool {
|
||||
url := fmt.Sprintf("https://api.cloudflare.com/client/v4/zones/%s/dns_records", zoneID)
|
||||
data := map[string]interface{}{
|
||||
"type": "A",
|
||||
"name": domainConfig.FullDomain,
|
||||
"content": domainConfig.Ipv4Addr,
|
||||
"ttl": 3600,
|
||||
"proxied": false,
|
||||
}
|
||||
jsonData, _ := json.Marshal(data)
|
||||
_, err := provider.sendRequest("POST", url, jsonData)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (provider DDNSProviderCloudflare) updateDNSRecord(zoneID string, recordID string, domainConfig *DDNSDomainConfig) bool {
|
||||
url := fmt.Sprintf("https://api.cloudflare.com/client/v4/zones/%s/dns_records/%s", zoneID, recordID)
|
||||
data := map[string]interface{}{
|
||||
"type": "A",
|
||||
"name": domainConfig.FullDomain,
|
||||
"content": domainConfig.Ipv4Addr,
|
||||
"ttl": 3600,
|
||||
"proxied": false,
|
||||
}
|
||||
jsonData, _ := json.Marshal(data)
|
||||
_, err := provider.sendRequest("PATCH", url, jsonData)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// 以下为辅助方法,如发送 HTTP 请求等
|
||||
func (provider DDNSProviderCloudflare) sendRequest(method string, url string, data []byte) ([]byte, error) {
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest(method, url, bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", provider.Secret))
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func(Body io.ReadCloser) {
|
||||
err := Body.Close()
|
||||
if err != nil {
|
||||
log.Printf("NEZHA>> 无法关闭HTTP响应体流: %s\n", err.Error())
|
||||
}
|
||||
}(resp.Body)
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return body, nil
|
||||
}
|
||||
|
||||
func (provider DDNSProviderWebHook) FormatWebhookString(s string, config *DDNSDomainConfig, ipType string) string {
|
||||
if config == nil {
|
||||
return s
|
||||
}
|
||||
|
||||
result := strings.TrimSpace(s)
|
||||
result = strings.Replace(s, "{ip}", config.Ipv4Addr, -1)
|
||||
result = strings.Replace(result, "{domain}", config.FullDomain, -1)
|
||||
result = strings.Replace(result, "{type}", ipType, -1)
|
||||
result = strings.Replace(result, "{access_id}", Conf.DDNS.AccessID, -1)
|
||||
result = strings.Replace(result, "{access_secret}", Conf.DDNS.AccessSecret, -1)
|
||||
// remove \r
|
||||
result = strings.Replace(result, "\r", "", -1)
|
||||
return result
|
||||
}
|
||||
|
||||
func SetStringHeadersToRequest(req *http.Request, headers []string) {
|
||||
if req == nil {
|
||||
return
|
||||
}
|
||||
for _, element := range headers {
|
||||
kv := strings.SplitN(element, ":", 2)
|
||||
if len(kv) == 2 {
|
||||
req.Header.Add(kv[0], kv[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SplitDomain 分割域名为前缀和一级域名
|
||||
func SplitDomain(domain string) (prefix string, topLevelDomain string) {
|
||||
// 带有二级TLD的一些常见例子,需要特别处理
|
||||
secondLevelTLDs := map[string]bool{
|
||||
".co.uk": true, ".com.cn": true, ".gov.cn": true, ".net.cn": true, ".org.cn": true,
|
||||
}
|
||||
|
||||
// 分割域名为"."的各部分
|
||||
parts := strings.Split(domain, ".")
|
||||
|
||||
// 处理特殊情况,例如 ".co.uk"
|
||||
for i := len(parts) - 2; i > 0; i-- {
|
||||
potentialTLD := fmt.Sprintf(".%s.%s", parts[i], parts[i+1])
|
||||
if secondLevelTLDs[potentialTLD] {
|
||||
if i > 1 {
|
||||
return strings.Join(parts[:i-1], "."), strings.Join(parts[i-1:], ".")
|
||||
}
|
||||
return "", domain // 当域名仅为二级TLD时,无前缀
|
||||
}
|
||||
}
|
||||
|
||||
// 常规处理,查找最后一个"."前的所有内容作为前缀
|
||||
if len(parts) > 2 {
|
||||
return strings.Join(parts[:len(parts)-2], "."), strings.Join(parts[len(parts)-2:], ".")
|
||||
}
|
||||
return "", domain // 当域名不包含子域名时,无前缀
|
||||
}
|
||||
|
||||
func RetryableUpdateDomain(provider DDNSProvider, config *DDNSDomainConfig, maxRetries int) bool {
|
||||
if nil == config {
|
||||
return false
|
||||
}
|
||||
for retries := 0; retries < maxRetries; retries++ {
|
||||
log.Printf("NEZHA>> 正在尝试更新域名(%s)DDNS(%d/%d)\n", config.FullDomain, retries+1, maxRetries)
|
||||
if provider.UpdateDomain(config) {
|
||||
log.Printf("NEZHA>> 尝试更新域名(%s)DDNS成功\n", config.FullDomain)
|
||||
return true
|
||||
}
|
||||
}
|
||||
log.Printf("NEZHA>> 尝试更新域名(%s)DDNS失败\n", config.FullDomain)
|
||||
return false
|
||||
}
|
||||
|
||||
func GetDDNSProviderFromString(provider string) (DDNSProvider, error) {
|
||||
switch provider {
|
||||
case "webhook":
|
||||
return DDNSProviderWebHook{
|
||||
URL: Conf.DDNS.WebhookURL,
|
||||
RequestMethod: Conf.DDNS.WebhookMethod,
|
||||
RequestBody: Conf.DDNS.WebhookRequestBody,
|
||||
RequestHeader: Conf.DDNS.WebhookHeaders,
|
||||
}, nil
|
||||
case "dummy":
|
||||
return DDNSProviderDummy{}, nil
|
||||
case "cloudflare":
|
||||
return DDNSProviderCloudflare{
|
||||
Secret: Conf.DDNS.AccessSecret,
|
||||
}, nil
|
||||
}
|
||||
return DDNSProviderDummy{}, errors.New(fmt.Sprintf("无法找到配置的DDNS提供者%s", Conf.DDNS.Provider))
|
||||
}
|
||||
@@ -8,9 +8,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
pb "github.com/naiba/nezha/proto"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -36,12 +37,13 @@ func NewServiceSentinel(serviceSentinelDispatchBus chan<- model.Monitor) {
|
||||
ServiceSentinelShared = &ServiceSentinel{
|
||||
serviceReportChannel: make(chan ReportData, 200),
|
||||
serviceStatusToday: make(map[uint64]*_TodayStatsOfMonitor),
|
||||
serviceCurrentStatusIndex: make(map[uint64]int),
|
||||
serviceCurrentStatusIndex: make(map[uint64]*indexStore),
|
||||
serviceCurrentStatusData: make(map[uint64][]*pb.TaskResult),
|
||||
lastStatus: make(map[uint64]int),
|
||||
serviceResponseDataStoreCurrentUp: make(map[uint64]uint64),
|
||||
serviceResponseDataStoreCurrentDown: make(map[uint64]uint64),
|
||||
serviceResponseDataStoreCurrentAvgDelay: make(map[uint64]float32),
|
||||
serviceResponsePing: make(map[uint64]map[uint64]*pingStore),
|
||||
monitors: make(map[uint64]*model.Monitor),
|
||||
sslCertCache: make(map[uint64]string),
|
||||
// 30天数据缓存
|
||||
@@ -95,11 +97,12 @@ type ServiceSentinel struct {
|
||||
|
||||
serviceResponseDataStoreLock sync.RWMutex
|
||||
serviceStatusToday map[uint64]*_TodayStatsOfMonitor // [monitor_id] -> _TodayStatsOfMonitor
|
||||
serviceCurrentStatusIndex map[uint64]int // [monitor_id] -> 该监控ID对应的 serviceCurrentStatusData 的最新索引下标
|
||||
serviceCurrentStatusIndex map[uint64]*indexStore // [monitor_id] -> 该监控ID对应的 serviceCurrentStatusData 的最新索引下标
|
||||
serviceCurrentStatusData map[uint64][]*pb.TaskResult // [monitor_id] -> []model.MonitorHistory
|
||||
serviceResponseDataStoreCurrentUp map[uint64]uint64 // [monitor_id] -> 当前服务在线计数
|
||||
serviceResponseDataStoreCurrentDown map[uint64]uint64 // [monitor_id] -> 当前服务离线计数
|
||||
serviceResponseDataStoreCurrentAvgDelay map[uint64]float32 // [monitor_id] -> 当前服务离线计数
|
||||
serviceResponsePing map[uint64]map[uint64]*pingStore // [monitor_id] -> ClientID -> delay
|
||||
lastStatus map[uint64]int
|
||||
sslCertCache map[uint64]string
|
||||
|
||||
@@ -111,6 +114,16 @@ type ServiceSentinel struct {
|
||||
monthlyStatus map[uint64]*model.ServiceItemResponse // [monitor_id] -> model.ServiceItemResponse
|
||||
}
|
||||
|
||||
type indexStore struct {
|
||||
index int
|
||||
t time.Time
|
||||
}
|
||||
|
||||
type pingStore struct {
|
||||
count int
|
||||
ping float32
|
||||
}
|
||||
|
||||
func (ss *ServiceSentinel) refreshMonthlyServiceStatus() {
|
||||
// 刷新数据防止无人访问
|
||||
ss.LoadStats()
|
||||
@@ -326,6 +339,34 @@ func (ss *ServiceSentinel) worker() {
|
||||
continue
|
||||
}
|
||||
mh := r.Data
|
||||
if mh.Type == model.TaskTypeTCPPing || mh.Type == model.TaskTypeICMPPing {
|
||||
monitorTcpMap, ok := ss.serviceResponsePing[mh.GetId()]
|
||||
if !ok {
|
||||
monitorTcpMap = make(map[uint64]*pingStore)
|
||||
ss.serviceResponsePing[mh.GetId()] = monitorTcpMap
|
||||
}
|
||||
ts, ok := monitorTcpMap[r.Reporter]
|
||||
if !ok {
|
||||
ts = &pingStore{}
|
||||
}
|
||||
ts.count++
|
||||
ts.ping = (ts.ping*float32(ts.count-1) + mh.Delay) / float32(ts.count)
|
||||
if ts.count == Conf.AvgPingCount {
|
||||
if ts.ping > float32(Conf.MaxTCPPingValue) {
|
||||
ts.ping = float32(Conf.MaxTCPPingValue)
|
||||
}
|
||||
ts.count = 0
|
||||
if err := DB.Create(&model.MonitorHistory{
|
||||
MonitorID: mh.GetId(),
|
||||
AvgDelay: ts.ping,
|
||||
Data: mh.Data,
|
||||
ServerID: r.Reporter,
|
||||
}).Error; err != nil {
|
||||
log.Println("NEZHA>> 服务监控数据持久化失败:", err)
|
||||
}
|
||||
}
|
||||
monitorTcpMap[r.Reporter] = ts
|
||||
}
|
||||
ss.serviceResponseDataStoreLock.Lock()
|
||||
// 写入当天状态
|
||||
if mh.Successful {
|
||||
@@ -336,9 +377,20 @@ func (ss *ServiceSentinel) worker() {
|
||||
} else {
|
||||
ss.serviceStatusToday[mh.GetId()].Down++
|
||||
}
|
||||
|
||||
currentTime := time.Now()
|
||||
if ss.serviceCurrentStatusIndex[mh.GetId()] == nil {
|
||||
ss.serviceCurrentStatusIndex[mh.GetId()] = &indexStore{
|
||||
t: currentTime,
|
||||
index: 0,
|
||||
}
|
||||
}
|
||||
// 写入当前数据
|
||||
ss.serviceCurrentStatusData[mh.GetId()][ss.serviceCurrentStatusIndex[mh.GetId()]] = mh
|
||||
ss.serviceCurrentStatusIndex[mh.GetId()]++
|
||||
if ss.serviceCurrentStatusIndex[mh.GetId()].t.Before(currentTime) {
|
||||
ss.serviceCurrentStatusIndex[mh.GetId()].t = currentTime.Add(30 * time.Second)
|
||||
ss.serviceCurrentStatusData[mh.GetId()][ss.serviceCurrentStatusIndex[mh.GetId()].index] = mh
|
||||
ss.serviceCurrentStatusIndex[mh.GetId()].index++
|
||||
}
|
||||
|
||||
// 更新当前状态
|
||||
ss.serviceResponseDataStoreCurrentUp[mh.GetId()] = 0
|
||||
@@ -365,8 +417,11 @@ func (ss *ServiceSentinel) worker() {
|
||||
stateCode := GetStatusCode(upPercent)
|
||||
|
||||
// 数据持久化
|
||||
if ss.serviceCurrentStatusIndex[mh.GetId()] == _CurrentStatusSize {
|
||||
ss.serviceCurrentStatusIndex[mh.GetId()] = 0
|
||||
if ss.serviceCurrentStatusIndex[mh.GetId()].index == _CurrentStatusSize {
|
||||
ss.serviceCurrentStatusIndex[mh.GetId()] = &indexStore{
|
||||
index: 0,
|
||||
t: currentTime,
|
||||
}
|
||||
if err := DB.Create(&model.MonitorHistory{
|
||||
MonitorID: mh.GetId(),
|
||||
AvgDelay: ss.serviceResponseDataStoreCurrentAvgDelay[mh.GetId()],
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package singleton
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
@@ -46,6 +47,21 @@ func InitConfigFromPath(path string) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ValidateConfig()
|
||||
}
|
||||
|
||||
// ValidateConfig 验证配置文件有效性
|
||||
func ValidateConfig() {
|
||||
// 如果DDNS启用则检查Provider是否存在, 不存在直接退出
|
||||
if Conf.DDNS.Enable {
|
||||
_, err := GetDDNSProviderFromString(Conf.DDNS.Provider)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if Conf.DDNS.MaxRetries < 1 || Conf.DDNS.MaxRetries > 10 {
|
||||
panic(fmt.Errorf("DDNS.MaxRetries值域为[1, 10]的整数, 当前为 %d", Conf.DDNS.MaxRetries))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// InitDBFromPath 从给出的文件路径中加载数据库
|
||||
@@ -99,6 +115,10 @@ func RecordTransferHourlyUsage() {
|
||||
func CleanMonitorHistory() {
|
||||
// 清理已被删除的服务器的监控记录与流量记录
|
||||
DB.Unscoped().Delete(&model.MonitorHistory{}, "created_at < ? OR monitor_id NOT IN (SELECT `id` FROM monitors)", time.Now().AddDate(0, 0, -30))
|
||||
// 由于网络监控记录的数据较多,并且前端仅使用了 1 天的数据
|
||||
// 考虑到 sqlite 数据量问题,仅保留一天数据,
|
||||
// server_id = 0 的数据会用于/service页面的可用性展示
|
||||
DB.Unscoped().Delete(&model.MonitorHistory{}, "(created_at < ? AND server_id != 0) OR monitor_id NOT IN (SELECT `id` FROM monitors)", time.Now().AddDate(0, 0, -1))
|
||||
DB.Unscoped().Delete(&model.Transfer{}, "server_id NOT IN (SELECT `id` FROM servers)")
|
||||
// 计算可清理流量记录的时长
|
||||
var allServerKeep time.Time
|
||||
|
||||
Reference in New Issue
Block a user