mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
✨ 任意时间区间(月流量)统计,无视重启~
This commit is contained in:
@@ -109,7 +109,7 @@ func checkStatus() {
|
||||
for _, server := range ServerList {
|
||||
// 监测点
|
||||
alertsStore[alert.ID][server.ID] = append(alertsStore[alert.
|
||||
ID][server.ID], alert.Snapshot(server))
|
||||
ID][server.ID], alert.Snapshot(server, DB))
|
||||
// 发送通知,分为触发报警和恢复通知
|
||||
max, passed := alert.Check(alertsStore[alert.ID][server.ID])
|
||||
if !passed {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
pb "github.com/naiba/nezha/proto"
|
||||
)
|
||||
|
||||
var Version = "v0.8.6" // !!记得修改 README 中的 badge 版本!!
|
||||
var Version = "v0.9.0" // !!记得修改 README 中的 badge 版本!!
|
||||
|
||||
var (
|
||||
Conf *model.Config
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
pb "github.com/naiba/nezha/proto"
|
||||
)
|
||||
|
||||
const _CurrentStatusSize = 30 // 统计 5 分钟内的数据为当前状态
|
||||
const _CurrentStatusSize = 30 // 统计 15 分钟内的数据为当前状态
|
||||
|
||||
var ServiceSentinelShared *ServiceSentinel
|
||||
|
||||
|
||||
@@ -73,7 +73,21 @@ func (s *NezhaHandler) ReportSystemState(c context.Context, r *pb.State) (*pb.Re
|
||||
dao.ServerLock.RLock()
|
||||
defer dao.ServerLock.RUnlock()
|
||||
dao.ServerList[clientID].LastActive = time.Now()
|
||||
|
||||
// 判断是否是机器重启,如果是机器重启要录入最后记录的流量里面
|
||||
if state.Uptime < dao.ServerList[clientID].State.Uptime {
|
||||
dao.ServerList[clientID].PrevHourlyTransferIn = dao.ServerList[clientID].PrevHourlyTransferIn - int64(dao.ServerList[clientID].State.NetInTransfer)
|
||||
dao.ServerList[clientID].PrevHourlyTransferOut = dao.ServerList[clientID].PrevHourlyTransferOut - int64(dao.ServerList[clientID].State.NetOutTransfer)
|
||||
}
|
||||
|
||||
dao.ServerList[clientID].State = &state
|
||||
|
||||
// 如果从未记录过,先打点,等到小时时间点时入库
|
||||
if dao.ServerList[clientID].PrevHourlyTransferIn == 0 || dao.ServerList[clientID].PrevHourlyTransferOut == 0 {
|
||||
dao.ServerList[clientID].PrevHourlyTransferIn = int64(state.NetInTransfer)
|
||||
dao.ServerList[clientID].PrevHourlyTransferOut = int64(state.NetOutTransfer)
|
||||
}
|
||||
|
||||
return &pb.Receipt{Proced: true}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user