From 9106011f5810d67744386fbaef640875605fa7d1 Mon Sep 17 00:00:00 2001 From: Ayrdrie Date: Tue, 3 Jul 2018 15:09:20 -0600 Subject: [PATCH] Add mongo document and connection metrics (#4362) --- plugins/inputs/mongodb/mongodb_data.go | 51 ++++++------ plugins/inputs/mongodb/mongodb_data_test.go | 88 ++++++++++++--------- plugins/inputs/mongodb/mongostat.go | 21 ++++- 3 files changed, 98 insertions(+), 62 deletions(-) diff --git a/plugins/inputs/mongodb/mongodb_data.go b/plugins/inputs/mongodb/mongodb_data.go index 19c15bd37..0c69670d5 100644 --- a/plugins/inputs/mongodb/mongodb_data.go +++ b/plugins/inputs/mongodb/mongodb_data.go @@ -31,28 +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", + "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 56256e062..5f4dd4c2c 100644 --- a/plugins/inputs/mongodb/mongodb_data_test.go +++ b/plugins/inputs/mongodb/mongodb_data_test.go @@ -38,6 +38,13 @@ func TestAddNonReplStats(t *testing.T) { NoTimeoutC: 0, PinnedC: 0, TotalC: 0, + DeletedD: 0, + InsertedD: 0, + ReturnedD: 0, + UpdatedD: 0, + CurrentC: 0, + AvailableC: 0, + TotalCreatedC: 0, }, tags, ) @@ -182,43 +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), + "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 bb4158053..dcfd7f89d 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. @@ -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,12 @@ type StatLine struct { TimedOutC int64 NoTimeoutC, PinnedC, TotalC int64 + // Document fields + DeletedD, InsertedD, ReturnedD, UpdatedD int64 + + // Connection fields + CurrentC, AvailableC, TotalCreatedC int64 + // Collection locks (3.0 mmap only) CollectionLocks *CollectionLockStatus