🐛 修复区间流量统计

This commit is contained in:
naiba
2021-07-16 18:09:50 +08:00
parent f9cd5ef59f
commit c11e3e2e49
4 changed files with 16 additions and 11 deletions

View File

@@ -41,6 +41,7 @@ var (
var (
client pb.NezhaServiceClient
inited bool
updateCh = make(chan struct{}) // Agent 自动更新间隔
httpClient = &http.Client{
Transport: &http.Transport{
@@ -99,6 +100,7 @@ func run() {
var conn *grpc.ClientConn
retry := func() {
inited = false
println("Error to close connection ...")
if conn != nil {
conn.Close()
@@ -128,6 +130,7 @@ func run() {
continue
}
cancel()
inited = true
// 执行 Task
tasks, err := client.RequestTask(context.Background(), monitor.GetHost().PB())
if err != nil {
@@ -266,7 +269,8 @@ func reportState() {
defer println("reportState exit", time.Now(), "=>", err)
for {
now = time.Now()
if client != nil {
// 为了更准确的记录时段流量inited 后再上传状态信息
if client != nil && inited {
monitor.TrackNetworkSpeed()
timeOutCtx, cancel := context.WithTimeout(context.Background(), networkTimeOut)
_, err = client.ReportSystemState(timeOutCtx, monitor.GetState().PB())

View File

@@ -162,6 +162,7 @@ func loadCrons() {
}
func main() {
cleanMonitorHistory()
go rpc.ServeRPC(dao.Conf.GRPCPort)
go rpc.DispatchTask(time.Second * 30)
go dao.AlertSentinelStart()