Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mixmaxhq/mongo-slow-queries
https://github.com/mixmaxhq/mongo-slow-queries
corgi-tag mongodb monitoring query-monitoring
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mixmaxhq/mongo-slow-queries
- Owner: mixmaxhq
- License: mit
- Created: 2017-02-06T20:03:02.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-11-20T17:16:07.000Z (12 months ago)
- Last Synced: 2024-10-15T15:42:55.471Z (about 1 month ago)
- Topics: corgi-tag, mongodb, monitoring, query-monitoring
- Language: JavaScript
- Homepage: https://www.mixmax.com/careers
- Size: 179 KB
- Stars: 23
- Watchers: 29
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# mongo-slow-queries
A module for pulling slow queries from Mongo, tagged with metadata as well.## Install
```
$ npm install mongo-slow-queries
```## Usage
### Initialization
To use `mongo-slow-queries` you just need to provide a Mongo DB reference when
creating an instance:```js
const mongojs = require('mongojs');
const MongoSlowQueryChecker = require('mongo-slow-queries');let db = mongojs('mongodb://localhost:27017/admin');
let slowQueries = new MongoSlowQueryChecker({ db });
```If the `db` object has an `adminCommand` method, it need not be a reference to
the `admin` database.### Querying for slow queries
Querying for slow queries is then as simple as calling `get`:```js
slowQueries.get((err, queries) => {
if (err) {
console.log('Failed to retrieve slow queries: ' + queries);
} else {
console.log('slow queries: ' + JSON.stringify(queries));
}
});
```### Query duration threshold
By default, `mongo-slow-queries` only returns queries that are currently
running that have already taken greater than five seconds to run. If you wish
to use a different threshold value, simply pass it in when you construct the
Mongo slow query checker:```js
let slowQueries = new MongoSlowQueryChecker({
db,
queryThreshold: 2 // The unit of time is in seconds.
});
```### Changelog
* 1.0.1 Fix which `query` we fingerprint.
* 1.0.0 Initial release.