From 5bee2cd107644df79cdb3569f2d9a0d6c91ee6ec Mon Sep 17 00:00:00 2001 From: Greg Linton Date: Fri, 29 Jun 2018 17:30:13 -0600 Subject: [PATCH 1/2] Add document metrics Resolves #4297 --- plugins/inputs/mongodb/mongodb_data.go | 4 ++++ plugins/inputs/mongodb/mongodb_data_test.go | 8 ++++++++ plugins/inputs/mongodb/mongostat.go | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/mongodb/mongodb_data.go b/plugins/inputs/mongodb/mongodb_data.go index 19c15bd37de8e..303d7d7fc9adb 100644 --- a/plugins/inputs/mongodb/mongodb_data.go +++ b/plugins/inputs/mongodb/mongodb_data.go @@ -53,6 +53,10 @@ var DefaultStats = map[string]string{ "cursor_no_timeout": "NoTimeoutC", "cursor_pinned": "PinnedC", "cursor_total": "TotalC", + "document_deleted": "DeletedD", + "document_inserted": "InsertedD", + "document_returned": "ReturnedD", + "document_updated": "UpdatedD", } var DefaultReplStats = map[string]string{ diff --git a/plugins/inputs/mongodb/mongodb_data_test.go b/plugins/inputs/mongodb/mongodb_data_test.go index 56256e062480b..22f31e26f78e4 100644 --- a/plugins/inputs/mongodb/mongodb_data_test.go +++ b/plugins/inputs/mongodb/mongodb_data_test.go @@ -38,6 +38,10 @@ func TestAddNonReplStats(t *testing.T) { NoTimeoutC: 0, PinnedC: 0, TotalC: 0, + DeletedD: 0, + InsertedD: 0, + ReturnedD: 0, + UpdatedD: 0, }, tags, ) @@ -219,6 +223,10 @@ func TestStateTag(t *testing.T) { "cursor_no_timeout": int64(0), "cursor_pinned": int64(0), "cursor_total": int64(0), + "document_deleted": int64(0), + "document_inserted": int64(0), + "document_returned": int64(0), + "document_updated": int64(0), } acc.AssertContainsTaggedFields(t, "mongodb", fields, stateTags) } diff --git a/plugins/inputs/mongodb/mongostat.go b/plugins/inputs/mongodb/mongostat.go index bb415805322f1..b9c1895f0cf9f 100644 --- a/plugins/inputs/mongodb/mongostat.go +++ b/plugins/inputs/mongodb/mongostat.go @@ -289,8 +289,9 @@ type OpcountStats struct { // MetricsStats stores information related to metrics type MetricsStats struct { - TTL *TTLStats `bson:"ttl"` - Cursor *CursorStats `bson:"cursor"` + TTL *TTLStats `bson:"ttl"` + Cursor *CursorStats `bson:"cursor"` + Document *DocumentStats `bson:"document"` } // TTLStats stores information related to documents with a ttl index. @@ -305,6 +306,14 @@ type CursorStats struct { Open *OpenCursorStats `bson:"open"` } +// DocumentStats stores information related to document metrics. +type DocumentStats struct { + Deleted int64 `bson:"deleted"` + Inserted int64 `bson:"inserted"` + Returned int64 `bson:"returned"` + Updated int64 `bson:"updated"` +} + // OpenCursorStats stores information related to open cursor metrics type OpenCursorStats struct { NoTimeout int64 `bson:"noTimeout"` @@ -457,6 +466,9 @@ type StatLine struct { TimedOutC int64 NoTimeoutC, PinnedC, TotalC int64 + // Document fields + DeletedD, InsertedD, ReturnedD, UpdatedD int64 + // Collection locks (3.0 mmap only) CollectionLocks *CollectionLockStatus From cffdcc9326b8203c6661eb85841fecc68c4025ac Mon Sep 17 00:00:00 2001 From: Ayrdrie Palmer Date: Fri, 29 Jun 2018 17:51:16 -0600 Subject: [PATCH 2/2] Add Connection Metrics for MongoDB serverStatus Resolves #4329 --- plugins/inputs/mongodb/mongodb_data.go | 55 +++++++------ plugins/inputs/mongodb/mongodb_data_test.go | 88 +++++++++++---------- plugins/inputs/mongodb/mongostat.go | 5 +- 3 files changed, 80 insertions(+), 68 deletions(-) diff --git a/plugins/inputs/mongodb/mongodb_data.go b/plugins/inputs/mongodb/mongodb_data.go index 303d7d7fc9adb..0c69670d50f25 100644 --- a/plugins/inputs/mongodb/mongodb_data.go +++ b/plugins/inputs/mongodb/mongodb_data.go @@ -31,32 +31,35 @@ func NewMongodbData(statLine *StatLine, tags map[string]string) *MongodbData { } var DefaultStats = map[string]string{ - "inserts_per_sec": "Insert", - "queries_per_sec": "Query", - "updates_per_sec": "Update", - "deletes_per_sec": "Delete", - "getmores_per_sec": "GetMore", - "commands_per_sec": "Command", - "flushes_per_sec": "Flushes", - "vsize_megabytes": "Virtual", - "resident_megabytes": "Resident", - "queued_reads": "QueuedReaders", - "queued_writes": "QueuedWriters", - "active_reads": "ActiveReaders", - "active_writes": "ActiveWriters", - "net_in_bytes": "NetIn", - "net_out_bytes": "NetOut", - "open_connections": "NumConnections", - "ttl_deletes_per_sec": "DeletedDocuments", - "ttl_passes_per_sec": "Passes", - "cursor_timed_out": "TimedOutC", - "cursor_no_timeout": "NoTimeoutC", - "cursor_pinned": "PinnedC", - "cursor_total": "TotalC", - "document_deleted": "DeletedD", - "document_inserted": "InsertedD", - "document_returned": "ReturnedD", - "document_updated": "UpdatedD", + "inserts_per_sec": "Insert", + "queries_per_sec": "Query", + "updates_per_sec": "Update", + "deletes_per_sec": "Delete", + "getmores_per_sec": "GetMore", + "commands_per_sec": "Command", + "flushes_per_sec": "Flushes", + "vsize_megabytes": "Virtual", + "resident_megabytes": "Resident", + "queued_reads": "QueuedReaders", + "queued_writes": "QueuedWriters", + "active_reads": "ActiveReaders", + "active_writes": "ActiveWriters", + "net_in_bytes": "NetIn", + "net_out_bytes": "NetOut", + "open_connections": "NumConnections", + "ttl_deletes_per_sec": "DeletedDocuments", + "ttl_passes_per_sec": "Passes", + "cursor_timed_out": "TimedOutC", + "cursor_no_timeout": "NoTimeoutC", + "cursor_pinned": "PinnedC", + "cursor_total": "TotalC", + "document_deleted": "DeletedD", + "document_inserted": "InsertedD", + "document_returned": "ReturnedD", + "document_updated": "UpdatedD", + "connections_current": "CurrentC", + "connections_available": "AvailableC", + "connections_total_created": "TotalCreatedC", } var DefaultReplStats = map[string]string{ diff --git a/plugins/inputs/mongodb/mongodb_data_test.go b/plugins/inputs/mongodb/mongodb_data_test.go index 22f31e26f78e4..5f4dd4c2c3ce3 100644 --- a/plugins/inputs/mongodb/mongodb_data_test.go +++ b/plugins/inputs/mongodb/mongodb_data_test.go @@ -42,6 +42,9 @@ func TestAddNonReplStats(t *testing.T) { InsertedD: 0, ReturnedD: 0, UpdatedD: 0, + CurrentC: 0, + AvailableC: 0, + TotalCreatedC: 0, }, tags, ) @@ -186,47 +189,50 @@ func TestStateTag(t *testing.T) { d.AddDefaultStats() d.flush(&acc) fields := map[string]interface{}{ - "active_reads": int64(0), - "active_writes": int64(0), - "commands_per_sec": int64(0), - "deletes_per_sec": int64(0), - "flushes_per_sec": int64(0), - "getmores_per_sec": int64(0), - "inserts_per_sec": int64(0), - "member_status": "PRI", - "state": "PRIMARY", - "net_in_bytes": int64(0), - "net_out_bytes": int64(0), - "open_connections": int64(0), - "queries_per_sec": int64(0), - "queued_reads": int64(0), - "queued_writes": int64(0), - "repl_commands_per_sec": int64(0), - "repl_deletes_per_sec": int64(0), - "repl_getmores_per_sec": int64(0), - "repl_inserts_per_sec": int64(0), - "repl_queries_per_sec": int64(0), - "repl_updates_per_sec": int64(0), - "repl_lag": int64(0), - "repl_oplog_window_sec": int64(0), - "resident_megabytes": int64(0), - "updates_per_sec": int64(0), - "vsize_megabytes": int64(0), - "ttl_deletes_per_sec": 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_no_timeout": int64(0), - "cursor_pinned": int64(0), - "cursor_total": int64(0), - "document_deleted": int64(0), - "document_inserted": int64(0), - "document_returned": int64(0), - "document_updated": int64(0), + "active_reads": int64(0), + "active_writes": int64(0), + "commands_per_sec": int64(0), + "deletes_per_sec": int64(0), + "flushes_per_sec": int64(0), + "getmores_per_sec": int64(0), + "inserts_per_sec": int64(0), + "member_status": "PRI", + "state": "PRIMARY", + "net_in_bytes": int64(0), + "net_out_bytes": int64(0), + "open_connections": int64(0), + "queries_per_sec": int64(0), + "queued_reads": int64(0), + "queued_writes": int64(0), + "repl_commands_per_sec": int64(0), + "repl_deletes_per_sec": int64(0), + "repl_getmores_per_sec": int64(0), + "repl_inserts_per_sec": int64(0), + "repl_queries_per_sec": int64(0), + "repl_updates_per_sec": int64(0), + "repl_lag": int64(0), + "repl_oplog_window_sec": int64(0), + "resident_megabytes": int64(0), + "updates_per_sec": int64(0), + "vsize_megabytes": int64(0), + "ttl_deletes_per_sec": 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_no_timeout": int64(0), + "cursor_pinned": int64(0), + "cursor_total": 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), } acc.AssertContainsTaggedFields(t, "mongodb", fields, stateTags) } diff --git a/plugins/inputs/mongodb/mongostat.go b/plugins/inputs/mongodb/mongostat.go index b9c1895f0cf9f..dcfd7f89d5bba 100644 --- a/plugins/inputs/mongodb/mongostat.go +++ b/plugins/inputs/mongodb/mongostat.go @@ -225,7 +225,7 @@ type FlushStats struct { type ConnectionStats struct { Current int64 `bson:"current"` Available int64 `bson:"available"` - TotalCreated int64 `bson:"totalCreated"` + TotalCreated int64 `bson:"total_created"` } // DurTiming stores information related to journaling. @@ -469,6 +469,9 @@ type StatLine struct { // Document fields DeletedD, InsertedD, ReturnedD, UpdatedD int64 + // Connection fields + CurrentC, AvailableC, TotalCreatedC int64 + // Collection locks (3.0 mmap only) CollectionLocks *CollectionLockStatus