pinglog.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package pinglog
  2. import (
  3. "github.com/gogf/gf/v2/database/gdb"
  4. "golang.org/x/net/context"
  5. "nodeMonitor/internal/dao"
  6. "nodeMonitor/internal/model"
  7. "nodeMonitor/internal/model/do"
  8. "nodeMonitor/internal/service"
  9. )
  10. type (
  11. sPing struct{}
  12. )
  13. func init() {
  14. service.RegisterPing(New())
  15. }
  16. func New() *sPing {
  17. return &sPing{}
  18. }
  19. // Create 创建延迟日志
  20. func (c *sPing) Create(ctx context.Context, ping model.PingSt, host string) error {
  21. return dao.Pinglog.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
  22. _, err := dao.Pinglog.Ctx(ctx).Data(do.Pinglog{
  23. Maxdelay: ping.MaxDelay,
  24. Mindelay: ping.MinDelay,
  25. Avgdelay: ping.AvgDelay,
  26. Losspk: ping.AvgDelay,
  27. Host: host,
  28. }).Insert()
  29. return err
  30. })
  31. }
  32. // GetStatus 查询节点状态
  33. // 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'
  34. func (c *sPing) GetStatus(ctx context.Context) {
  35. //查询的数据超过3次就是不ok了
  36. }