@platformatic/metrics 2.60.0 → 2.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +13 -2
  2. package/package.json +4 -2
package/index.js CHANGED
@@ -77,8 +77,19 @@ async function collectMetrics (serviceId, workerId, metricsConfig = {}, registry
77
77
  }
78
78
 
79
79
  async function collectThreadCpuMetrics (registry) {
80
- // We need until we switch to 22 as thread-cpu-usage is ESM
81
- const { threadCpuUsage } = await import('thread-cpu-usage')
80
+ let threadCpuUsage
81
+
82
+ try {
83
+ // We need until we switch to 22 as thread-cpu-usage is ESM
84
+ const res = await import('thread-cpu-usage')
85
+ threadCpuUsage = res.threadCpuUsage
86
+ } catch {
87
+ process.emitWarning('thread-cpu-usage not available')
88
+ // We ignore the loading error, as this might
89
+ // happen if the library has failed to compile
90
+ // on this platform.
91
+ return
92
+ }
82
93
 
83
94
  let lastSample = process.hrtime.bigint()
84
95
  let lastUsage = threadCpuUsage()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/metrics",
3
- "version": "2.60.0",
3
+ "version": "2.61.0",
4
4
  "description": "Platformatic Stackable Metrics",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -16,7 +16,9 @@
16
16
  "homepage": "https://github.com/platformatic/platformatic#readme",
17
17
  "dependencies": {
18
18
  "@platformatic/http-metrics": "^0.2.1",
19
- "prom-client": "^15.1.2",
19
+ "prom-client": "^15.1.2"
20
+ },
21
+ "optionalDependencies": {
20
22
  "thread-cpu-usage": "^0.2.0"
21
23
  },
22
24
  "devDependencies": {