mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
🐛 fix(alert): 添加报警规则
This commit is contained in:
parent
789065cb5f
commit
4ec61d0043
@ -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')
|
||||
|
@ -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"></script>
|
||||
<script src="/static/main.js?v202012202118"></script>
|
||||
<script src="/static/main.js?v202012211616"></script>
|
||||
</body>
|
||||
|
||||
</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()
|
||||
|
@ -48,8 +48,8 @@
|
||||
<th>运行状态</th>
|
||||
<th>节点名</th>
|
||||
<th>系统</th>
|
||||
<th>服务器位置</th>
|
||||
<th>在线时间</th>
|
||||
<th>位置</th>
|
||||
<th>在线</th>
|
||||
<th>网络(B/s) ↓|↑</th>
|
||||
<th>流量(B) ↓|↑</th>
|
||||
<th>CPU</th>
|
||||
@ -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()
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user