add recover

This commit is contained in:
Ulric Qin 2022-04-15 17:36:33 +08:00
parent e40c5ae3d2
commit 0d09cfa89c
1 changed files with 8 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package diskio
import (
"fmt"
"log"
"strings"
"time"
"flashcat.cloud/categraf/config"
@ -84,13 +85,13 @@ func (d *DiskIO) Gather(queue chan *types.Sample) {
var samples []*types.Sample
defer func() {
// if r := recover(); r != nil {
// if strings.Contains(fmt.Sprint(r), "closed channel") {
// return
// } else {
// log.Println("E! gather metrics panic:", r)
// }
// }
if r := recover(); r != nil {
if strings.Contains(fmt.Sprint(r), "closed channel") {
return
} else {
log.Println("E! gather metrics panic:", r)
}
}
now := time.Now()
for i := 0; i < len(samples); i++ {