@platformatic/control 2.26.2 → 2.27.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.
package/lib/errors.js CHANGED
@@ -23,4 +23,5 @@ module.exports = {
23
23
  FailedToGetRuntimeHistoryLogs: createError(`${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS`, 'Failed to get history logs %s.'),
24
24
  FailedToGetRuntimeAllLogs: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_ALL_LOGS`, 'Failed to get runtime all logs %s.'),
25
25
  FailedToGetRuntimeLogIndexes: createError(`${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS_COUNT`, 'Failed to get history logs count %s.'),
26
+ FailedToGetRuntimeMetrics: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_METRICS`, 'Failed to get runtime metrics %s.'),
26
27
  }
@@ -229,6 +229,36 @@ class RuntimeApiClient {
229
229
  }
230
230
  }
231
231
 
232
+ async getRuntimeMetrics (pid, options = {}) {
233
+ const client = this.#getUndiciClient(pid)
234
+
235
+ const format = options.format ?? 'text'
236
+ const headers = {}
237
+ if (format === 'json') {
238
+ headers['accept'] = 'application/json'
239
+ }
240
+ if (format === 'text') {
241
+ headers['accept'] = 'text/plain'
242
+ }
243
+
244
+ const { statusCode, body } = await client.request({
245
+ path: '/api/v1/metrics',
246
+ method: 'GET',
247
+ headers
248
+ })
249
+
250
+ if (statusCode !== 200) {
251
+ const error = await body.text()
252
+ throw new errors.FailedToGetRuntimeMetrics(error)
253
+ }
254
+
255
+ const metrics = format === 'json'
256
+ ? await body.json()
257
+ : await body.text()
258
+
259
+ return metrics
260
+ }
261
+
232
262
  getRuntimeLiveMetricsStream (pid) {
233
263
  const socketPath = this.#getSocketPathFromPid(pid)
234
264
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/control",
3
- "version": "2.26.2",
3
+ "version": "2.27.0",
4
4
  "description": "Platformatic Control",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -25,8 +25,8 @@
25
25
  "split2": "^4.2.0",
26
26
  "tsd": "^0.31.0",
27
27
  "typescript": "^5.5.4",
28
- "@platformatic/service": "2.26.2",
29
- "@platformatic/runtime": "2.26.2"
28
+ "@platformatic/runtime": "2.27.0",
29
+ "@platformatic/service": "2.27.0"
30
30
  },
31
31
  "dependencies": {
32
32
  "@fastify/error": "^4.0.0",
@@ -37,7 +37,7 @@
37
37
  "table": "^6.8.1",
38
38
  "undici": "^7.0.0",
39
39
  "ws": "^8.16.0",
40
- "@platformatic/utils": "2.26.2"
40
+ "@platformatic/utils": "2.27.0"
41
41
  },
42
42
  "scripts": {
43
43
  "test": "pnpm run lint && pnpm run unit",