-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0458df
commit 5ed6e16
Showing
138 changed files
with
2,870 additions
and
50 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+9.69 KB
.yarn/cache/@opencensus-propagation-b3-npm-0.0.8-19f31e4e91-c480bd1810.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.73 KB
.yarn/cache/@pm2-pm2-version-check-npm-1.0.4-78a842a54a-663438d915.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+29 KB
.yarn/cache/continuation-local-storage-npm-3.2.1-0ee1d709d7-5ac1dcf354.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+3.51 KB
.yarn/cache/module-details-from-path-npm-1.0.3-396d5203b4-378a8a2601.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+5.46 KB
.yarn/cache/require-in-the-middle-npm-5.2.0-322999f7de-20bfdc0e97.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { register, Gauge } from 'prom-client'; | ||
import pm2, { ProcessDescription } from 'pm2'; | ||
|
||
export const pm2Metrics = async () => { | ||
const memoryGauge = new Gauge({ | ||
name: 'worker_memory_bytes', | ||
help: 'Worker memory usage in bytes', | ||
labelNames: ['name', 'instance'], | ||
}); | ||
|
||
const cpuGauge = new Gauge({ | ||
name: 'worker_cpu_percentage', | ||
help: 'Worker CPU usage in percentage', | ||
labelNames: ['name', 'instance'], | ||
}); | ||
|
||
const uptimeGauge = new Gauge({ | ||
name: 'worker_uptime_seconds', | ||
help: 'Worker uptime in seconds', | ||
labelNames: ['name', 'instance'], | ||
}); | ||
|
||
const restartsGauge = new Gauge({ | ||
name: 'worker_restarts_total', | ||
help: 'Total number of process restarts', | ||
labelNames: ['name', 'instance'], | ||
}); | ||
|
||
const statusGauge = new Gauge({ | ||
name: 'worker_status', | ||
help: 'Is the process running', | ||
labelNames: ['name', 'instance'], | ||
}); | ||
|
||
const instancesGauge = new Gauge({ | ||
name: 'worker_instances', | ||
help: 'Process instances', | ||
labelNames: ['name', 'instance'], | ||
}); | ||
|
||
try { | ||
await new Promise((resolve, reject) => { | ||
pm2.connect(async error => { | ||
if (error) { | ||
console.error(error); | ||
reject(new Error('Error connecting to PM2')); | ||
} | ||
|
||
try { | ||
const processDescriptionList: ProcessDescription[] = | ||
await new Promise((resolve, reject) => { | ||
pm2.list((error, list) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(list); | ||
} | ||
}); | ||
}); | ||
|
||
for (const proc of processDescriptionList) { | ||
const { name, pm_id: instance, monit, pm2_env } = proc; | ||
const labels = { name, instance }; | ||
|
||
uptimeGauge.set( | ||
labels, | ||
pm2_env | ||
? Math.round((Date.now() - (pm2_env.pm_uptime || 0)) / 1000) | ||
: 0, | ||
); | ||
statusGauge.set( | ||
labels, | ||
pm2_env ? (pm2_env.status === 'online' ? 1 : 0) : 0, | ||
); | ||
instancesGauge.set( | ||
labels, | ||
pm2_env ? Number(pm2_env.instances) || 1 : 0, | ||
); | ||
memoryGauge.set(labels, monit ? monit.memory || 0 : 0); | ||
cpuGauge.set(labels, monit ? monit.cpu || 0 : 0); | ||
restartsGauge.set( | ||
labels, | ||
pm2_env | ||
? pm2_env.unstable_restarts || 0 + (pm2_env.restart_time || 0) | ||
: 0, | ||
); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
reject(new Error('Error fetching PM2 metrics')); | ||
} finally { | ||
pm2.disconnect(); | ||
resolve(true); | ||
} | ||
}); | ||
}); | ||
|
||
const metrics = await register.metrics(); | ||
|
||
return metrics; | ||
} catch { | ||
throw new Error('Error fetching PM2 metrics'); | ||
} | ||
}; |
Oops, something went wrong.