This commit is contained in:
孟帅
2023-02-23 17:53:04 +08:00
parent 7cf1b8ce8e
commit 61d0988d2c
402 changed files with 18340 additions and 35547 deletions

View File

@@ -1,6 +1,6 @@
// Package crons
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2022 HotGo CLI
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
@@ -72,7 +72,7 @@ func StartALL(sysCron []*entity.SysCron) error {
)
if len(sysCron) == 0 {
g.Log().Info(ct, "没有可用的定时任务")
g.Log().Debug(ct, "no scheduled task is available.")
return nil
}

View File

@@ -1,79 +0,0 @@
// Package crons
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2022 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package crons
import (
"context"
"github.com/gogf/gf/v2/os/gtime"
"github.com/shirou/gopsutil/load"
"github.com/shirou/gopsutil/net"
"hotgo/internal/global"
"hotgo/internal/model"
"hotgo/utility/format"
"runtime"
"sync"
)
func init() {
cronList = append(cronList, Monitor)
}
// Monitor 监控
var Monitor = &cMonitor{name: "monitor"}
type cMonitor struct {
name string
sync.RWMutex
}
func (c *cMonitor) GetName() string {
return c.name
}
// Execute 执行任务
func (c *cMonitor) Execute(ctx context.Context) {
c.Lock()
defer c.Unlock()
c.NetIO()
c.loadAvg()
}
func (c *cMonitor) loadAvg() {
pl, _ := load.Avg()
counter := model.LoadAvgStats{
Time: gtime.Now(),
Avg: pl.Load1,
Ratio: pl.Load1 / (float64(runtime.NumCPU()) * 2) * 100,
}
global.MonitorData.LoadAvg = append(global.MonitorData.LoadAvg, &counter)
if len(global.MonitorData.LoadAvg) > 10 {
global.MonitorData.LoadAvg = append(global.MonitorData.LoadAvg[:0], global.MonitorData.LoadAvg[(1):]...)
}
}
func (c *cMonitor) NetIO() {
var counter model.NetIOCounters
ni, _ := net.IOCounters(true)
counter.Time = gtime.Now()
for _, v := range ni {
counter.BytesSent += v.BytesSent
counter.BytesRecv += v.BytesRecv
}
if len(global.MonitorData.NetIO) > 0 {
lastNetIO := global.MonitorData.NetIO[len(global.MonitorData.NetIO)-1]
sub := counter.Time.Sub(lastNetIO.Time).Seconds()
counter.Down = format.Round2Float64((float64(counter.BytesRecv - lastNetIO.BytesRecv)) / sub)
counter.UP = format.Round2Float64((float64(counter.BytesSent - lastNetIO.BytesSent)) / sub)
}
global.MonitorData.NetIO = append(global.MonitorData.NetIO, &counter)
if len(global.MonitorData.NetIO) > 10 {
global.MonitorData.NetIO = append(global.MonitorData.NetIO[:0], global.MonitorData.NetIO[(1):]...)
}
}

View File

@@ -1,6 +1,6 @@
// Package crons
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2022 HotGo CLI
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
@@ -16,7 +16,7 @@ func init() {
cronList = append(cronList, Test)
}
// Test 测试任务
// Test 测试任务(无参数)
var Test = &cTest{name: "test"}
type cTest struct {

View File

@@ -1,6 +1,6 @@
// Package crons
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2022 HotGo CLI
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
@@ -17,7 +17,7 @@ func init() {
cronList = append(cronList, Test2)
}
// Test2 测试2任务
// Test2 测试2任务(带参数)
var Test2 = &cTest2{name: "test2"}
type cTest2 struct {