🐛 流量记录删除条件 typo
This commit is contained in:
parent
561a3c85fb
commit
5443c72dbe
@ -4,7 +4,7 @@
|
|||||||
<br>
|
<br>
|
||||||
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
|
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
|
||||||
<br><br>
|
<br><br>
|
||||||
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.11.3&logo=github&style=for-the-badge"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.7.1-brightgreen?style=for-the-badge&logo=linux">
|
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.11.5&logo=github&style=for-the-badge"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.7.1-brightgreen?style=for-the-badge&logo=linux">
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,计划任务和在线终端。</p>
|
<p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,计划任务和在线终端。</p>
|
||||||
|
@ -87,12 +87,18 @@ func recordTransferHourlyUsage() {
|
|||||||
In: server.State.NetInTransfer - uint64(server.PrevHourlyTransferIn),
|
In: server.State.NetInTransfer - uint64(server.PrevHourlyTransferIn),
|
||||||
Out: server.State.NetOutTransfer - uint64(server.PrevHourlyTransferOut),
|
Out: server.State.NetOutTransfer - uint64(server.PrevHourlyTransferOut),
|
||||||
}
|
}
|
||||||
|
if tx.In == 0 && tx.Out == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
server.PrevHourlyTransferIn = int64(server.State.NetInTransfer)
|
server.PrevHourlyTransferIn = int64(server.State.NetInTransfer)
|
||||||
server.PrevHourlyTransferOut = int64(server.State.NetOutTransfer)
|
server.PrevHourlyTransferOut = int64(server.State.NetOutTransfer)
|
||||||
tx.CreatedAt = nowTrimSeconds
|
tx.CreatedAt = nowTrimSeconds
|
||||||
txs = append(txs, tx)
|
txs = append(txs, tx)
|
||||||
}
|
}
|
||||||
dao.DB.Create(txs)
|
if len(txs) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println("NEZHA>> Cron 流量统计入库", len(txs), dao.DB.Create(txs).Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanMonitorHistory() {
|
func cleanMonitorHistory() {
|
||||||
@ -130,12 +136,12 @@ func cleanMonitorHistory() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for id, couldRemove := range specialServerKeep {
|
for id, couldRemove := range specialServerKeep {
|
||||||
dao.DB.Unscoped().Delete(&model.Transfer{}, "id = ? AND created_at < ?", id, couldRemove)
|
dao.DB.Unscoped().Delete(&model.Transfer{}, "server_id = ? AND created_at < ?", id, couldRemove)
|
||||||
}
|
}
|
||||||
if allServerKeep.IsZero() {
|
if allServerKeep.IsZero() {
|
||||||
dao.DB.Unscoped().Delete(&model.Transfer{}, "id NOT IN (?)", specialServerIDs)
|
dao.DB.Unscoped().Delete(&model.Transfer{}, "server_id NOT IN (?)", specialServerIDs)
|
||||||
} else {
|
} else {
|
||||||
dao.DB.Unscoped().Delete(&model.Transfer{}, "id NOT IN (?) AND created_at < ?", specialServerIDs, allServerKeep)
|
dao.DB.Unscoped().Delete(&model.Transfer{}, "server_id NOT IN (?) AND created_at < ?", specialServerIDs, allServerKeep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,25 +199,9 @@ func main() {
|
|||||||
graceful.Graceful(func() error {
|
graceful.Graceful(func() error {
|
||||||
return srv.ListenAndServe()
|
return srv.ListenAndServe()
|
||||||
}, func(c context.Context) error {
|
}, func(c context.Context) error {
|
||||||
dao.ServerLock.Lock()
|
log.Println("NEZHA>> Graceful::START")
|
||||||
defer dao.ServerLock.Unlock()
|
recordTransferHourlyUsage()
|
||||||
var txs []model.Transfer
|
log.Println("NEZHA>> Graceful::END")
|
||||||
for _, s := range dao.ServerList {
|
|
||||||
in := s.State.NetInTransfer - uint64(s.PrevHourlyTransferIn)
|
|
||||||
out := s.State.NetOutTransfer - uint64(s.PrevHourlyTransferOut)
|
|
||||||
if in > 0 || out > 0 {
|
|
||||||
tx := model.Transfer{
|
|
||||||
ServerID: s.ID,
|
|
||||||
In: in,
|
|
||||||
Out: out,
|
|
||||||
}
|
|
||||||
tx.CreatedAt = time.Now()
|
|
||||||
txs = append(txs, tx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := dao.DB.Create(txs).Error; err != nil {
|
|
||||||
log.Println("NEZHA>> 流量统计入库", err)
|
|
||||||
}
|
|
||||||
srv.Shutdown(c)
|
srv.Shutdown(c)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
pb "github.com/naiba/nezha/proto"
|
pb "github.com/naiba/nezha/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "v0.11.3" // !!记得修改 README 中的 badge 版本!!
|
var Version = "v0.11.5" // !!记得修改 README 中的 badge 版本!!
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Conf *model.Config
|
Conf *model.Config
|
||||||
|
Loading…
Reference in New Issue
Block a user