-
Notifications
You must be signed in to change notification settings - Fork 5
/
queue-metrics.js
30 lines (26 loc) · 1.1 KB
/
queue-metrics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const queues = {};
setInterval(() => {
const memoryUsage = process.memoryUsage();
console.log(`Memory Usage:
RSS: ${(memoryUsage.rss / 1024 / 1024).toFixed(2)} MB
Heap Total: ${(memoryUsage.heapTotal / 1024 / 1024).toFixed(2)} MB
Heap Used: ${(memoryUsage.heapUsed / 1024 / 1024).toFixed(2)} MB
External: ${(memoryUsage.external / 1024 / 1024).toFixed(2)} MB`);
}, 10000); // Check memory every 10 seconds
setInterval(async () => {
const jobCountsByWallet = {}; // Store metrics per wallet
const jobs = await Promise.all(
Object.keys(queues).map((wallet) =>
queues[wallet].getJobs(['waiting', 'active'])
)
);
for (const job of jobs.flat()) {
const { wallet } = job.data;
const state = await job.getState();
if (!jobCountsByWallet[wallet])
jobCountsByWallet[wallet] = { waiting: 0, active: 0 };
if (state === 'waiting') jobCountsByWallet[wallet].waiting += 1;
if (state === 'active') jobCountsByWallet[wallet].active += 1;
}
console.log('Job counts by wallet:', jobCountsByWallet);
}, 10000);