Skip to content

Commit a37fd3e

Browse files
committed
MongoDB: Add cursor Metrics
Fixes: #3840 ``` $ GOCACHE=off go test -v -tags=integration ./... === RUN TestAddNonReplStats --- PASS: TestAddNonReplStats (0.00s) === RUN TestAddReplStats --- PASS: TestAddReplStats (0.00s) === RUN TestAddWiredTigerStats --- PASS: TestAddWiredTigerStats (0.00s) === RUN TestAddShardStats --- PASS: TestAddShardStats (0.00s) === RUN TestAddShardHostStats --- PASS: TestAddShardHostStats (0.00s) === RUN TestStateTag --- PASS: TestStateTag (0.00s) === RUN TestGetDefaultTags --- PASS: TestGetDefaultTags (0.00s) === RUN TestAddDefaultStats --- PASS: TestAddDefaultStats (0.01s) PASS ok github.com/influxdata/telegraf/plugins/inputs/mongodb 0.012s ``` ``` $ ./telegraf --config ~/tele-conf --test > mongodb,host=foo,hostname=127.0.0.1:27017 active_reads=1i,active_writes=0i,commands_per_sec=4i,cursor_no_timeout=0i,cursor_pinned=0i,cursor_timed_out=0i,cursor_total=0i,deletes_per_sec=0i,flushes_per_sec=0i,getmores_per_sec=0i,inserts_per_sec=0i,jumbo_chunks=0i,net_in_bytes=639i,net_out_bytes=27185i,open_connections=2i,percent_cache_dirty=0,percent_cache_used=0,queries_per_sec=2i,queued_reads=0i,queued_writes=0i,resident_megabytes=66i,total_available=0i,total_created=0i,total_in_use=0i,total_refreshing=0i,ttl_deletes_per_sec=0i,ttl_passes_per_sec=0i,updates_per_sec=0i,vsize_megabytes=1013i,wtcache_app_threads_page_read_count=0i,wtcache_app_threads_page_read_time=0i,wtcache_app_threads_page_write_count=22i,wtcache_bytes_read_into=0i,wtcache_bytes_written_from=39880i,wtcache_current_bytes=39003i,wtcache_max_bytes_configured=7778336768i,wtcache_pages_evicted_by_app_thread=0i,wtcache_pages_queued_for_eviction=0i,wtcache_server_evicting_pages=0i,wtcache_tracked_dirty_bytes=0i,wtcache_worker_thread_evictingpages=0i 1525703381000000000 ```
1 parent d96bcac commit a37fd3e

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

plugins/inputs/mongodb/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ Error in input [mongodb]: not authorized on admin to execute command { serverSta
4848
- active_reads (integer)
4949
- active_writes (integer)
5050
- commands_per_sec (integer)
51+
- cursor_timed_out (integer)
52+
- cursor_no_timeout (integer)
53+
- cursor_pinned (integer)
54+
- cursor_total (integer)
5155
- deletes_per_sec (integer)
5256
- flushes_per_sec (integer)
5357
- getmores_per_sec (integer)
@@ -120,7 +124,7 @@ Error in input [mongodb]: not authorized on admin to execute command { serverSta
120124

121125
### Example Output:
122126
```
123-
mongodb,hostname=127.0.0.1:27017 active_reads=0i,active_writes=0i,commands_per_sec=6i,deletes_per_sec=0i,flushes_per_sec=0i,getmores_per_sec=1i,inserts_per_sec=0i,jumbo_chunks=0i,member_status="PRI",net_in_bytes=851i,net_out_bytes=23904i,open_connections=6i,percent_cache_dirty=0,percent_cache_used=0,queries_per_sec=2i,queued_reads=0i,queued_writes=0i,repl_commands_per_sec=0i,repl_deletes_per_sec=0i,repl_getmores_per_sec=0i,repl_inserts_per_sec=0i,repl_lag=0i,repl_queries_per_sec=0i,repl_updates_per_sec=0i,resident_megabytes=67i,state="PRIMARY",total_available=0i,total_created=0i,total_in_use=0i,total_refreshing=0i,ttl_deletes_per_sec=0i,ttl_passes_per_sec=0i,updates_per_sec=0i,vsize_megabytes=729i,wtcache_app_threads_page_read_count=4i,wtcache_app_threads_page_read_time=18i,wtcache_app_threads_page_write_count=6i,wtcache_bytes_read_into=10075i,wtcache_bytes_written_from=115711i,wtcache_current_bytes=86038i,wtcache_max_bytes_configured=1073741824i,wtcache_pages_evicted_by_app_thread=0i,wtcache_pages_queued_for_eviction=0i,wtcache_server_evicting_pages=0i,wtcache_tracked_dirty_bytes=0i,wtcache_worker_thread_evictingpages=0i 1522798796000000000
127+
mongodb,hostname=127.0.0.1:27017 active_reads=0i,active_writes=0i,commands_per_sec=6i,cursor_no_timeout=0i,cursor_pinned=0i,cursor_timed_out=0i,cursor_total=0i,deletes_per_sec=0i,flushes_per_sec=0i,getmores_per_sec=1i,inserts_per_sec=0i,jumbo_chunks=0i,member_status="PRI",net_in_bytes=851i,net_out_bytes=23904i,open_connections=6i,percent_cache_dirty=0,percent_cache_used=0,queries_per_sec=2i,queued_reads=0i,queued_writes=0i,repl_commands_per_sec=0i,repl_deletes_per_sec=0i,repl_getmores_per_sec=0i,repl_inserts_per_sec=0i,repl_lag=0i,repl_queries_per_sec=0i,repl_updates_per_sec=0i,resident_megabytes=67i,state="PRIMARY",total_available=0i,total_created=0i,total_in_use=0i,total_refreshing=0i,ttl_deletes_per_sec=0i,ttl_passes_per_sec=0i,updates_per_sec=0i,vsize_megabytes=729i,wtcache_app_threads_page_read_count=4i,wtcache_app_threads_page_read_time=18i,wtcache_app_threads_page_write_count=6i,wtcache_bytes_read_into=10075i,wtcache_bytes_written_from=115711i,wtcache_current_bytes=86038i,wtcache_max_bytes_configured=1073741824i,wtcache_pages_evicted_by_app_thread=0i,wtcache_pages_queued_for_eviction=0i,wtcache_server_evicting_pages=0i,wtcache_tracked_dirty_bytes=0i,wtcache_worker_thread_evictingpages=0i 1522798796000000000
124128
mongodb_db_stats,db_name=local,hostname=127.0.0.1:27017 avg_obj_size=818.625,collections=5i,data_size=6549i,index_size=86016i,indexes=4i,num_extents=0i,objects=8i,ok=1i,storage_size=118784i,type="db_stat" 1522799074000000000
125129
mongodb_shard_stats,hostname=127.0.0.1:27017,in_use=3i,available=3i,created=4i,refreshing=0i 1522799074000000000
126130
```

plugins/inputs/mongodb/mongodb_data.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ var DefaultStats = map[string]string{
4949
"open_connections": "NumConnections",
5050
"ttl_deletes_per_sec": "DeletedDocuments",
5151
"ttl_passes_per_sec": "Passes",
52+
"cursor_timed_out": "TimedOutC",
53+
"cursor_no_timeout": "NoTimeoutC",
54+
"cursor_pinned": "PinnedC",
55+
"cursor_total": "TotalC",
5256
}
5357

5458
var DefaultReplStats = map[string]string{

plugins/inputs/mongodb/mongodb_data_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ func TestAddNonReplStats(t *testing.T) {
3434
NumConnections: 0,
3535
Passes: 0,
3636
DeletedDocuments: 0,
37+
TimedOutC: 0,
38+
NoTimeoutC: 0,
39+
PinnedC: 0,
40+
TotalC: 0,
3741
},
3842
tags,
3943
)
@@ -211,6 +215,10 @@ func TestStateTag(t *testing.T) {
211215
"total_available": int64(0),
212216
"total_created": int64(0),
213217
"total_refreshing": int64(0),
218+
"cursor_timed_out": int64(0),
219+
"cursor_no_timeout": int64(0),
220+
"cursor_pinned": int64(0),
221+
"cursor_total": int64(0),
214222
}
215223
acc.AssertContainsTaggedFields(t, "mongodb", fields, stateTags)
216224
}

plugins/inputs/mongodb/mongostat.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ type OpcountStats struct {
289289

290290
// MetricsStats stores information related to metrics
291291
type MetricsStats struct {
292-
TTL *TTLStats `bson:"ttl"`
292+
TTL *TTLStats `bson:"ttl"`
293+
Cursor *CursorStats `bson:"cursor"`
293294
}
294295

295296
// TTLStats stores information related to documents with a ttl index.
@@ -298,6 +299,19 @@ type TTLStats struct {
298299
Passes int64 `bson:"passes"`
299300
}
300301

302+
// CursorStats stores information related to cursor metrics.
303+
type CursorStats struct {
304+
TimedOut int64 `bson:"timedOut"`
305+
Open *OpenCursorStats `bson:"open"`
306+
}
307+
308+
// OpenCursorStats stores information related to open cursor metrics
309+
type OpenCursorStats struct {
310+
NoTimeout int64 `bson:"noTimeout"`
311+
Pinned int64 `bson:"pinned"`
312+
Total int64 `bson:"total"`
313+
}
314+
301315
// ReadWriteLockTimes stores time spent holding read/write locks.
302316
type ReadWriteLockTimes struct {
303317
Read int64 `bson:"R"`
@@ -439,6 +453,10 @@ type StatLine struct {
439453
// TTL fields
440454
Passes, DeletedDocuments int64
441455

456+
// Cursor fields
457+
TimedOutC int64
458+
NoTimeoutC, PinnedC, TotalC int64
459+
442460
// Collection locks (3.0 mmap only)
443461
CollectionLocks *CollectionLockStatus
444462

@@ -582,9 +600,19 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
582600
returnVal.Command = diff(newStat.Opcounters.Command, oldStat.Opcounters.Command, sampleSecs)
583601
}
584602

585-
if newStat.Metrics != nil && newStat.Metrics.TTL != nil && oldStat.Metrics != nil && oldStat.Metrics.TTL != nil {
586-
returnVal.Passes = diff(newStat.Metrics.TTL.Passes, oldStat.Metrics.TTL.Passes, sampleSecs)
587-
returnVal.DeletedDocuments = diff(newStat.Metrics.TTL.DeletedDocuments, oldStat.Metrics.TTL.DeletedDocuments, sampleSecs)
603+
if newStat.Metrics != nil && oldStat.Metrics != nil {
604+
if newStat.Metrics.TTL != nil && oldStat.Metrics.TTL != nil {
605+
returnVal.Passes = diff(newStat.Metrics.TTL.Passes, oldStat.Metrics.TTL.Passes, sampleSecs)
606+
returnVal.DeletedDocuments = diff(newStat.Metrics.TTL.DeletedDocuments, oldStat.Metrics.TTL.DeletedDocuments, sampleSecs)
607+
}
608+
if newStat.Metrics.Cursor != nil && oldStat.Metrics.Cursor != nil {
609+
returnVal.TimedOutC = diff(newStat.Metrics.Cursor.TimedOut, oldStat.Metrics.Cursor.TimedOut, sampleSecs)
610+
if newStat.Metrics.Cursor.Open != nil && oldStat.Metrics.Cursor.Open != nil {
611+
returnVal.NoTimeoutC = diff(newStat.Metrics.Cursor.Open.NoTimeout, oldStat.Metrics.Cursor.Open.NoTimeout, sampleSecs)
612+
returnVal.PinnedC = diff(newStat.Metrics.Cursor.Open.Pinned, oldStat.Metrics.Cursor.Open.Pinned, sampleSecs)
613+
returnVal.TotalC = diff(newStat.Metrics.Cursor.Open.Total, oldStat.Metrics.Cursor.Open.Total, sampleSecs)
614+
}
615+
}
588616
}
589617

590618
if newStat.OpcountersRepl != nil && oldStat.OpcountersRepl != nil {

0 commit comments

Comments
 (0)