diff --git a/resource/static/main.js b/resource/static/main.js index f32acef..2aedffb 100644 --- a/resource/static/main.js +++ b/resource/static/main.js @@ -1,13 +1,7 @@ -/** - * Converts a long string of bytes into a readable format e.g KB, MB, GB, TB, YB - * - * @param {Int} num The number of bytes. - */ function readableBytes(bytes) { 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(2) * 1 + ' ' + sizes[i]; + return (bytes / Math.pow(1024, i)).toFixed(0) + ' ' + sizes[i]; } const confirmBtn = $('.mini.confirm.modal .positive.button') diff --git a/resource/template/common/footer.html b/resource/template/common/footer.html index 60f9ffb..96322dd 100644 --- a/resource/template/common/footer.html +++ b/resource/template/common/footer.html @@ -9,7 +9,7 @@ - + diff --git a/resource/template/theme-default/home.html b/resource/template/theme-default/home.html index 7318f34..18a9780 100644 --- a/resource/template/theme-default/home.html +++ b/resource/template/theme-default/home.html @@ -151,10 +151,13 @@ }, secondToDate(s) { var d = Math.floor(s / 3600 / 24); + if (d > 0) { + return d + "天" + } var h = Math.floor(s / 3600 % 24); - var m = Math.floor((s / 60 % 60)); - var s = Math.floor((s % 60)); - return result = d + "天" + h + "小时" + m + "分钟" + s + "秒"; + var m = Math.floor(s / 60 % 60); + var s = Math.floor(s % 60); + return h + ":" + ("0" + m).slice(-2) + ":" + ("0" + s).slice(-2); }, formatTimestamp(t) { return new Date(t * 1000).toLocaleString() diff --git a/resource/template/theme-hotaru/home.html b/resource/template/theme-hotaru/home.html index 81c7d86..d141eb1 100644 --- a/resource/template/theme-hotaru/home.html +++ b/resource/template/theme-hotaru/home.html @@ -48,8 +48,8 @@ 运行状态 节点名 系统 - 服务器位置 - 在线时间 + 位置 + 在线 网络(B/s) ↓|↑ 流量(B) ↓|↑ CPU @@ -200,8 +200,7 @@ readableBytes(bytes) { 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(2) * 1 + ' ' + sizes[i]; + return (bytes / Math.pow(1024, i)).toFixed(0) + ' ' + sizes[i]; }, troggleDarkMode() { const hour = new Date(Date.now()).getHours() @@ -211,10 +210,13 @@ }, secondToDate(s) { var d = Math.floor(s / 3600 / 24); + if (d > 0) { + return d + "天" + } var h = Math.floor(s / 3600 % 24); - var m = Math.floor((s / 60 % 60)); - var s = Math.floor((s % 60)); - return result = d + "天" + h + "小时" + m + "分钟" + s + "秒"; + var m = Math.floor(s / 60 % 60); + var s = Math.floor(s % 60); + return h + ":" + ("0" + m).slice(-2) + ":" + ("0" + s).slice(-2); }, formatTimestamp(t) { return new Date(t * 1000).toLocaleString() diff --git a/service/alertmanager/alertmanager.go b/service/alertmanager/alertmanager.go index fd603a7..7d611cc 100644 --- a/service/alertmanager/alertmanager.go +++ b/service/alertmanager/alertmanager.go @@ -30,17 +30,19 @@ type NotificationHistory struct { func Start() { alertsStore = make(map[uint64]map[uint64][][]interface{}) + notificationsLock.Lock() + if err := dao.DB.Find(¬ifications).Error; err != nil { + panic(err) + } + notificationsLock.Unlock() alertsLock.Lock() if err := dao.DB.Find(&alerts).Error; err != nil { panic(err) } - if err := dao.DB.Find(¬ifications).Error; err != nil { - panic(err) - } - alertsLock.Unlock() for i := 0; i < len(alerts); i++ { alertsStore[alerts[i].ID] = make(map[uint64][][]interface{}) } + alertsLock.Unlock() time.Sleep(time.Second * 10) go checkStatus() @@ -50,11 +52,16 @@ func OnRefreshOrAddAlert(alert model.AlertRule) { alertsLock.Lock() defer alertsLock.Unlock() delete(alertsStore, alert.ID) + var isEdit bool for i := 0; i < len(alerts); i++ { if alerts[i].ID == alert.ID { alerts[i] = alert + isEdit = true } } + if !isEdit { + alerts = append(alerts, alert) + } alertsStore[alert.ID] = make(map[uint64][][]interface{}) } @@ -72,11 +79,16 @@ func OnDeleteAlert(id uint64) { func OnRefreshOrAddNotification(n model.Notification) { notificationsLock.Lock() defer notificationsLock.Unlock() + var isEdit bool for i := 0; i < len(notifications); i++ { if notifications[i].ID == n.ID { notifications[i] = n + isEdit = true } } + if !isEdit { + notifications = append(notifications, n) + } } func OnDeleteNotification(id uint64) {