Add shard server stats to the mongodb input plugin (#3808)

This commit is contained in:
Jake Champlin 2018-02-20 16:55:56 -05:00 committed by Daniel Nelson
parent 8147d60973
commit 18aef35c58
5 changed files with 68 additions and 1 deletions

View File

@ -49,6 +49,10 @@ and create a single measurement containing values e.g.
* resident_megabytes * resident_megabytes
* updates_per_sec * updates_per_sec
* vsize_megabytes * vsize_megabytes
* total_in_use
* total_available
* total_created
* total_refreshing
* ttl_deletes_per_sec * ttl_deletes_per_sec
* ttl_passes_per_sec * ttl_passes_per_sec
* repl_lag * repl_lag

View File

@ -66,6 +66,13 @@ var DefaultClusterStats = map[string]string{
"jumbo_chunks": "JumboChunksCount", "jumbo_chunks": "JumboChunksCount",
} }
var DefaultShardStats = map[string]string{
"total_in_use": "TotalInUse",
"total_available": "TotalAvailable",
"total_created": "TotalCreated",
"total_refreshing": "TotalRefreshing",
}
var MmapStats = map[string]string{ var MmapStats = map[string]string{
"mapped_megabytes": "Mapped", "mapped_megabytes": "Mapped",
"non-mapped_megabytes": "NonMapped", "non-mapped_megabytes": "NonMapped",
@ -127,6 +134,7 @@ func (d *MongodbData) AddDefaultStats() {
d.addStat(statLine, DefaultReplStats) d.addStat(statLine, DefaultReplStats)
} }
d.addStat(statLine, DefaultClusterStats) d.addStat(statLine, DefaultClusterStats)
d.addStat(statLine, DefaultShardStats)
if d.StatLine.StorageEngine == "mmapv1" { if d.StatLine.StorageEngine == "mmapv1" {
d.addStat(statLine, MmapStats) d.addStat(statLine, MmapStats)
} else if d.StatLine.StorageEngine == "wiredTiger" { } else if d.StatLine.StorageEngine == "wiredTiger" {

View File

@ -99,6 +99,27 @@ func TestAddWiredTigerStats(t *testing.T) {
} }
} }
func TestAddShardStats(t *testing.T) {
d := NewMongodbData(
&StatLine{
TotalInUse: 0,
TotalAvailable: 0,
TotalCreated: 0,
TotalRefreshing: 0,
},
tags,
)
var acc testutil.Accumulator
d.AddDefaultStats()
d.flush(&acc)
for key, _ := range DefaultShardStats {
assert.True(t, acc.HasInt64Field("mongodb", key))
}
}
func TestStateTag(t *testing.T) { func TestStateTag(t *testing.T) {
d := NewMongodbData( d := NewMongodbData(
&StatLine{ &StatLine{
@ -147,6 +168,10 @@ func TestStateTag(t *testing.T) {
"ttl_deletes_per_sec": int64(0), "ttl_deletes_per_sec": int64(0),
"ttl_passes_per_sec": int64(0), "ttl_passes_per_sec": int64(0),
"jumbo_chunks": int64(0), "jumbo_chunks": int64(0),
"total_in_use": int64(0),
"total_available": int64(0),
"total_created": int64(0),
"total_refreshing": int64(0),
} }
acc.AssertContainsTaggedFields(t, "mongodb", fields, stateTags) acc.AssertContainsTaggedFields(t, "mongodb", fields, stateTags)
} }

View File

@ -55,8 +55,18 @@ func (s *Server) gatherData(acc telegraf.Accumulator, gatherDbStats bool) error
JumboChunksCount: int64(jumbo_chunks), JumboChunksCount: int64(jumbo_chunks),
} }
result_db_stats := &DbStats{} resultShards := &ShardStats{}
err = s.Session.DB("admin").Run(bson.D{
{
Name: "shardConnPoolStats",
Value: 1,
},
}, &resultShards)
if err != nil {
log.Println("E! Error getting database shard stats (" + err.Error() + ")")
}
result_db_stats := &DbStats{}
if gatherDbStats == true { if gatherDbStats == true {
names := []string{} names := []string{}
names, err = s.Session.DatabaseNames() names, err = s.Session.DatabaseNames()
@ -88,6 +98,7 @@ func (s *Server) gatherData(acc telegraf.Accumulator, gatherDbStats bool) error
ReplSetStatus: result_repl, ReplSetStatus: result_repl,
ClusterStatus: result_cluster, ClusterStatus: result_cluster,
DbStats: result_db_stats, DbStats: result_db_stats,
ShardStats: resultShards,
} }
defer func() { defer func() {

View File

@ -34,6 +34,7 @@ type MongoStatus struct {
ReplSetStatus *ReplSetStatus ReplSetStatus *ReplSetStatus
ClusterStatus *ClusterStatus ClusterStatus *ClusterStatus
DbStats *DbStats DbStats *DbStats
ShardStats *ShardStats
} }
type ServerStatus struct { type ServerStatus struct {
@ -116,6 +117,14 @@ type WiredTiger struct {
Cache CacheStats `bson:"cache"` Cache CacheStats `bson:"cache"`
} }
// ShardStats stores information from shardConnPoolStats.
type ShardStats struct {
TotalInUse int64 `bson:"totalInUse"`
TotalAvailable int64 `bson:"totalAvailable"`
TotalCreated int64 `bson:"totalCreated"`
TotalRefreshing int64 `bson:"totalRefreshing"`
}
type ConcurrentTransactions struct { type ConcurrentTransactions struct {
Write ConcurrentTransStats `bson:"write"` Write ConcurrentTransStats `bson:"write"`
Read ConcurrentTransStats `bson:"read"` Read ConcurrentTransStats `bson:"read"`
@ -450,6 +459,9 @@ type StatLine struct {
// DB stats field // DB stats field
DbStatsLines []DbStatLine DbStatsLines []DbStatLine
// Shard stats
TotalInUse, TotalAvailable, TotalCreated, TotalRefreshing int64
} }
type DbStatLine struct { type DbStatLine struct {
@ -783,5 +795,12 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
returnVal.DbStatsLines = append(returnVal.DbStatsLines, *dbStatLine) returnVal.DbStatsLines = append(returnVal.DbStatsLines, *dbStatLine)
} }
// Set shard stats
newShardStats := *newMongo.ShardStats
returnVal.TotalInUse = newShardStats.TotalInUse
returnVal.TotalAvailable = newShardStats.TotalAvailable
returnVal.TotalCreated = newShardStats.TotalCreated
returnVal.TotalRefreshing = newShardStats.TotalRefreshing
return returnVal return returnVal
} }