展示月流量使用情况

This commit is contained in:
naiba
2021-11-06 16:00:08 +08:00
parent 611cabf369
commit 561a3c85fb
8 changed files with 136 additions and 39 deletions

View File

@@ -98,17 +98,19 @@ func (p *commonPage) checkViewPassword(c *gin.Context) {
}
func (p *commonPage) service(c *gin.Context) {
dao.AlertsLock.RLock()
defer dao.AlertsLock.RUnlock()
c.HTML(http.StatusOK, "theme-"+dao.Conf.Site.Theme+"/service", mygin.CommonEnvironment(c, gin.H{
"Title": "服务状态",
"Services": dao.ServiceSentinelShared.LoadStats(),
"CustomCode": dao.Conf.Site.CustomCode,
"Title": "服务状态",
"Services": dao.ServiceSentinelShared.LoadStats(),
"CycleTransferStats": dao.AlertsCycleTransferStatsStore,
"CustomCode": dao.Conf.Site.CustomCode,
}))
}
func (cp *commonPage) home(c *gin.Context) {
dao.SortedServerLock.RLock()
defer dao.SortedServerLock.RUnlock()
c.HTML(http.StatusOK, "theme-"+dao.Conf.Site.Theme+"/home", mygin.CommonEnvironment(c, gin.H{
"Servers": dao.SortedServerList,
"CustomCode": dao.Conf.Site.CustomCode,

View File

@@ -61,11 +61,24 @@ func (ma *memberAPI) delete(c *gin.Context) {
case "server":
err = dao.DB.Unscoped().Delete(&model.Server{}, "id = ?", id).Error
if err == nil {
// 删除服务器
dao.ServerLock.Lock()
delete(dao.SecretToID, dao.ServerList[id].Secret)
delete(dao.ServerList, id)
dao.ServerLock.Unlock()
dao.ReSortServer()
// 删除循环流量状态中的此服务器相关的记录
dao.AlertsLock.Lock()
for i := 0; i < len(dao.Alerts); i++ {
if dao.AlertsCycleTransferStatsStore[dao.Alerts[i].ID] != nil {
delete(dao.AlertsCycleTransferStatsStore[dao.Alerts[i].ID].ServerName, id)
delete(dao.AlertsCycleTransferStatsStore[dao.Alerts[i].ID].Transfer, id)
delete(dao.AlertsCycleTransferStatsStore[dao.Alerts[i].ID].NextUpdate, id)
}
}
dao.AlertsLock.Unlock()
// 删除服务器相关循环流量记录
dao.DB.Unscoped().Delete(&model.Transfer{}, "server_id = ?", id)
}
case "notification":
err = dao.DB.Unscoped().Delete(&model.Notification{}, "id = ?", id).Error