mirror of
https://github.com/nezhahq/nezha.git
synced 2025-02-08 12:38:13 -05:00
🐛 修复 cron/v3 表达式
This commit is contained in:
parent
d116347ef9
commit
aa5ac76442
@ -1,7 +1,7 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
<img width="500" style="max-width:100%" src="resource/static/brand.png" title="哪吒监控">
|
<img width="500" style="max-width:100%" src="resource/static/brand.png" title="哪吒监控">
|
||||||
<br><br>
|
<br><br>
|
||||||
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.9.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.6.4-brightgreen?style=for-the-badge&logo=linux">
|
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.9.6&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.6.4-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>
|
||||||
|
@ -277,16 +277,20 @@ func (ma *memberAPI) addOrEditCron(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cr.CronID, err = dao.Cron.AddFunc(cr.Scheduler, dao.CronTrigger(cr))
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, model.Response{
|
||||||
|
Code: http.StatusBadRequest,
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
dao.CronLock.Lock()
|
dao.CronLock.Lock()
|
||||||
defer dao.CronLock.Unlock()
|
defer dao.CronLock.Unlock()
|
||||||
crOld := dao.Crons[cr.ID]
|
crOld := dao.Crons[cr.ID]
|
||||||
if crOld != nil && crOld.CronID != 0 {
|
if crOld != nil && crOld.CronID != 0 {
|
||||||
dao.Cron.Remove(crOld.CronID)
|
dao.Cron.Remove(cron.EntryID(crOld.ID))
|
||||||
}
|
|
||||||
|
|
||||||
cr.CronID, err = dao.Cron.AddFunc(cr.Scheduler, dao.CronTrigger(cr))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(dao.Crons, cr.ID)
|
delete(dao.Crons, cr.ID)
|
||||||
|
@ -61,9 +61,15 @@ func initSystem() {
|
|||||||
loadCrons() //加载计划任务
|
loadCrons() //加载计划任务
|
||||||
|
|
||||||
// 清理 服务请求记录 和 流量记录 的旧数据
|
// 清理 服务请求记录 和 流量记录 的旧数据
|
||||||
dao.Cron.AddFunc("0 20 3 * * *", cleanMonitorHistory)
|
_, err := dao.Cron.AddFunc("30 3 * * *", cleanMonitorHistory)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
// 流量记录打点
|
// 流量记录打点
|
||||||
dao.Cron.AddFunc("0 0 * * * *", recordTransferHourlyUsage)
|
_, err = dao.Cron.AddFunc("0 * * * *", recordTransferHourlyUsage)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordTransferHourlyUsage() {
|
func recordTransferHourlyUsage() {
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
pb "github.com/naiba/nezha/proto"
|
pb "github.com/naiba/nezha/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "v0.9.5" // !!记得修改 README 中的 badge 版本!!
|
var Version = "v0.9.6" // !!记得修改 README 中的 badge 版本!!
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Conf *model.Config
|
Conf *model.Config
|
||||||
|
@ -71,7 +71,10 @@ func NewServiceSentinel() {
|
|||||||
go ServiceSentinelShared.worker()
|
go ServiceSentinelShared.worker()
|
||||||
|
|
||||||
// 每日将游标往后推一天
|
// 每日将游标往后推一天
|
||||||
Cron.AddFunc("0 0 * * * *", ServiceSentinelShared.refreshMonthlyServiceStatus)
|
_, err := Cron.AddFunc("* * * * *", ServiceSentinelShared.refreshMonthlyServiceStatus)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -92,13 +95,13 @@ type ServiceSentinel struct {
|
|||||||
monitors map[uint64]model.Monitor
|
monitors map[uint64]model.Monitor
|
||||||
sslCertCache map[uint64]string
|
sslCertCache map[uint64]string
|
||||||
// 30天数据缓存
|
// 30天数据缓存
|
||||||
monthlyStatusLock sync.RWMutex
|
monthlyStatusLock sync.Mutex
|
||||||
monthlyStatus map[uint64]*model.ServiceItemResponse
|
monthlyStatus map[uint64]*model.ServiceItemResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *ServiceSentinel) refreshMonthlyServiceStatus() {
|
func (ss *ServiceSentinel) refreshMonthlyServiceStatus() {
|
||||||
ss.monthlyStatusLock.Lock()
|
ss.monthlyStatusLock.Lock()
|
||||||
defer ss.monitorsLock.Unlock()
|
defer ss.monthlyStatusLock.Unlock()
|
||||||
// 将数据往前搦
|
// 将数据往前搦
|
||||||
for _, v := range ss.monthlyStatus {
|
for _, v := range ss.monthlyStatus {
|
||||||
for i := 0; i < len(v.Up)-2; i++ {
|
for i := 0; i < len(v.Up)-2; i++ {
|
||||||
@ -195,16 +198,9 @@ func (ss *ServiceSentinel) LoadStats() map[uint64]*model.ServiceItemResponse {
|
|||||||
// 刷新最新一天的数据
|
// 刷新最新一天的数据
|
||||||
ss.serviceResponseDataStoreLock.RLock()
|
ss.serviceResponseDataStoreLock.RLock()
|
||||||
defer ss.serviceResponseDataStoreLock.RUnlock()
|
defer ss.serviceResponseDataStoreLock.RUnlock()
|
||||||
ss.monthlyStatusLock.RLock()
|
ss.monthlyStatusLock.Lock()
|
||||||
defer ss.monthlyStatusLock.RUnlock()
|
defer ss.monthlyStatusLock.Unlock()
|
||||||
for k := range ss.monitors {
|
for k := range ss.monitors {
|
||||||
if ss.monthlyStatus[k] == nil {
|
|
||||||
ss.monthlyStatus[k] = &model.ServiceItemResponse{
|
|
||||||
Up: new([30]int),
|
|
||||||
Down: new([30]int),
|
|
||||||
Delay: new([30]float32),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ss.monthlyStatus[k].Monitor = ss.monitors[k]
|
ss.monthlyStatus[k].Monitor = ss.monitors[k]
|
||||||
v := ss.serviceStatusToday[k]
|
v := ss.serviceStatusToday[k]
|
||||||
ss.monthlyStatus[k].Up[29] = v.Up
|
ss.monthlyStatus[k].Up[29] = v.Up
|
||||||
|
Loading…
Reference in New Issue
Block a user