Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit b183a1a

Browse files
authored
Merge pull request #4662 from withspectrum/improve-statsd-tracking
Track db connection count to statsd
2 parents c4b6207 + 7566993 commit b183a1a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

shared/bull/create-queue.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ function createQueue(name: string, queueOptions?: Object = {}) {
6363
jobPromise
6464
.then(() => {
6565
const duration = new Date().getTime() - startTime;
66-
statsd.timing('jobs.duration', duration);
66+
statsd.timing('jobs.duration', duration, {
67+
queue: name,
68+
});
6769
statsd.increment('jobs.active', -1, {
6870
queue: name,
6971
});

shared/db/db.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import { statsd } from '../statsd';
99

1010
const IS_PROD = !process.env.FORCE_DEV && process.env.NODE_ENV === 'production';
1111

12+
const CONNECTIONS = 20;
1213
const DEFAULT_CONFIG = {
1314
// Connect to the test database when, well, testing
1415
db: !process.env.TEST_DB ? 'spectrum' : 'testing',
15-
max: 20, // Maximum number of connections, default is 1000
16-
buffer: 20, // Minimum number of connections open at any given moment, default is 50
16+
max: CONNECTIONS, // Maximum number of connections, default is 1000
17+
buffer: CONNECTIONS, // Minimum number of connections open at any given moment, default is 50
1718
timeoutGb: 60 * 60 * 1000, // How long should an unused connection stick around, default is an hour, this is a minute
1819
timeout: 30, // The number of seconds for a connection to be opened, default 20
1920
};
@@ -58,6 +59,10 @@ poolMaster.on('queueing', size => {
5859
statsd.gauge('db.query_queue.size', size);
5960
});
6061

62+
poolMaster.on('size', size => {
63+
statsd.gauge('db.connections.count', size);
64+
});
65+
6166
// Exit the process on unhealthy db in test env
6267
if (process.env.TEST_DB) {
6368
poolMaster.on('healthy', healthy => {

0 commit comments

Comments
 (0)