Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commands stats to mongodb plugin. #6905

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions plugins/inputs/mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,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)
Expand Down Expand Up @@ -109,6 +119,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)
Expand Down
17 changes: 17 additions & 0 deletions plugins/inputs/mongodb/mongodb_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -249,8 +264,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" {
Expand Down
173 changes: 107 additions & 66 deletions plugins/inputs/mongodb/mongodb_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -223,72 +252,84 @@ func TestStateTag(t *testing.T) {
d.AddDefaultStats()
d.flush(&acc)
fields := map[string]interface{}{
"active_reads": int64(0),
"active_writes": int64(0),
"commands": int64(0),
"commands_per_sec": int64(0),
"deletes": int64(0),
"deletes_per_sec": int64(0),
"flushes": int64(0),
"flushes_per_sec": int64(0),
"flushes_total_time_ns": int64(0),
"getmores": int64(0),
"getmores_per_sec": int64(0),
"inserts": int64(0),
"inserts_per_sec": int64(0),
"member_status": "PRI",
"state": "PRIMARY",
"net_in_bytes_count": int64(0),
"net_in_bytes": int64(0),
"net_out_bytes_count": int64(0),
"net_out_bytes": int64(0),
"open_connections": int64(0),
"queries": int64(0),
"queries_per_sec": int64(0),
"queued_reads": int64(0),
"queued_writes": int64(0),
"repl_commands": int64(0),
"repl_commands_per_sec": int64(0),
"repl_deletes": int64(0),
"repl_deletes_per_sec": int64(0),
"repl_getmores": int64(0),
"repl_getmores_per_sec": int64(0),
"repl_inserts": int64(0),
"repl_inserts_per_sec": int64(0),
"repl_queries": int64(0),
"repl_queries_per_sec": int64(0),
"repl_updates": int64(0),
"repl_updates_per_sec": int64(0),
"repl_lag": int64(0),
"resident_megabytes": int64(0),
"updates": int64(0),
"updates_per_sec": int64(0),
"uptime_ns": int64(0),
"vsize_megabytes": int64(0),
"ttl_deletes": int64(0),
"ttl_deletes_per_sec": int64(0),
"ttl_passes": int64(0),
"ttl_passes_per_sec": int64(0),
"jumbo_chunks": int64(0),
"total_in_use": int64(0),
"total_available": int64(0),
"total_created": int64(0),
"total_refreshing": int64(0),
"cursor_timed_out": int64(0),
"cursor_timed_out_count": int64(0),
"cursor_no_timeout": int64(0),
"cursor_no_timeout_count": int64(0),
"cursor_pinned": int64(0),
"cursor_pinned_count": int64(0),
"cursor_total": int64(0),
"cursor_total_count": int64(0),
"document_deleted": int64(0),
"document_inserted": int64(0),
"document_returned": int64(0),
"document_updated": int64(0),
"connections_current": int64(0),
"connections_available": int64(0),
"connections_total_created": int64(0),
"active_reads": int64(0),
"active_writes": int64(0),
"commands": int64(0),
"commands_per_sec": int64(0),
"deletes": int64(0),
"deletes_per_sec": int64(0),
"flushes": int64(0),
"flushes_per_sec": int64(0),
"flushes_total_time_ns": int64(0),
"getmores": int64(0),
"getmores_per_sec": int64(0),
"inserts": int64(0),
"inserts_per_sec": int64(0),
"member_status": "PRI",
"state": "PRIMARY",
"net_in_bytes_count": int64(0),
"net_in_bytes": int64(0),
"net_out_bytes_count": int64(0),
"net_out_bytes": int64(0),
"open_connections": int64(0),
"queries": int64(0),
"queries_per_sec": int64(0),
"queued_reads": int64(0),
"queued_writes": int64(0),
"repl_commands": int64(0),
"repl_commands_per_sec": int64(0),
"repl_deletes": int64(0),
"repl_deletes_per_sec": int64(0),
"repl_getmores": int64(0),
"repl_getmores_per_sec": int64(0),
"repl_inserts": int64(0),
"repl_inserts_per_sec": int64(0),
"repl_queries": int64(0),
"repl_queries_per_sec": int64(0),
"repl_updates": int64(0),
"repl_updates_per_sec": int64(0),
"repl_lag": int64(0),
"resident_megabytes": int64(0),
"updates": int64(0),
"updates_per_sec": int64(0),
"uptime_ns": int64(0),
"vsize_megabytes": int64(0),
"ttl_deletes": int64(0),
"ttl_deletes_per_sec": int64(0),
"ttl_passes": int64(0),
"ttl_passes_per_sec": int64(0),
"jumbo_chunks": int64(0),
"total_in_use": int64(0),
"total_available": int64(0),
"total_created": int64(0),
"total_refreshing": int64(0),
"cursor_timed_out": int64(0),
"cursor_timed_out_count": int64(0),
"cursor_no_timeout": int64(0),
"cursor_no_timeout_count": int64(0),
"cursor_pinned": int64(0),
"cursor_pinned_count": int64(0),
"cursor_total": int64(0),
"cursor_total_count": int64(0),
"document_deleted": int64(0),
"document_inserted": int64(0),
"document_returned": int64(0),
"document_updated": int64(0),
"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)
}
51 changes: 51 additions & 0 deletions plugins/inputs/mongodb/mongostat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"`
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down