Add commands stats to mongodb input plugin (#6905)
This commit is contained in:
parent
ba138b8f5b
commit
3e1c7a8948
|
@ -69,14 +69,24 @@ by running Telegraf with the `--debug` argument.
|
|||
- cursor_pinned_count (integer)
|
||||
- cursor_total_count (integer)
|
||||
- deletes (integer)
|
||||
- delete_command_total (integer)
|
||||
- delete_command_failed (integer)
|
||||
- document_deleted (integer)
|
||||
- document_inserted (integer)
|
||||
- document_returned (integer)
|
||||
- document_updated (integer)
|
||||
- find_command_total (integer)
|
||||
- find_command_failed (integer)
|
||||
- find_and_modify_command_total (integer)
|
||||
- find_and_modify_command_failed (integer)
|
||||
- flushes (integer)
|
||||
- flushes_total_time_ns (integer)
|
||||
- getmores (integer)
|
||||
- get_more_command_total (integer)
|
||||
- get_more_command_failed (integer)
|
||||
- inserts (integer)
|
||||
- insert_command_total (integer)
|
||||
- insert_command_failed (integer)
|
||||
- jumbo_chunks (integer)
|
||||
- latency_commands_count (integer)
|
||||
- latency_commands (integer)
|
||||
|
@ -110,6 +120,8 @@ by running Telegraf with the `--debug` argument.
|
|||
- ttl_deletes (integer)
|
||||
- ttl_passes (integer)
|
||||
- updates (integer)
|
||||
- update_command_total (integer)
|
||||
- update_command_failed (integer)
|
||||
- uptime_ns (integer)
|
||||
- vsize_megabytes (integer)
|
||||
- wtcache_app_threads_page_read_count (integer)
|
||||
|
|
|
@ -86,6 +86,21 @@ var DefaultStats = map[string]string{
|
|||
"connections_total_created": "TotalCreatedC",
|
||||
}
|
||||
|
||||
var DefaultCommandsStats = map[string]string{
|
||||
"delete_command_total": "DeleteCommandTotal",
|
||||
"delete_command_failed": "DeleteCommandFailed",
|
||||
"find_command_total": "FindCommandTotal",
|
||||
"find_command_failed": "FindCommandFailed",
|
||||
"find_and_modify_command_total": "FindAndModifyCommandTotal",
|
||||
"find_and_modify_command_failed": "FindAndModifyCommandFailed",
|
||||
"get_more_command_total": "GetMoreCommandTotal",
|
||||
"get_more_command_failed": "GetMoreCommandFailed",
|
||||
"insert_command_total": "InsertCommandTotal",
|
||||
"insert_command_failed": "InsertCommandFailed",
|
||||
"update_command_total": "UpdateCommandTotal",
|
||||
"update_command_failed": "UpdateCommandFailed",
|
||||
}
|
||||
|
||||
var DefaultLatencyStats = map[string]string{
|
||||
"latency_writes_count": "WriteOpsCnt",
|
||||
"latency_writes": "WriteLatency",
|
||||
|
@ -253,8 +268,10 @@ func (d *MongodbData) AddDefaultStats() {
|
|||
d.add("repl_oplog_window_sec", d.StatLine.OplogStats.TimeDiff)
|
||||
}
|
||||
|
||||
d.addStat(statLine, DefaultCommandsStats)
|
||||
d.addStat(statLine, DefaultClusterStats)
|
||||
d.addStat(statLine, DefaultShardStats)
|
||||
|
||||
if d.StatLine.StorageEngine == "mmapv1" || d.StatLine.StorageEngine == "rocksdb" {
|
||||
d.addStat(statLine, MmapStats)
|
||||
} else if d.StatLine.StorageEngine == "wiredTiger" {
|
||||
|
|
|
@ -165,6 +165,35 @@ func TestAddLatencyStats(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAddCommandsStats(t *testing.T) {
|
||||
d := NewMongodbData(
|
||||
&StatLine{
|
||||
DeleteCommandTotal: 73,
|
||||
DeleteCommandFailed: 364,
|
||||
FindCommandTotal: 113,
|
||||
FindCommandFailed: 201,
|
||||
FindAndModifyCommandTotal: 7,
|
||||
FindAndModifyCommandFailed: 55,
|
||||
GetMoreCommandTotal: 4,
|
||||
GetMoreCommandFailed: 55,
|
||||
InsertCommandTotal: 34,
|
||||
InsertCommandFailed: 65,
|
||||
UpdateCommandTotal: 23,
|
||||
UpdateCommandFailed: 6,
|
||||
},
|
||||
tags,
|
||||
)
|
||||
|
||||
var acc testutil.Accumulator
|
||||
|
||||
d.AddDefaultStats()
|
||||
d.flush(&acc)
|
||||
|
||||
for key := range DefaultCommandsStats {
|
||||
assert.True(t, acc.HasInt64Field("mongodb", key))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddShardHostStats(t *testing.T) {
|
||||
expectedHosts := []string{"hostA", "hostB"}
|
||||
hostStatLines := map[string]ShardHostStatLine{}
|
||||
|
@ -291,6 +320,18 @@ func TestStateTag(t *testing.T) {
|
|||
"connections_current": int64(0),
|
||||
"connections_available": int64(0),
|
||||
"connections_total_created": int64(0),
|
||||
"delete_command_total": int64(0),
|
||||
"delete_command_failed": int64(0),
|
||||
"find_command_total": int64(0),
|
||||
"find_command_failed": int64(0),
|
||||
"find_and_modify_command_total": int64(0),
|
||||
"find_and_modify_command_failed": int64(0),
|
||||
"get_more_command_total": int64(0),
|
||||
"get_more_command_failed": int64(0),
|
||||
"insert_command_total": int64(0),
|
||||
"insert_command_failed": int64(0),
|
||||
"update_command_total": int64(0),
|
||||
"update_command_failed": int64(0),
|
||||
}
|
||||
acc.AssertContainsTaggedFields(t, "mongodb", fields, stateTags)
|
||||
}
|
||||
|
|
|
@ -333,6 +333,7 @@ type MetricsStats struct {
|
|||
TTL *TTLStats `bson:"ttl"`
|
||||
Cursor *CursorStats `bson:"cursor"`
|
||||
Document *DocumentStats `bson:"document"`
|
||||
Commands *CommandsStats `bson:"commands"`
|
||||
}
|
||||
|
||||
// TTLStats stores information related to documents with a ttl index.
|
||||
|
@ -355,6 +356,21 @@ type DocumentStats struct {
|
|||
Updated int64 `bson:"updated"`
|
||||
}
|
||||
|
||||
// CommandsStats stores information related to document metrics.
|
||||
type CommandsStats struct {
|
||||
Delete *CommandsStatsValue `bson:"delete"`
|
||||
Find *CommandsStatsValue `bson:"find"`
|
||||
FindAndModify *CommandsStatsValue `bson:"findAndModify"`
|
||||
GetMore *CommandsStatsValue `bson:"getMore"`
|
||||
Insert *CommandsStatsValue `bson:"insert"`
|
||||
Update *CommandsStatsValue `bson:"update"`
|
||||
}
|
||||
|
||||
type CommandsStatsValue struct {
|
||||
Failed int64 `bson:"failed"`
|
||||
Total int64 `bson:"total"`
|
||||
}
|
||||
|
||||
// OpenCursorStats stores information related to open cursor metrics
|
||||
type OpenCursorStats struct {
|
||||
NoTimeout int64 `bson:"noTimeout"`
|
||||
|
@ -528,6 +544,14 @@ type StatLine struct {
|
|||
// Document fields
|
||||
DeletedD, InsertedD, ReturnedD, UpdatedD int64
|
||||
|
||||
//Commands fields
|
||||
DeleteCommandTotal, DeleteCommandFailed int64
|
||||
FindCommandTotal, FindCommandFailed int64
|
||||
FindAndModifyCommandTotal, FindAndModifyCommandFailed int64
|
||||
GetMoreCommandTotal, GetMoreCommandFailed int64
|
||||
InsertCommandTotal, InsertCommandFailed int64
|
||||
UpdateCommandTotal, UpdateCommandFailed int64
|
||||
|
||||
// Connection fields
|
||||
CurrentC, AvailableC, TotalCreatedC int64
|
||||
|
||||
|
@ -740,6 +764,33 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
|
|||
returnVal.ReturnedD = newStat.Metrics.Document.Returned
|
||||
returnVal.UpdatedD = newStat.Metrics.Document.Updated
|
||||
}
|
||||
|
||||
if newStat.Metrics.Commands != nil {
|
||||
if newStat.Metrics.Commands.Delete != nil {
|
||||
returnVal.DeleteCommandTotal = newStat.Metrics.Commands.Delete.Total
|
||||
returnVal.DeleteCommandFailed = newStat.Metrics.Commands.Delete.Failed
|
||||
}
|
||||
if newStat.Metrics.Commands.Find != nil {
|
||||
returnVal.FindCommandTotal = newStat.Metrics.Commands.Find.Total
|
||||
returnVal.FindCommandFailed = newStat.Metrics.Commands.Find.Failed
|
||||
}
|
||||
if newStat.Metrics.Commands.FindAndModify != nil {
|
||||
returnVal.FindAndModifyCommandTotal = newStat.Metrics.Commands.FindAndModify.Total
|
||||
returnVal.FindAndModifyCommandFailed = newStat.Metrics.Commands.FindAndModify.Failed
|
||||
}
|
||||
if newStat.Metrics.Commands.GetMore != nil {
|
||||
returnVal.GetMoreCommandTotal = newStat.Metrics.Commands.GetMore.Total
|
||||
returnVal.GetMoreCommandFailed = newStat.Metrics.Commands.GetMore.Failed
|
||||
}
|
||||
if newStat.Metrics.Commands.Insert != nil {
|
||||
returnVal.InsertCommandTotal = newStat.Metrics.Commands.Insert.Total
|
||||
returnVal.InsertCommandFailed = newStat.Metrics.Commands.Insert.Failed
|
||||
}
|
||||
if newStat.Metrics.Commands.Update != nil {
|
||||
returnVal.UpdateCommandTotal = newStat.Metrics.Commands.Update.Total
|
||||
returnVal.UpdateCommandFailed = newStat.Metrics.Commands.Update.Failed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if newStat.OpcountersRepl != nil && oldStat.OpcountersRepl != nil {
|
||||
|
|
Loading…
Reference in New Issue