@constellation-network/node-pilot 0.0.15 → 0.0.16

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/README.md CHANGED
@@ -21,7 +21,7 @@ $ npm install -g @constellation-network/node-pilot
21
21
  $ cpilot COMMAND
22
22
  running command...
23
23
  $ cpilot (--version|-v)
24
- @constellation-network/node-pilot/0.0.15 darwin-arm64 node-v24.8.0
24
+ @constellation-network/node-pilot/0.0.16 darwin-arm64 node-v24.8.0
25
25
  $ cpilot --help [COMMAND]
26
26
  USAGE
27
27
  $ cpilot COMMAND
@@ -62,7 +62,7 @@ EXAMPLES
62
62
  $ cpilot config
63
63
  ```
64
64
 
65
- _See code: [src/commands/config.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.15/src/commands/config.ts)_
65
+ _See code: [src/commands/config.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.16/src/commands/config.ts)_
66
66
 
67
67
  ## `cpilot config get [NAME]`
68
68
 
@@ -86,7 +86,7 @@ EXAMPLES
86
86
  $ cpilot config get gl0:CL_PUBLIC_HTTP_PORT
87
87
  ```
88
88
 
89
- _See code: [src/commands/config/get.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.15/src/commands/config/get.ts)_
89
+ _See code: [src/commands/config/get.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.16/src/commands/config/get.ts)_
90
90
 
91
91
  ## `cpilot config set NAME VALUE`
92
92
 
@@ -109,7 +109,7 @@ EXAMPLES
109
109
  $ cpilot config set gl0:CL_PUBLIC_HTTP_PORT 9000
110
110
  ```
111
111
 
112
- _See code: [src/commands/config/set.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.15/src/commands/config/set.ts)_
112
+ _See code: [src/commands/config/set.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.16/src/commands/config/set.ts)_
113
113
 
114
114
  ## `cpilot help [COMMAND]`
115
115
 
@@ -146,7 +146,7 @@ EXAMPLES
146
146
  $ cpilot info
147
147
  ```
148
148
 
149
- _See code: [src/commands/info.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.15/src/commands/info.ts)_
149
+ _See code: [src/commands/info.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.16/src/commands/info.ts)_
150
150
 
151
151
  ## `cpilot logs LAYER`
152
152
 
@@ -170,7 +170,7 @@ EXAMPLES
170
170
  $ cpilot logs
171
171
  ```
172
172
 
173
- _See code: [src/commands/logs.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.15/src/commands/logs.ts)_
173
+ _See code: [src/commands/logs.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.16/src/commands/logs.ts)_
174
174
 
175
175
  ## `cpilot restart [LAYER]`
176
176
 
@@ -198,7 +198,7 @@ EXAMPLES
198
198
  $ cpilot restart
199
199
  ```
200
200
 
201
- _See code: [src/commands/restart.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.15/src/commands/restart.ts)_
201
+ _See code: [src/commands/restart.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.16/src/commands/restart.ts)_
202
202
 
203
203
  ## `cpilot shutdown`
204
204
 
@@ -215,7 +215,7 @@ EXAMPLES
215
215
  $ cpilot shutdown
216
216
  ```
217
217
 
218
- _See code: [src/commands/shutdown.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.15/src/commands/shutdown.ts)_
218
+ _See code: [src/commands/shutdown.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.16/src/commands/shutdown.ts)_
219
219
 
220
220
  ## `cpilot status`
221
221
 
@@ -229,5 +229,5 @@ DESCRIPTION
229
229
  Display node status and configuration settings
230
230
  ```
231
231
 
232
- _See code: [src/commands/status.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.15/src/commands/status.ts)_
232
+ _See code: [src/commands/status.ts](https://github.com/Constellation-Labs/node-pilot/blob/v0.0.16/src/commands/status.ts)_
233
233
  <!-- commandsstop -->
@@ -30,8 +30,8 @@ export const checkDependencies = async () => {
30
30
  await promptHelper.doYouWishToContinue();
31
31
  }
32
32
  clm.debug(`Running install-dependencies.sh from ${pilotDir}`);
33
- const silent = !process.env.DEBUG;
34
- const result = shell.exec('bash install-dependencies.sh', { cwd: pilotDir, silent });
33
+ // const silent = !process.env.DEBUG;
34
+ const result = shell.exec('bash install-dependencies.sh', { cwd: pilotDir });
35
35
  if (result.code > 0) {
36
36
  console.log(result.stderr);
37
37
  clm.error(`Failed to install dependencies. Please try again after resolving any errors.`);
@@ -13,9 +13,7 @@ export const checkHardware = {
13
13
  const totalSpaceGB = (r.bsize * r.blocks / (1024 * 1024 * 1024)).toFixed(2);
14
14
  // const usage = diskusage.checkSync(os.homedir());
15
15
  // const usableSpaceGB = (usage.total / (1024 * 1024 * 1024)).toFixed(2);
16
- // Retrieve sys memory
17
- const totalMemoryBytes = os.totalmem();
18
- const totalMemoryGB = (totalMemoryBytes / (1024 * 1024 * 1024)).toFixed(2);
16
+ const totalMemoryGB = (os.totalmem() / (1024 * 1024 * 1024)).toFixed(2);
19
17
  // Retrieve number of CPU cores
20
18
  const numOfCores = os.availableParallelism();
21
19
  let allPassed = true;
@@ -66,16 +66,14 @@ export const projectHelper = {
66
66
  const { projectDir } = configStore.getProjectInfo();
67
67
  const { platform } = configStore.getSystemInfo();
68
68
  // Create gl0 folder for the fast-forward feature before Docker does
69
+ const gl0DataDir = path.join(projectDir, 'gl0', 'data');
70
+ fs.mkdirSync(path.join(gl0DataDir, 'incremental_snapshot'), { recursive: true });
71
+ fs.mkdirSync(path.join(gl0DataDir, 'snapshot_info'));
72
+ fs.mkdirSync(path.join(gl0DataDir, 'tmp'));
69
73
  if (platform === 'linux') {
70
74
  const layerDir = path.join(projectDir, 'gl0');
71
75
  // set permission for group "docker" on the layer folder and any subfolders created later
72
- await shellService.runCommand(`sudo setfacl -m g:docker:rwX -dm g:docker:rwX ${layerDir}`);
73
- }
74
- else {
75
- const gl0DataDir = path.join(projectDir, 'gl0', 'data');
76
- fs.mkdirSync(path.join(gl0DataDir, 'incremental_snapshot'), { recursive: true });
77
- fs.mkdirSync(path.join(gl0DataDir, 'snapshot_info'));
78
- fs.mkdirSync(path.join(gl0DataDir, 'tmp'));
76
+ await shellService.runCommand(`sudo setfacl -Rm g:docker:rwX -dm g:docker:rwX ${layerDir}`);
79
77
  }
80
78
  this.importEnvFiles();
81
79
  },
@@ -21,7 +21,9 @@ export type NodeStatusInfo = {
21
21
  clusterOrdinal: number;
22
22
  clusterSession: string;
23
23
  clusterState: string;
24
+ cpuUsage: string;
24
25
  error: string;
26
+ memUsage: string;
25
27
  ordinal: number;
26
28
  pilotSession: string;
27
29
  session: string;
@@ -1,4 +1,16 @@
1
1
  class CellFormatter {
2
+ formatCpu(value) {
3
+ if (value === '-')
4
+ return value;
5
+ const num = Number.parseInt(value, 10);
6
+ if (num === 0)
7
+ return value;
8
+ if (num < 60)
9
+ return this.style(value.toString(), "green");
10
+ if (num < 90)
11
+ return this.style(value.toString(), "yellow", "bold");
12
+ return this.style(value.toString(), "red", "bold");
13
+ }
2
14
  formatDistance(value) {
3
15
  if (value === '-')
4
16
  return value;
@@ -14,10 +26,22 @@ class CellFormatter {
14
26
  return value;
15
27
  return this.style(value, "bgRed", "bold");
16
28
  }
29
+ formatMem(value) {
30
+ if (value === '-')
31
+ return value;
32
+ const num = Number.parseInt(value.split('(')[1], 10);
33
+ if (num === 0)
34
+ return value;
35
+ if (num < 70)
36
+ return this.style(value.toString(), "green");
37
+ if (num < 90)
38
+ return this.style(value.toString(), "yellow", "bold");
39
+ return this.style(value.toString(), "red", "bold");
40
+ }
17
41
  formatOrdinal(value) {
18
42
  const [v, changed] = value.split(':');
19
43
  if (changed) {
20
- return this.style(v, "bgCyan");
44
+ return this.style(v, "whiteBright");
21
45
  }
22
46
  return this.style(v, "cyan");
23
47
  }
@@ -48,15 +72,17 @@ class CellFormatter {
48
72
  return `c${color}v${value}s${style}`;
49
73
  }
50
74
  }
51
- const { formatDistance, formatError, formatOrdinal, formatState, formatUpTIme } = new CellFormatter();
52
- // Layer | Uptime | State | Ordinal | Distance from cluster | Cluster State | Error
75
+ const { formatCpu, formatDistance, formatError, formatMem, formatOrdinal, formatState, formatUpTIme } = new CellFormatter();
76
+ // Layer | Uptime | State | Ordinal | Distance from cluster | Cluster State | CPU Usage | Mem Usage | Error
53
77
  export const statusTableHeader = [
54
78
  { color: 'white', headerColor: 'whiteBright', value: 'Network' },
55
79
  { color: 'whiteBright', headerColor: 'whiteBright', value: 'Layer' },
56
80
  { color: 'white', formatter: formatUpTIme, headerColor: 'whiteBright', value: 'Uptime' },
57
- { color: 'white', formatter: formatState, headerColor: 'whiteBright', value: 'Node State', width: 18 },
81
+ { color: 'white', formatter: formatState, headerColor: 'whiteBright', value: 'Node State', width: 24 },
58
82
  { color: 'white', formatter: formatOrdinal, headerColor: 'whiteBright', value: 'Ordinal' },
59
- { color: 'white', formatter: formatDistance, headerColor: 'whiteBright', value: 'Ord. lag' },
83
+ { color: 'white', formatter: formatDistance, headerColor: 'whiteBright', value: 'Distance' },
60
84
  { color: 'white', formatter: formatState, headerColor: 'whiteBright', value: 'Cluster State', width: 16 },
85
+ { color: 'white', formatter: formatCpu, headerColor: 'whiteBright', value: 'CPU Usage', width: 12 },
86
+ { color: 'white', formatter: formatMem, headerColor: 'whiteBright', value: 'Mem Usage (GB)', width: 16 },
61
87
  { color: 'white', formatter: formatError, headerColor: 'whiteBright', value: 'Error', width: 22 },
62
88
  ];
@@ -5,23 +5,6 @@ import ttyTable from "tty-table";
5
5
  import { clm } from "../clm.js";
6
6
  import { configStore } from "../config-store.js";
7
7
  import { statusTableHeader } from "./status-table-helper.js";
8
- // mismatched snapshot hash, cluster fork, lagging behind cluster, stalled state, missing snapshot
9
- // const possibleErrors = [
10
- // '-',
11
- // 'Bad snapshot hash',
12
- // 'Cluster fork',
13
- // 'Lagging behind',
14
- // 'Stalled state',
15
- // 'Missing snapshot',
16
- // ]
17
- //
18
- // const possibleStates =
19
- // [
20
- // 'Ready',
21
- // 'Restarting',
22
- // 'Offline',
23
- // 'SessionStarted'
24
- // ]
25
8
  export class StatusTable {
26
9
  alreadyRendered = false;
27
10
  previousHeight = 0;
@@ -62,10 +45,6 @@ export class StatusTable {
62
45
  configStore.setActiveProject(activeProject);
63
46
  return info;
64
47
  }
65
- // Layer | Uptime | State | Ordinal | Distance from cluster | Cluster State | Error
66
- // state: Restarting...
67
- // cluster state: Ready, Offline, Restarting...
68
- // possibleErrors: mismatched snapshot hash, cluster fork, lagging behind cluster, stalled state, missing snapshot
69
48
  async monitorState() {
70
49
  const projects = this.getProjectInfo();
71
50
  const values = {};
@@ -87,23 +66,37 @@ export class StatusTable {
87
66
  n.ordinal ? ordinal : '-',
88
67
  distance,
89
68
  n.clusterState || 'Ready',
69
+ n.cpuUsage || '-',
70
+ n.memUsage || '-',
90
71
  n.error || '-'
91
72
  ]);
92
73
  values[p.layer].ordinal = n.ordinal;
93
74
  }
94
- // const rows = [
95
- // ["GL0", '1760103674654', possibleStates[Math.floor(Math.random()*possibleStates.length)], '5174762', String(Math.floor(Math.random()*8)), possibleStates[Math.floor(Math.random()*possibleStates.length)], possibleErrors[Math.floor(Math.random()*possibleErrors.length)]],
96
- // ["GL1", '1760102674654', possibleStates[Math.floor(Math.random()*possibleStates.length)], '4174762', String(Math.floor(Math.random()*8)), possibleStates[Math.floor(Math.random()*possibleStates.length)], possibleErrors[Math.floor(Math.random()*possibleErrors.length)]],
97
- // ]
98
75
  this.render(rows);
99
- process.stdout.write(" *press any key to cancel");
76
+ process.stdout.write(" * press any key to cancel");
100
77
  // eslint-disable-next-line no-await-in-loop
101
78
  await sleep(1);
102
79
  }
103
80
  }
104
- render(body) {
81
+ render(rows) {
82
+ const header = [...statusTableHeader];
83
+ // const emptyColumns = Array.from({length: rows[0].length}).fill(0) as number[];
84
+ // for (const [, row] of rows.entries()) {
85
+ // for (const [j, cell] of row.entries()) {
86
+ // if (cell === '-') emptyColumns[j] += 1;
87
+ // }
88
+ // }
89
+ //
90
+ // for (const [j, cell] of emptyColumns.entries()) {
91
+ // if(cell === rows.length) {
92
+ // header.splice(j, 1);
93
+ // for (const [, row] of rows.entries()) {
94
+ // row.splice(j, 1);
95
+ // }
96
+ // }
97
+ // }
105
98
  const options = { terminalAdapter: true };
106
- const t1 = ttyTable(statusTableHeader, body, options);
99
+ const t1 = ttyTable(header, rows, options);
107
100
  // hide cursor
108
101
  console.log("\u001B[?25l");
109
102
  // wipe existing if already rendered
@@ -16,10 +16,9 @@ export class FastforwardService {
16
16
  const { projectDir } = configStore.getProjectInfo();
17
17
  const { type } = configStore.getNetworkInfo();
18
18
  this.network = type;
19
- this.tmpDir = path.join(projectDir, 'gl0', 'tmp');
20
19
  this.dataDir = path.join(projectDir, 'gl0', 'data');
20
+ this.tmpDir = path.join(projectDir, 'gl0', 'data', 'tmp');
21
21
  fs.mkdirSync(this.tmpDir, { recursive: true });
22
- fs.mkdirSync(this.dataDir, { recursive: true });
23
22
  // const env = configStore.getEnvNetworkInfo(type);
24
23
  this.lbUrl = `https://l0-lb-${this.network}.constellationnetwork.io`;
25
24
  // this.lbUrl = `http://${env.CL_L0_PEER_HTTP_HOST}:${env.CL_L0_PEER_HTTP_PORT}`;
@@ -13,7 +13,7 @@ export const nodeService = {
13
13
  .then(res => {
14
14
  if (res.ok)
15
15
  return res.json().then(i => ({ ...i, layer }));
16
- clm.warn(`Failed to get node info from ${res.url} (${res.status})`);
16
+ clm.debug(`Failed to get node info from ${res.url} (${res.status})`);
17
17
  throw new Error(`Failed`);
18
18
  })
19
19
  .catch(() => ({ layer, state: "Unavailable" }));
@@ -276,5 +276,5 @@
276
276
  ]
277
277
  }
278
278
  },
279
- "version": "0.0.15"
279
+ "version": "0.0.16"
280
280
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@constellation-network/node-pilot",
3
3
  "description": "An easy deployment and monitoring tool for Constellation nodes.",
4
- "version": "0.0.15",
4
+ "version": "0.0.16",
5
5
  "author": "Frank Fox",
6
6
  "bin": {
7
7
  "cpilot": "bin/run.js"