Fix panic in mongodb input if ShardStats is nil (#6680)

This commit is contained in:
alan7yg 2019-11-20 02:52:48 +08:00 committed by Daniel Nelson
parent 7ff6ec1963
commit a66b6729e9
1 changed files with 16 additions and 14 deletions

View File

@ -983,21 +983,23 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
}
// Set shard stats
newShardStats := *newMongo.ShardStats
returnVal.TotalInUse = newShardStats.TotalInUse
returnVal.TotalAvailable = newShardStats.TotalAvailable
returnVal.TotalCreated = newShardStats.TotalCreated
returnVal.TotalRefreshing = newShardStats.TotalRefreshing
returnVal.ShardHostStatsLines = map[string]ShardHostStatLine{}
for host, stats := range newShardStats.Hosts {
shardStatLine := &ShardHostStatLine{
InUse: stats.InUse,
Available: stats.Available,
Created: stats.Created,
Refreshing: stats.Refreshing,
}
if newMongo.ShardStats != nil {
newShardStats := *newMongo.ShardStats
returnVal.TotalInUse = newShardStats.TotalInUse
returnVal.TotalAvailable = newShardStats.TotalAvailable
returnVal.TotalCreated = newShardStats.TotalCreated
returnVal.TotalRefreshing = newShardStats.TotalRefreshing
returnVal.ShardHostStatsLines = map[string]ShardHostStatLine{}
for host, stats := range newShardStats.Hosts {
shardStatLine := &ShardHostStatLine{
InUse: stats.InUse,
Available: stats.Available,
Created: stats.Created,
Refreshing: stats.Refreshing,
}
returnVal.ShardHostStatsLines[host] = *shardStatLine
returnVal.ShardHostStatsLines[host] = *shardStatLine
}
}
return returnVal