wattpm 2.27.0 → 2.28.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/index.js CHANGED
@@ -6,6 +6,7 @@ import { helpCommand } from './lib/commands/help.js'
6
6
  import { initCommand } from './lib/commands/init.js'
7
7
  import { injectCommand } from './lib/commands/inject.js'
8
8
  import { logsCommand } from './lib/commands/logs.js'
9
+ import { metricsCommand } from './lib/commands/metrics.js'
9
10
  import { configCommand, envCommand, psCommand, servicesCommand } from './lib/commands/management.js'
10
11
  import { version } from './lib/schema.js'
11
12
  import { createLogger, overrideFatal, parseArgs, setVerbose } from './lib/utils.js'
@@ -100,6 +101,9 @@ export async function main () {
100
101
  case 'help':
101
102
  command = helpCommand
102
103
  break
104
+ case 'metrics':
105
+ command = metricsCommand
106
+ break
103
107
  default:
104
108
  logger.fatal(
105
109
  `Unknown command ${bold(unparsed[0])}. Please run ${bold("'wattpm help'")} to see available commands.`
@@ -4,7 +4,7 @@ import { logo } from '../logo.js'
4
4
  async function loadCommands () {
5
5
  const commands = {}
6
6
 
7
- for (const file of ['init', 'build', 'execution', 'management', 'logs', 'inject', 'external']) {
7
+ for (const file of ['init', 'build', 'execution', 'management', 'logs', 'inject', 'external', 'metrics']) {
8
8
  const category = await import(`./${file}.js`)
9
9
  Object.assign(commands, category.help)
10
10
  }
@@ -0,0 +1,51 @@
1
+ import { ensureLoggableError } from '@platformatic/utils'
2
+ import { RuntimeApiClient } from '@platformatic/control'
3
+ import { bold } from 'colorette'
4
+ import { parseArgs, getMatchingRuntime } from '../utils.js'
5
+
6
+ export async function metricsCommand (logger, args) {
7
+ try {
8
+ const { values, positionals } = parseArgs(
9
+ args,
10
+ { format: { type: 'string', short: 'f', default: 'json' } },
11
+ false
12
+ )
13
+
14
+ const client = new RuntimeApiClient()
15
+ const [runtime] = await getMatchingRuntime(client, positionals)
16
+ const metrics = await client.getRuntimeMetrics(runtime.pid, { format: values.format })
17
+ const result = values.format === 'text' ? metrics : JSON.stringify(metrics, null, 2)
18
+ console.log(result)
19
+ await client.close()
20
+
21
+ logger.done(`Runtime ${bold(runtime.packageName)} have been stopped.`)
22
+ } catch (error) {
23
+ if (error.code === 'PLT_CTR_RUNTIME_NOT_FOUND') {
24
+ logger.fatal('Cannot find a matching runtime.')
25
+ /* c8 ignore next 3 */
26
+ } else {
27
+ logger.fatal({ error: ensureLoggableError(error) }, `Cannot reload the runtime: ${error.message}`)
28
+ }
29
+ }
30
+ }
31
+
32
+ export const help = {
33
+ metrics: {
34
+ usage: 'metrics [id]',
35
+ description: 'Return metrics from a running application',
36
+ options: [
37
+ {
38
+ usage: '-f, --format',
39
+ description: 'Define metrics format, it should be either text or json (default is json)'
40
+ }
41
+ ],
42
+ args: [
43
+ {
44
+ name: 'id',
45
+ description:
46
+ 'The process ID of the application (it can be omitted only if there is a single application running)'
47
+ }
48
+ ],
49
+ footer: 'If process id is not specified, the command will return metrics from main application running.'
50
+ }
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wattpm",
3
- "version": "2.27.0",
3
+ "version": "2.28.0",
4
4
  "description": "The Node.js Application Server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -35,11 +35,11 @@
35
35
  "pino-pretty": "^13.0.0",
36
36
  "split2": "^4.2.0",
37
37
  "table": "^6.8.2",
38
- "@platformatic/basic": "2.27.0",
39
- "@platformatic/config": "2.27.0",
40
- "@platformatic/control": "2.27.0",
41
- "@platformatic/runtime": "2.27.0",
42
- "@platformatic/utils": "2.27.0"
38
+ "@platformatic/basic": "2.28.0",
39
+ "@platformatic/config": "2.28.0",
40
+ "@platformatic/control": "2.28.0",
41
+ "@platformatic/runtime": "2.28.0",
42
+ "@platformatic/utils": "2.28.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "borp": "^0.19.0",
@@ -49,7 +49,7 @@
49
49
  "neostandard": "^0.12.0",
50
50
  "typescript": "^5.5.4",
51
51
  "undici": "^7.0.0",
52
- "@platformatic/node": "2.27.0"
52
+ "@platformatic/node": "2.28.0"
53
53
  },
54
54
  "scripts": {
55
55
  "test": "npm run lint && borp --concurrency=1 --timeout=300000",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/wattpm/2.27.0.json",
2
+ "$id": "https://schemas.platformatic.dev/wattpm/2.28.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "type": "object",
5
5
  "properties": {