123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package pinglog
- import (
- "github.com/gogf/gf/v2/database/gdb"
- "golang.org/x/net/context"
- "nodeMonitor/internal/dao"
- "nodeMonitor/internal/model"
- "nodeMonitor/internal/model/do"
- "nodeMonitor/internal/service"
- )
- type (
- sPing struct{}
- )
- func init() {
- service.RegisterPing(New())
- }
- func New() *sPing {
- return &sPing{}
- }
- // Create 创建延迟日志
- func (c *sPing) Create(ctx context.Context, ping model.PingSt, host string) error {
- return dao.Pinglog.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
- _, err := dao.Pinglog.Ctx(ctx).Data(do.Pinglog{
- Maxdelay: ping.MaxDelay,
- Mindelay: ping.MinDelay,
- Avgdelay: ping.AvgDelay,
- Losspk: ping.AvgDelay,
- Host: host,
- }).Insert()
- return err
- })
- }
- // GetStatus 查询节点状态
- // SELECT * FROM pinglog WHERE DATE_SUB(create_at,INTERVAL 10 MINUTE) <= NOW() and avgdelay = 0 and losspk >= 0 and maxdelay = 0 and `host` = 'kdvkr-04.xyz'
- func (c *sPing) GetStatus(ctx context.Context) {
- //查询的数据超过3次就是不ok了
- }
|