优化 agent 信息上报与 ARM 安装面板的错误提示

This commit is contained in:
naiba 2021-06-30 18:15:53 +08:00
parent 92ecb33901
commit 8d0e269b73
9 changed files with 23 additions and 15 deletions

View File

@ -267,12 +267,14 @@ func doTask(task *pb.Task) {
func reportState() {
var lastReportHostInfo time.Time
var err error
var now time.Time
defer println("reportState exit", time.Now(), "=>", err)
for {
now = time.Now()
if client != nil {
monitor.TrackNetworkSpeed()
timeOutCtx, cancel := context.WithTimeout(context.Background(), networkTimeOut)
_, err = client.ReportSystemState(timeOutCtx, monitor.GetState(dao.ReportDelay).PB())
_, err = client.ReportSystemState(timeOutCtx, monitor.GetState().PB())
cancel()
if err != nil {
println("reportState error", err)
@ -283,6 +285,7 @@ func reportState() {
client.ReportSystemInfo(context.Background(), monitor.GetHost().PB())
}
}
time.Sleep(time.Until(now.Add(time.Second)))
}
}

View File

@ -63,12 +63,12 @@ func GetHost() *model.Host {
}
}
func GetState(delay int64) *model.HostState {
func GetState() *model.HostState {
hi, _ := host.Info()
mv, _ := mem.VirtualMemory()
ms, _ := mem.SwapMemory()
var cpuPercent float64
cp, err := cpu.Percent(time.Second*time.Duration(delay), false)
cp, err := cpu.Percent(0, false)
if err == nil {
cpuPercent = cp[0]
}

View File

@ -41,7 +41,7 @@ func (r *AlertRule) Check(points [][]interface{}) (int, bool) {
for i := 0; i < len(r.Rules); i++ {
total := 0.0
fail := 0.0
num := int(r.Rules[i].Duration / 2) // SnapshotDelay
num := int(r.Rules[i].Duration)
if num > max {
max = num
}

View File

@ -1,7 +1,10 @@
function readableBytes(bytes) {
if (!bytes) {
return '0B'
}
var i = Math.floor(Math.log(bytes) / Math.log(1024)),
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");

View File

@ -9,7 +9,7 @@
<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="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>
</html>

View File

@ -69,9 +69,9 @@
<td>@#server.Host?server.Host.Platform:'-'#@</td>
<td>@#server.Host?server.Host.CountryCode:'-'#@</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>@#server.State?formatByteSize(server.State.NetInTransfer)+'|'+formatByteSize(server.State.NetOutTransfer):'-'#@
<td>@#server.State?readableBytes(server.State.NetInTransfer)+'|'+readableBytes(server.State.NetOutTransfer):'-'#@
</td>
<td>
<div v-if="server.State" :class="formatPercent(server.live,server.State.CPU, 100).class">
@ -226,10 +226,6 @@
},
formatTimestamp(t) {
return new Date(t * 1000).toLocaleString()
},
formatByteSize(bs) {
const x = this.readableBytes(bs)
return x != "NaN undefined" ? x : '0 KB'
}
}
})

View File

@ -11,7 +11,7 @@ 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.6.1"
NZ_VERSION="v0.6.2"
red='\033[0;31m'
green='\033[0;32m'
@ -134,6 +134,11 @@ install_dashboard() {
echo -e "> 安装面板"
if [[ $(uname -m | grep 'arm') != "" ]]; then
echo "面板目前不支持在 arm 环境下安装"
exit 1
fi
# 哪吒监控文件夹
mkdir -p $NZ_DASHBOARD_PATH
chmod 777 -R $NZ_DASHBOARD_PATH

View File

@ -59,7 +59,7 @@ func AlertSentinelStart() {
checkCount = 0
lastPrint = startedAt
}
time.Sleep(time.Until(startedAt.Add(time.Second * SnapshotDelay)))
time.Sleep(time.Until(startedAt.Add(time.Second * 3))) // 3秒钟检查一次
}
}

View File

@ -6,6 +6,7 @@ import (
"time"
"github.com/naiba/nezha/model"
"github.com/naiba/nezha/pkg/utils"
pb "github.com/naiba/nezha/proto"
"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.SendNotification(fmt.Sprintf(
"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
return &pb.Receipt{Proced: true}, nil