@percy/monitoring 1.31.2 → 1.31.3-beta.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/dist/disk.js ADDED
@@ -0,0 +1,36 @@
1
+ import { promisify } from 'util';
2
+ import { exec as callbackExec } from 'child_process';
3
+
4
+ // We wrap the dependency in an object so we can easily mock it
5
+ export const dependencies = {
6
+ defaultExec: promisify(callbackExec)
7
+ };
8
+
9
+ /**
10
+ * Gets available disk space for the primary system partition.
11
+ * @param {string} platform - The OS platform ('win32', 'linux', 'darwin').
12
+ * @param {function} exec - Optional exec function for testing.
13
+ * @returns {Promise<string>} The available disk space (e.g., "123.45 gb") or 'N/A'.
14
+ */
15
+ export async function getDiskSpaceInfo(platform, exec = dependencies.defaultExec) {
16
+ try {
17
+ if (platform === 'win32') {
18
+ const {
19
+ stdout
20
+ } = await exec('wmic logicaldisk where "DeviceID=\'C:\'" get FreeSpace /value');
21
+ const freeSpaceBytes = Number(stdout.trim().split('=')[1]);
22
+ if (isNaN(freeSpaceBytes)) return 'N/A';
23
+ return `${(freeSpaceBytes / 1024 ** 3).toFixed(2)} gb`;
24
+ } else {
25
+ const {
26
+ stdout
27
+ } = await exec('df -k /');
28
+ const lines = stdout.trim().split('\n');
29
+ const availableKB = Number(lines[1].split(/\s+/)[3]);
30
+ if (isNaN(availableKB)) return 'N/A';
31
+ return `${(availableKB / 1024 ** 2).toFixed(2)} gb`;
32
+ }
33
+ } catch (error) {
34
+ return 'N/A';
35
+ }
36
+ }
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import fs from 'fs';
3
3
  import logger from '@percy/logger';
4
4
  import { getCPUUsageInfo, getClientCPUDetails } from './cpu.js';
5
5
  import { getMemoryUsageInfo, getClientMemoryDetails } from './memory.js';
6
+ import { getDiskSpaceInfo } from './disk.js';
6
7
  export default class Monitoring {
7
8
  constructor() {
8
9
  this.os = this.getOS();
@@ -37,18 +38,25 @@ export default class Monitoring {
37
38
  isMachineLevel() {
38
39
  return !this.isContainerLevel();
39
40
  }
40
- async logSystemInfo() {
41
+ async logSystemInfo({
42
+ getDiskSpaceInfo: getDiskSpaceInfoParam = getDiskSpaceInfo,
43
+ getClientCPUDetails: getClientCPUDetailsParam = getClientCPUDetails
44
+ } = {}) {
41
45
  try {
42
- const cpu = await getClientCPUDetails();
46
+ var _os$cpus$;
47
+ const cpu = await getClientCPUDetailsParam();
43
48
  const mem = await getClientMemoryDetails();
44
49
  const percyEnvs = this.getPercyEnv();
50
+ const cpuName = ((_os$cpus$ = os.cpus()[0]) === null || _os$cpus$ === void 0 ? void 0 : _os$cpus$.model.trim()) || 'N/A';
51
+ const diskSpace = await getDiskSpaceInfoParam(this.os);
45
52
  this.log.debug(`[Operating System] Platform: ${this.os}, Type: ${os.type()}, Release: ${os.release()}`);
53
+ this.log.debug(`[CPU] Name: ${cpuName}`);
46
54
  this.log.debug(`[CPU] Arch: ${cpu.arch}, cores: ${cpu.cores}`);
55
+ this.log.debug(`[Disk] Available Space: ${diskSpace}`);
47
56
  this.log.debug(`[Memory] Total: ${mem.total / 1024 ** 3} gb, Swap Space: ${mem.swaptotal / 1024 ** 3} gb`);
48
57
  this.log.debug(`Container Level: ${this.isContainer}, Pod Level: ${this.isPod}, Machine Level: ${this.isMachine}`);
49
58
  this.log.debug(`Percy Envs: ${JSON.stringify(percyEnvs)}`);
50
59
  } catch (error) {
51
- // suppress error
52
60
  this.log.debug(`Error logging system info: ${error}`);
53
61
  }
54
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/monitoring",
3
- "version": "1.31.2",
3
+ "version": "1.31.3-beta.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "publishConfig": {
11
11
  "access": "public",
12
- "tag": "latest"
12
+ "tag": "beta"
13
13
  },
14
14
  "engines": {
15
15
  "node": ">=14"
@@ -29,10 +29,10 @@
29
29
  "test:coverage": "yarn test --coverage"
30
30
  },
31
31
  "dependencies": {
32
- "@percy/config": "1.31.2",
33
- "@percy/logger": "1.31.2",
34
- "@percy/sdk-utils": "1.31.2",
32
+ "@percy/config": "1.31.3-beta.0",
33
+ "@percy/logger": "1.31.3-beta.0",
34
+ "@percy/sdk-utils": "1.31.3-beta.0",
35
35
  "systeminformation": "^5.25.11"
36
36
  },
37
- "gitHead": "9e203e849d328de6a314f1e468b2c100dfe2830c"
37
+ "gitHead": "5979f9463370916036b700109320b6e9f2d17bc5"
38
38
  }