发送监控流量
()
| 15 | |
| 16 | // 发送监控流量 |
| 17 | func init() { |
| 18 | if !teaconst.IsMain { |
| 19 | return |
| 20 | } |
| 21 | |
| 22 | events.On(events.EventStart, func() { |
| 23 | var ticker = time.NewTicker(1 * time.Minute) |
| 24 | goman.New(func() { |
| 25 | for range ticker.C { |
| 26 | // 加入到数据队列中 |
| 27 | var inBytes = atomic.LoadUint64(&teaconst.InTrafficBytes) |
| 28 | atomic.StoreUint64(&teaconst.InTrafficBytes, 0) // 重置数据 |
| 29 | if inBytes > 0 { |
| 30 | monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemTrafficIn, maps.Map{ |
| 31 | "total": inBytes, |
| 32 | }) |
| 33 | } |
| 34 | |
| 35 | var outBytes = atomic.LoadUint64(&teaconst.OutTrafficBytes) |
| 36 | atomic.StoreUint64(&teaconst.OutTrafficBytes, 0) // 重置数据 |
| 37 | if outBytes > 0 { |
| 38 | monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemTrafficOut, maps.Map{ |
| 39 | "total": outBytes, |
| 40 | }) |
| 41 | } |
| 42 | } |
| 43 | }) |
| 44 | }) |
| 45 | } |