mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 20:58: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) {
|
function readableBytes(bytes) {
|
||||||
var i = Math.floor(Math.log(bytes) / Math.log(1024)),
|
var i = Math.floor(Math.log(bytes) / Math.log(1024)),
|
||||||
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||||
|
return (bytes / Math.pow(1024, i)).toFixed(0) + ' ' + sizes[i];
|
||||||
return (bytes / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + sizes[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const confirmBtn = $('.mini.confirm.modal .positive.button')
|
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="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="/static/semantic-ui-alerts.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue"></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>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -151,10 +151,13 @@
|
|||||||
},
|
},
|
||||||
secondToDate(s) {
|
secondToDate(s) {
|
||||||
var d = Math.floor(s / 3600 / 24);
|
var d = Math.floor(s / 3600 / 24);
|
||||||
|
if (d > 0) {
|
||||||
|
return d + "天"
|
||||||
|
}
|
||||||
var h = Math.floor(s / 3600 % 24);
|
var h = Math.floor(s / 3600 % 24);
|
||||||
var m = Math.floor((s / 60 % 60));
|
var m = Math.floor(s / 60 % 60);
|
||||||
var s = Math.floor((s % 60));
|
var s = Math.floor(s % 60);
|
||||||
return result = d + "天" + h + "小时" + m + "分钟" + s + "秒";
|
return h + ":" + ("0" + m).slice(-2) + ":" + ("0" + s).slice(-2);
|
||||||
},
|
},
|
||||||
formatTimestamp(t) {
|
formatTimestamp(t) {
|
||||||
return new Date(t * 1000).toLocaleString()
|
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>位置</th>
|
||||||
<th>在线时间</th>
|
<th>在线</th>
|
||||||
<th>网络(B/s) ↓|↑</th>
|
<th>网络(B/s) ↓|↑</th>
|
||||||
<th>流量(B) ↓|↑</th>
|
<th>流量(B) ↓|↑</th>
|
||||||
<th>CPU</th>
|
<th>CPU</th>
|
||||||
@ -200,8 +200,7 @@
|
|||||||
readableBytes(bytes) {
|
readableBytes(bytes) {
|
||||||
var i = Math.floor(Math.log(bytes) / Math.log(1024)),
|
var i = Math.floor(Math.log(bytes) / Math.log(1024)),
|
||||||
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||||
|
return (bytes / Math.pow(1024, i)).toFixed(0) + ' ' + sizes[i];
|
||||||
return (bytes / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + sizes[i];
|
|
||||||
},
|
},
|
||||||
troggleDarkMode() {
|
troggleDarkMode() {
|
||||||
const hour = new Date(Date.now()).getHours()
|
const hour = new Date(Date.now()).getHours()
|
||||||
@ -211,10 +210,13 @@
|
|||||||
},
|
},
|
||||||
secondToDate(s) {
|
secondToDate(s) {
|
||||||
var d = Math.floor(s / 3600 / 24);
|
var d = Math.floor(s / 3600 / 24);
|
||||||
|
if (d > 0) {
|
||||||
|
return d + "天"
|
||||||
|
}
|
||||||
var h = Math.floor(s / 3600 % 24);
|
var h = Math.floor(s / 3600 % 24);
|
||||||
var m = Math.floor((s / 60 % 60));
|
var m = Math.floor(s / 60 % 60);
|
||||||
var s = Math.floor((s % 60));
|
var s = Math.floor(s % 60);
|
||||||
return result = d + "天" + h + "小时" + m + "分钟" + s + "秒";
|
return h + ":" + ("0" + m).slice(-2) + ":" + ("0" + s).slice(-2);
|
||||||
},
|
},
|
||||||
formatTimestamp(t) {
|
formatTimestamp(t) {
|
||||||
return new Date(t * 1000).toLocaleString()
|
return new Date(t * 1000).toLocaleString()
|
||||||
|
@ -30,17 +30,19 @@ type NotificationHistory struct {
|
|||||||
|
|
||||||
func Start() {
|
func Start() {
|
||||||
alertsStore = make(map[uint64]map[uint64][][]interface{})
|
alertsStore = make(map[uint64]map[uint64][][]interface{})
|
||||||
|
notificationsLock.Lock()
|
||||||
|
if err := dao.DB.Find(¬ifications).Error; err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
notificationsLock.Unlock()
|
||||||
alertsLock.Lock()
|
alertsLock.Lock()
|
||||||
if err := dao.DB.Find(&alerts).Error; err != nil {
|
if err := dao.DB.Find(&alerts).Error; err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if err := dao.DB.Find(¬ifications).Error; err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
alertsLock.Unlock()
|
|
||||||
for i := 0; i < len(alerts); i++ {
|
for i := 0; i < len(alerts); i++ {
|
||||||
alertsStore[alerts[i].ID] = make(map[uint64][][]interface{})
|
alertsStore[alerts[i].ID] = make(map[uint64][][]interface{})
|
||||||
}
|
}
|
||||||
|
alertsLock.Unlock()
|
||||||
|
|
||||||
time.Sleep(time.Second * 10)
|
time.Sleep(time.Second * 10)
|
||||||
go checkStatus()
|
go checkStatus()
|
||||||
@ -50,11 +52,16 @@ func OnRefreshOrAddAlert(alert model.AlertRule) {
|
|||||||
alertsLock.Lock()
|
alertsLock.Lock()
|
||||||
defer alertsLock.Unlock()
|
defer alertsLock.Unlock()
|
||||||
delete(alertsStore, alert.ID)
|
delete(alertsStore, alert.ID)
|
||||||
|
var isEdit bool
|
||||||
for i := 0; i < len(alerts); i++ {
|
for i := 0; i < len(alerts); i++ {
|
||||||
if alerts[i].ID == alert.ID {
|
if alerts[i].ID == alert.ID {
|
||||||
alerts[i] = alert
|
alerts[i] = alert
|
||||||
|
isEdit = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !isEdit {
|
||||||
|
alerts = append(alerts, alert)
|
||||||
|
}
|
||||||
alertsStore[alert.ID] = make(map[uint64][][]interface{})
|
alertsStore[alert.ID] = make(map[uint64][][]interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,11 +79,16 @@ func OnDeleteAlert(id uint64) {
|
|||||||
func OnRefreshOrAddNotification(n model.Notification) {
|
func OnRefreshOrAddNotification(n model.Notification) {
|
||||||
notificationsLock.Lock()
|
notificationsLock.Lock()
|
||||||
defer notificationsLock.Unlock()
|
defer notificationsLock.Unlock()
|
||||||
|
var isEdit bool
|
||||||
for i := 0; i < len(notifications); i++ {
|
for i := 0; i < len(notifications); i++ {
|
||||||
if notifications[i].ID == n.ID {
|
if notifications[i].ID == n.ID {
|
||||||
notifications[i] = n
|
notifications[i] = n
|
||||||
|
isEdit = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !isEdit {
|
||||||
|
notifications = append(notifications, n)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnDeleteNotification(id uint64) {
|
func OnDeleteNotification(id uint64) {
|
||||||
|
Loading…
Reference in New Issue
Block a user