mirror of
https://github.com/nezhahq/nezha.git
synced 2025-02-02 01:28:13 -05:00
优化 agent 信息上报与 ARM 安装面板的错误提示
This commit is contained in:
parent
92ecb33901
commit
8d0e269b73
@ -267,12 +267,14 @@ func doTask(task *pb.Task) {
|
|||||||
func reportState() {
|
func reportState() {
|
||||||
var lastReportHostInfo time.Time
|
var lastReportHostInfo time.Time
|
||||||
var err error
|
var err error
|
||||||
|
var now time.Time
|
||||||
defer println("reportState exit", time.Now(), "=>", err)
|
defer println("reportState exit", time.Now(), "=>", err)
|
||||||
for {
|
for {
|
||||||
|
now = time.Now()
|
||||||
if client != nil {
|
if client != nil {
|
||||||
monitor.TrackNetworkSpeed()
|
monitor.TrackNetworkSpeed()
|
||||||
timeOutCtx, cancel := context.WithTimeout(context.Background(), networkTimeOut)
|
timeOutCtx, cancel := context.WithTimeout(context.Background(), networkTimeOut)
|
||||||
_, err = client.ReportSystemState(timeOutCtx, monitor.GetState(dao.ReportDelay).PB())
|
_, err = client.ReportSystemState(timeOutCtx, monitor.GetState().PB())
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println("reportState error", err)
|
println("reportState error", err)
|
||||||
@ -283,6 +285,7 @@ func reportState() {
|
|||||||
client.ReportSystemInfo(context.Background(), monitor.GetHost().PB())
|
client.ReportSystemInfo(context.Background(), monitor.GetHost().PB())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
time.Sleep(time.Until(now.Add(time.Second)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,12 +63,12 @@ func GetHost() *model.Host {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetState(delay int64) *model.HostState {
|
func GetState() *model.HostState {
|
||||||
hi, _ := host.Info()
|
hi, _ := host.Info()
|
||||||
mv, _ := mem.VirtualMemory()
|
mv, _ := mem.VirtualMemory()
|
||||||
ms, _ := mem.SwapMemory()
|
ms, _ := mem.SwapMemory()
|
||||||
var cpuPercent float64
|
var cpuPercent float64
|
||||||
cp, err := cpu.Percent(time.Second*time.Duration(delay), false)
|
cp, err := cpu.Percent(0, false)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cpuPercent = cp[0]
|
cpuPercent = cp[0]
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func (r *AlertRule) Check(points [][]interface{}) (int, bool) {
|
|||||||
for i := 0; i < len(r.Rules); i++ {
|
for i := 0; i < len(r.Rules); i++ {
|
||||||
total := 0.0
|
total := 0.0
|
||||||
fail := 0.0
|
fail := 0.0
|
||||||
num := int(r.Rules[i].Duration / 2) // SnapshotDelay
|
num := int(r.Rules[i].Duration)
|
||||||
if num > max {
|
if num > max {
|
||||||
max = num
|
max = num
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
function readableBytes(bytes) {
|
function readableBytes(bytes) {
|
||||||
|
if (!bytes) {
|
||||||
|
return '0B'
|
||||||
|
}
|
||||||
var i = Math.floor(Math.log(bytes) / Math.log(1024)),
|
var i = Math.floor(Math.log(bytes) / Math.log(1024)),
|
||||||
sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||||
return (bytes / Math.pow(1024, i)).toFixed(0) + " " + sizes[i];
|
return parseFloat((bytes / Math.pow(1024, i)).toFixed(2)) + sizes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
const confirmBtn = $(".mini.confirm.modal .positive.button");
|
const confirmBtn = $(".mini.confirm.modal .positive.button");
|
||||||
|
2
resource/template/common/footer.html
vendored
2
resource/template/common/footer.html
vendored
@ -9,7 +9,7 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.1/dist/semantic.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.1/dist/semantic.min.js"></script>
|
||||||
<script src="/static/semantic-ui-alerts.min.js"></script>
|
<script src="/static/semantic-ui-alerts.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.min.js"></script>
|
||||||
<script src="/static/main.js?v202106212144"></script>
|
<script src="/static/main.js?v202106302144"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
8
resource/template/theme-hotaru/home.html
vendored
8
resource/template/theme-hotaru/home.html
vendored
@ -69,9 +69,9 @@
|
|||||||
<td>@#server.Host?server.Host.Platform:'-'#@</td>
|
<td>@#server.Host?server.Host.Platform:'-'#@</td>
|
||||||
<td>@#server.Host?server.Host.CountryCode:'-'#@</td>
|
<td>@#server.Host?server.Host.CountryCode:'-'#@</td>
|
||||||
<td>@#server.State?secondToDate(server.State.Uptime):'-'#@</td>
|
<td>@#server.State?secondToDate(server.State.Uptime):'-'#@</td>
|
||||||
<td>@#server.State?formatByteSize(server.State.NetInSpeed)+'/s|'+formatByteSize(server.State.NetOutSpeed)+'/s':'-'#@
|
<td>@#server.State?readableBytes(server.State.NetInSpeed)+'/s|'+readableBytes(server.State.NetOutSpeed)+'/s':'-'#@
|
||||||
</td>
|
</td>
|
||||||
<td>@#server.State?formatByteSize(server.State.NetInTransfer)+'|'+formatByteSize(server.State.NetOutTransfer):'-'#@
|
<td>@#server.State?readableBytes(server.State.NetInTransfer)+'|'+readableBytes(server.State.NetOutTransfer):'-'#@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div v-if="server.State" :class="formatPercent(server.live,server.State.CPU, 100).class">
|
<div v-if="server.State" :class="formatPercent(server.live,server.State.CPU, 100).class">
|
||||||
@ -226,10 +226,6 @@
|
|||||||
},
|
},
|
||||||
formatTimestamp(t) {
|
formatTimestamp(t) {
|
||||||
return new Date(t * 1000).toLocaleString()
|
return new Date(t * 1000).toLocaleString()
|
||||||
},
|
|
||||||
formatByteSize(bs) {
|
|
||||||
const x = this.readableBytes(bs)
|
|
||||||
return x != "NaN undefined" ? x : '0 KB'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -11,7 +11,7 @@ NZ_BASE_PATH="/opt/nezha"
|
|||||||
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
|
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
|
||||||
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
||||||
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
|
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
|
||||||
NZ_VERSION="v0.6.1"
|
NZ_VERSION="v0.6.2"
|
||||||
|
|
||||||
red='\033[0;31m'
|
red='\033[0;31m'
|
||||||
green='\033[0;32m'
|
green='\033[0;32m'
|
||||||
@ -134,6 +134,11 @@ install_dashboard() {
|
|||||||
|
|
||||||
echo -e "> 安装面板"
|
echo -e "> 安装面板"
|
||||||
|
|
||||||
|
if [[ $(uname -m | grep 'arm') != "" ]]; then
|
||||||
|
echo "面板目前不支持在 arm 环境下安装"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# 哪吒监控文件夹
|
# 哪吒监控文件夹
|
||||||
mkdir -p $NZ_DASHBOARD_PATH
|
mkdir -p $NZ_DASHBOARD_PATH
|
||||||
chmod 777 -R $NZ_DASHBOARD_PATH
|
chmod 777 -R $NZ_DASHBOARD_PATH
|
||||||
|
@ -59,7 +59,7 @@ func AlertSentinelStart() {
|
|||||||
checkCount = 0
|
checkCount = 0
|
||||||
lastPrint = startedAt
|
lastPrint = startedAt
|
||||||
}
|
}
|
||||||
time.Sleep(time.Until(startedAt.Add(time.Second * SnapshotDelay)))
|
time.Sleep(time.Until(startedAt.Add(time.Second * 3))) // 3秒钟检查一次
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/naiba/nezha/model"
|
"github.com/naiba/nezha/model"
|
||||||
|
"github.com/naiba/nezha/pkg/utils"
|
||||||
pb "github.com/naiba/nezha/proto"
|
pb "github.com/naiba/nezha/proto"
|
||||||
"github.com/naiba/nezha/service/dao"
|
"github.com/naiba/nezha/service/dao"
|
||||||
)
|
)
|
||||||
@ -94,7 +95,7 @@ func (s *NezhaHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rece
|
|||||||
dao.ServerList[clientID].Host.IP != host.IP {
|
dao.ServerList[clientID].Host.IP != host.IP {
|
||||||
dao.SendNotification(fmt.Sprintf(
|
dao.SendNotification(fmt.Sprintf(
|
||||||
"IP变更提醒 服务器:%s ,旧IP:%s,新IP:%s。",
|
"IP变更提醒 服务器:%s ,旧IP:%s,新IP:%s。",
|
||||||
dao.ServerList[clientID].Name, dao.ServerList[clientID].Host.IP, host.IP), true)
|
dao.ServerList[clientID].Name, utils.IPDesensitize(dao.ServerList[clientID].Host.IP), utils.IPDesensitize(host.IP)), true)
|
||||||
}
|
}
|
||||||
dao.ServerList[clientID].Host = &host
|
dao.ServerList[clientID].Host = &host
|
||||||
return &pb.Receipt{Proced: true}, nil
|
return &pb.Receipt{Proced: true}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user