Skip to content

Commit aba269e

Browse files
phenomenesdanielnelson
authored andcommitted
Add extra wired tiger cache metrics to mongodb input (#3281)
1 parent f673501 commit aba269e

File tree

3 files changed

+72
-10
lines changed

3 files changed

+72
-10
lines changed

plugins/inputs/mongodb/mongodb_data.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ var WiredTigerStats = map[string]string{
7777
"percent_cache_used": "CacheUsedPercent",
7878
}
7979

80+
var WiredTigerExtStats = map[string]string{
81+
"wtcache_tracked_dirty_bytes": "TrackedDirtyBytes",
82+
"wtcache_current_bytes": "CurrentCachedBytes",
83+
"wtcache_max_bytes_configured": "MaxBytesConfigured",
84+
"wtcache_app_threads_page_read_count": "AppThreadsPageReadCount",
85+
"wtcache_app_threads_page_read_time": "AppThreadsPageReadTime",
86+
"wtcache_app_threads_page_write_count": "AppThreadsPageWriteCount",
87+
"wtcache_bytes_written_from": "BytesWrittenFrom",
88+
"wtcache_bytes_read_into": "BytesReadInto",
89+
"wtcache_pages_evicted_by_app_thread": "PagesEvictedByAppThread",
90+
"wtcache_pages_queued_for_eviction": "PagesQueuedForEviction",
91+
"wtcache_server_evicting_pages": "ServerEvictingPages",
92+
"wtcache_worker_thread_evictingpages": "WorkerThreadEvictingPages",
93+
}
94+
8095
var DbDataStats = map[string]string{
8196
"collections": "Collections",
8297
"objects": "Objects",
@@ -121,13 +136,11 @@ func (d *MongodbData) AddDefaultStats() {
121136
floatVal, _ := strconv.ParseFloat(percentVal, 64)
122137
d.add(key, floatVal)
123138
}
139+
d.addStat(statLine, WiredTigerExtStats)
124140
}
125141
}
126142

127-
func (d *MongodbData) addStat(
128-
statLine reflect.Value,
129-
stats map[string]string,
130-
) {
143+
func (d *MongodbData) addStat(statLine reflect.Value, stats map[string]string) {
131144
for key, value := range stats {
132145
val := statLine.FieldByName(value).Interface()
133146
d.add(key, val)

plugins/inputs/mongodb/mongodb_data_test.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,21 @@ func TestAddReplStats(t *testing.T) {
7070
func TestAddWiredTigerStats(t *testing.T) {
7171
d := NewMongodbData(
7272
&StatLine{
73-
StorageEngine: "wiredTiger",
74-
CacheDirtyPercent: 0,
75-
CacheUsedPercent: 0,
73+
StorageEngine: "wiredTiger",
74+
CacheDirtyPercent: 0,
75+
CacheUsedPercent: 0,
76+
TrackedDirtyBytes: 0,
77+
CurrentCachedBytes: 0,
78+
MaxBytesConfigured: 0,
79+
AppThreadsPageReadCount: 0,
80+
AppThreadsPageReadTime: 0,
81+
AppThreadsPageWriteCount: 0,
82+
BytesWrittenFrom: 0,
83+
BytesReadInto: 0,
84+
PagesEvictedByAppThread: 0,
85+
PagesQueuedForEviction: 0,
86+
ServerEvictingPages: 0,
87+
WorkerThreadEvictingPages: 0,
7688
},
7789
tags,
7890
)

plugins/inputs/mongodb/mongostat.go

+40-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,19 @@ type ConcurrentTransStats struct {
127127

128128
// CacheStats stores cache statistics for WiredTiger.
129129
type CacheStats struct {
130-
TrackedDirtyBytes int64 `bson:"tracked dirty bytes in the cache"`
131-
CurrentCachedBytes int64 `bson:"bytes currently in the cache"`
132-
MaxBytesConfigured int64 `bson:"maximum bytes configured"`
130+
TrackedDirtyBytes int64 `bson:"tracked dirty bytes in the cache"`
131+
CurrentCachedBytes int64 `bson:"bytes currently in the cache"`
132+
MaxBytesConfigured int64 `bson:"maximum bytes configured"`
133+
AppThreadsPageReadCount int64 `bson:"application threads page read from disk to cache count"`
134+
AppThreadsPageReadTime int64 `bson:"application threads page read from disk to cache time (usecs)"`
135+
AppThreadsPageWriteCount int64 `bson:"application threads page write from cache to disk count"`
136+
AppThreadsPageWriteTime int64 `bson:"application threads page write from cache to disk time (usecs)"`
137+
BytesWrittenFrom int64 `bson:"bytes written from cache"`
138+
BytesReadInto int64 `bson:"bytes read into cache"`
139+
PagesEvictedByAppThread int64 `bson:"pages evicted by application threads"`
140+
PagesQueuedForEviction int64 `bson:"pages queued for eviction"`
141+
ServerEvictingPages int64 `bson:"eviction server evicting pages"`
142+
WorkerThreadEvictingPages int64 `bson:"eviction worker thread evicting pages"`
133143
}
134144

135145
// TransactionStats stores transaction checkpoints in WiredTiger.
@@ -406,6 +416,20 @@ type StatLine struct {
406416
CacheDirtyPercent float64
407417
CacheUsedPercent float64
408418

419+
// Cache ultilization extended (wiredtiger only)
420+
TrackedDirtyBytes int64
421+
CurrentCachedBytes int64
422+
MaxBytesConfigured int64
423+
AppThreadsPageReadCount int64
424+
AppThreadsPageReadTime int64
425+
AppThreadsPageWriteCount int64
426+
BytesWrittenFrom int64
427+
BytesReadInto int64
428+
PagesEvictedByAppThread int64
429+
PagesQueuedForEviction int64
430+
ServerEvictingPages int64
431+
WorkerThreadEvictingPages int64
432+
409433
// Replicated Opcounter fields
410434
InsertR, QueryR, UpdateR, DeleteR, GetMoreR, CommandR int64
411435
ReplLag int64
@@ -534,6 +558,19 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
534558
returnVal.Flushes = newStat.WiredTiger.Transaction.TransCheckpoints - oldStat.WiredTiger.Transaction.TransCheckpoints
535559
returnVal.CacheDirtyPercent = float64(newStat.WiredTiger.Cache.TrackedDirtyBytes) / float64(newStat.WiredTiger.Cache.MaxBytesConfigured)
536560
returnVal.CacheUsedPercent = float64(newStat.WiredTiger.Cache.CurrentCachedBytes) / float64(newStat.WiredTiger.Cache.MaxBytesConfigured)
561+
562+
returnVal.TrackedDirtyBytes = newStat.WiredTiger.Cache.TrackedDirtyBytes
563+
returnVal.CurrentCachedBytes = newStat.WiredTiger.Cache.CurrentCachedBytes
564+
returnVal.MaxBytesConfigured = newStat.WiredTiger.Cache.MaxBytesConfigured
565+
returnVal.AppThreadsPageReadCount = newStat.WiredTiger.Cache.AppThreadsPageReadCount
566+
returnVal.AppThreadsPageReadTime = newStat.WiredTiger.Cache.AppThreadsPageReadTime
567+
returnVal.AppThreadsPageWriteCount = newStat.WiredTiger.Cache.AppThreadsPageWriteCount
568+
returnVal.BytesWrittenFrom = newStat.WiredTiger.Cache.BytesWrittenFrom
569+
returnVal.BytesReadInto = newStat.WiredTiger.Cache.BytesReadInto
570+
returnVal.PagesEvictedByAppThread = newStat.WiredTiger.Cache.PagesEvictedByAppThread
571+
returnVal.PagesQueuedForEviction = newStat.WiredTiger.Cache.PagesQueuedForEviction
572+
returnVal.ServerEvictingPages = newStat.WiredTiger.Cache.ServerEvictingPages
573+
returnVal.WorkerThreadEvictingPages = newStat.WiredTiger.Cache.WorkerThreadEvictingPages
537574
} else if newStat.BackgroundFlushing != nil && oldStat.BackgroundFlushing != nil {
538575
returnVal.Flushes = newStat.BackgroundFlushing.Flushes - oldStat.BackgroundFlushing.Flushes
539576
}

0 commit comments

Comments
 (0)