agent-window 1.2.5 → 1.2.6
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/package.json +1 -1
- package/src/core/platform/pm2-bridge.js +45 -15
package/package.json
CHANGED
|
@@ -71,6 +71,34 @@ async function execPM2Command(args, options = {}) {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Parse environment variables from PM2 format
|
|
76
|
+
* PM2 sometimes returns env as string "KEY=value" or as object
|
|
77
|
+
*/
|
|
78
|
+
function parseEnv(env) {
|
|
79
|
+
if (!env) return {};
|
|
80
|
+
|
|
81
|
+
// If already an object, return it
|
|
82
|
+
if (typeof env === 'object') return env;
|
|
83
|
+
|
|
84
|
+
// If string, parse it (format: "KEY1=value1\nKEY2=value2" or "KEY=value")
|
|
85
|
+
if (typeof env === 'string') {
|
|
86
|
+
const result = {};
|
|
87
|
+
// Split by newlines and parse each KEY=value pair
|
|
88
|
+
env.split('\n').forEach(line => {
|
|
89
|
+
const eqIndex = line.indexOf('=');
|
|
90
|
+
if (eqIndex > 0) {
|
|
91
|
+
const key = line.substring(0, eqIndex).trim();
|
|
92
|
+
const value = line.substring(eqIndex + 1).trim();
|
|
93
|
+
result[key] = value;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {};
|
|
100
|
+
}
|
|
101
|
+
|
|
74
102
|
/**
|
|
75
103
|
* Get list of PM2 processes
|
|
76
104
|
*/
|
|
@@ -78,21 +106,23 @@ async function list(options = {}) {
|
|
|
78
106
|
try {
|
|
79
107
|
const result = await execPM2Command(['jlist'], { ...options, silent: true });
|
|
80
108
|
const processes = JSON.parse(result.stdout || '[]');
|
|
81
|
-
return processes.map(p =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
return processes.map(p => {
|
|
110
|
+
const env = parseEnv(p.pm2_env?.env);
|
|
111
|
+
return {
|
|
112
|
+
pid: p.pid,
|
|
113
|
+
name: p.name,
|
|
114
|
+
pm_id: p.pm_id,
|
|
115
|
+
status: p.pm2_env?.status || 'unknown',
|
|
116
|
+
uptime: p.pm2_env?.pm_uptime || null,
|
|
117
|
+
memory: p.monit?.memory || 0,
|
|
118
|
+
cpu: p.monit?.cpu || 0,
|
|
119
|
+
restarts: p.pm2_env?.restart_time || 0,
|
|
120
|
+
cwd: p.pm2_env?.cwd || null,
|
|
121
|
+
script: p.pm2_env?.pm_cwd || null,
|
|
122
|
+
env: env,
|
|
123
|
+
configPath: env.CONFIG_PATH || null
|
|
124
|
+
};
|
|
125
|
+
});
|
|
96
126
|
} catch {
|
|
97
127
|
return [];
|
|
98
128
|
}
|