Skip to content

Commit 19287cc

Browse files
author
chenjie
committed
update
1 parent 42dad0b commit 19287cc

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

monitor/monitor.go

+37-38
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ type callinfo struct {
4646
Callinfos map[string]map[string]*pathinfo //first key peername,second key path
4747
}
4848
type pathinfo struct {
49-
SuccessCount uint32
50-
ErrCount uint32
49+
TotalCount uint32
5150
ErrCodeCount map[int32]uint32
5251
T50 uint64 //nano second
5352
T90 uint64 //nano second
@@ -222,15 +221,15 @@ func WebClientMonitor(peername, method, path string, e error, timewaste uint64)
222221
}
223222
}
224223
atomic.AddUint32(&(pinfo.timewaste[timewasteIndex(timewaste)]), 1)
224+
atomic.AddUint32(&pinfo.TotalCount, 1)
225225
//error
226226
ee := cerror.ConvertStdError(e)
227+
pinfo.lker.Lock()
227228
if ee == nil {
228-
atomic.AddUint32(&pinfo.SuccessCount, 1)
229-
return
229+
pinfo.ErrCodeCount[0]++
230+
} else {
231+
pinfo.ErrCodeCount[ee.Code]++
230232
}
231-
atomic.AddUint32(&pinfo.ErrCount, 1)
232-
pinfo.lker.Lock()
233-
pinfo.ErrCodeCount[ee.Code]++
234233
pinfo.lker.Unlock()
235234
}
236235
func WebServerMonitor(peername, method, path string, e error, timewaste uint64) {
@@ -264,15 +263,15 @@ func WebServerMonitor(peername, method, path string, e error, timewaste uint64)
264263
}
265264
}
266265
atomic.AddUint32(&(pinfo.timewaste[timewasteIndex(timewaste)]), 1)
266+
atomic.AddUint32(&pinfo.TotalCount, 1)
267267
//error
268268
ee := cerror.ConvertStdError(e)
269+
pinfo.lker.Lock()
269270
if ee == nil {
270-
atomic.AddUint32(&pinfo.SuccessCount, 1)
271-
return
271+
pinfo.ErrCodeCount[0]++
272+
} else {
273+
pinfo.ErrCodeCount[ee.Code]++
272274
}
273-
atomic.AddUint32(&pinfo.ErrCount, 1)
274-
pinfo.lker.Lock()
275-
pinfo.ErrCodeCount[ee.Code]++
276275
pinfo.lker.Unlock()
277276
}
278277
func GrpcClientMonitor(peername, method, path string, e error, timewaste uint64) {
@@ -306,15 +305,15 @@ func GrpcClientMonitor(peername, method, path string, e error, timewaste uint64)
306305
}
307306
}
308307
atomic.AddUint32(&(pinfo.timewaste[timewasteIndex(timewaste)]), 1)
308+
atomic.AddUint32(&pinfo.TotalCount, 1)
309309
//error
310310
ee := cerror.ConvertStdError(e)
311+
pinfo.lker.Lock()
311312
if ee == nil {
312-
atomic.AddUint32(&pinfo.SuccessCount, 1)
313-
return
313+
pinfo.ErrCodeCount[0]++
314+
} else {
315+
pinfo.ErrCodeCount[ee.Code]++
314316
}
315-
atomic.AddUint32(&pinfo.ErrCount, 1)
316-
pinfo.lker.Lock()
317-
pinfo.ErrCodeCount[ee.Code]++
318317
pinfo.lker.Unlock()
319318

320319
}
@@ -349,15 +348,15 @@ func GrpcServerMonitor(peername, method, path string, e error, timewaste uint64)
349348
}
350349
}
351350
atomic.AddUint32(&(pinfo.timewaste[timewasteIndex(timewaste)]), 1)
351+
atomic.AddUint32(&pinfo.TotalCount, 1)
352352
//error
353353
ee := cerror.ConvertStdError(e)
354+
pinfo.lker.Lock()
354355
if ee == nil {
355-
atomic.AddUint32(&pinfo.SuccessCount, 1)
356-
return
356+
pinfo.ErrCodeCount[0]++
357+
} else {
358+
pinfo.ErrCodeCount[ee.Code]++
357359
}
358-
atomic.AddUint32(&pinfo.ErrCount, 1)
359-
pinfo.lker.Lock()
360-
pinfo.ErrCodeCount[ee.Code]++
361360
pinfo.lker.Unlock()
362361
}
363362
func CrpcClientMonitor(peername, method, path string, e error, timewaste uint64) {
@@ -391,15 +390,15 @@ func CrpcClientMonitor(peername, method, path string, e error, timewaste uint64)
391390
}
392391
}
393392
atomic.AddUint32(&(pinfo.timewaste[timewasteIndex(timewaste)]), 1)
393+
atomic.AddUint32(&pinfo.TotalCount, 1)
394394
//error
395395
ee := cerror.ConvertStdError(e)
396+
pinfo.lker.Lock()
396397
if ee == nil {
397-
atomic.AddUint32(&pinfo.SuccessCount, 1)
398-
return
398+
pinfo.ErrCodeCount[0]++
399+
} else {
400+
pinfo.ErrCodeCount[ee.Code]++
399401
}
400-
atomic.AddUint32(&pinfo.ErrCount, 1)
401-
pinfo.lker.Lock()
402-
pinfo.ErrCodeCount[ee.Code]++
403402
pinfo.lker.Unlock()
404403
}
405404
func CrpcServerMonitor(peername, method, path string, e error, timewaste uint64) {
@@ -433,15 +432,15 @@ func CrpcServerMonitor(peername, method, path string, e error, timewaste uint64)
433432
}
434433
}
435434
atomic.AddUint32(&(pinfo.timewaste[timewasteIndex(timewaste)]), 1)
435+
atomic.AddUint32(&pinfo.TotalCount, 1)
436436
//error
437437
ee := cerror.ConvertStdError(e)
438+
pinfo.lker.Lock()
438439
if ee == nil {
439-
atomic.AddUint32(&pinfo.SuccessCount, 1)
440-
return
440+
pinfo.ErrCodeCount[0]++
441+
} else {
442+
pinfo.ErrCodeCount[ee.Code]++
441443
}
442-
atomic.AddUint32(&pinfo.ErrCount, 1)
443-
pinfo.lker.Lock()
444-
pinfo.ErrCodeCount[ee.Code]++
445444
pinfo.lker.Unlock()
446445
}
447446

@@ -469,42 +468,42 @@ func GetMonitorInfo() *Monitor {
469468
for _, cinfo := range r.WebClientinfos {
470469
for _, peer := range cinfo.Callinfos {
471470
for _, path := range peer {
472-
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.SuccessCount+path.ErrCount)
471+
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.TotalCount)
473472
}
474473
}
475474
}
476475
for _, cinfo := range r.WebServerinfos {
477476
for _, peer := range cinfo.Callinfos {
478477
for _, path := range peer {
479-
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.SuccessCount+path.ErrCount)
478+
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.TotalCount)
480479
}
481480
}
482481
}
483482
for _, cinfo := range r.GrpcClientinfos {
484483
for _, peer := range cinfo.Callinfos {
485484
for _, path := range peer {
486-
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.SuccessCount+path.ErrCount)
485+
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.TotalCount)
487486
}
488487
}
489488
}
490489
for _, cinfo := range r.GrpcServerinfos {
491490
for _, peer := range cinfo.Callinfos {
492491
for _, path := range peer {
493-
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.SuccessCount+path.ErrCount)
492+
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.TotalCount)
494493
}
495494
}
496495
}
497496
for _, cinfo := range r.CrpcClientinfos {
498497
for _, peer := range cinfo.Callinfos {
499498
for _, path := range peer {
500-
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.SuccessCount+path.ErrCount)
499+
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.TotalCount)
501500
}
502501
}
503502
}
504503
for _, cinfo := range r.CrpcServerinfos {
505504
for _, peer := range cinfo.Callinfos {
506505
for _, path := range peer {
507-
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.SuccessCount+path.ErrCount)
506+
path.T50, path.T90, path.T99 = getT(&path.timewaste, path.maxTimewaste, path.TotalCount)
508507
}
509508
}
510509
}

0 commit comments

Comments
 (0)