How To Collect Latency Stats?

150 views
Skip to first unread message

theironcook

unread,
Aug 8, 2018, 6:46:13 PM8/8/18
to Mongoose Node.JS ODM
Hi,

I'd like to measure the average latency per request from my app servers to my mongo database.  Every minute, I want to log out the average db transaction time from the app servers perspective.  This type of data has helped me trouble shoot issues in the past.

import * as mongoose from "mongoose";

...

this.mongoose.connection['db']['stats']((err, stats) => {
if (err) {
metricsLogger.logKeyValues( { ERROR: err });
return;
}

metricsLogger.logKeyValues({AvgObjectSize: stats.avgObjSize, fsTotalSize: stats.fsTotalSize,
fsUsedSize: stats.fsUsedSize});
});



Here's some sample code I'm playing around with.  The stats object contains data that looks like this: 
  db="xxx" collections="1" views="0" objects="75" avgObjSize="731.3466666666667" dataSize="54851" storageSize="45056" numExtents="0" indexes="1" indexSize="36864" fsUsedSize="6353461248" fsTotalSize="43985149952" ok="1"

I'm hoping that there are latency and request count statistics somewhere stored in the mongoose connection...  Or maybe someone knows if I can intercept all requests and capture my own latency metrics manually somehow?

Thanks,
Reply all
Reply to author
Forward
0 new messages