@gazzehamine/armada-watch-agent 1.4.0 → 1.4.2

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/collector.js CHANGED
@@ -7,6 +7,7 @@ exports.getSystemInfo = getSystemInfo;
7
7
  exports.collectMetrics = collectMetrics;
8
8
  exports.collectProcesses = collectProcesses;
9
9
  exports.collectDockerContainers = collectDockerContainers;
10
+ exports.collectPM2Processes = collectPM2Processes;
10
11
  exports.collectSSLCertificates = collectSSLCertificates;
11
12
  const systeminformation_1 = __importDefault(require("systeminformation"));
12
13
  const os_1 = __importDefault(require("os"));
@@ -262,6 +263,33 @@ async function getCertificateInfo(certPath, domain) {
262
263
  return null;
263
264
  }
264
265
  }
266
+ /**
267
+ * Collect PM2 process information
268
+ */
269
+ async function collectPM2Processes() {
270
+ try {
271
+ // Execute pm2 jlist command to get JSON output
272
+ const { stdout } = await execAsync('pm2 jlist');
273
+ const pm2Processes = JSON.parse(stdout);
274
+ return pm2Processes.map((proc) => ({
275
+ pmId: proc.pm_id || 0,
276
+ name: proc.name || 'unknown',
277
+ version: proc.pm2_env?.version || 'unknown',
278
+ mode: proc.pm2_env?.exec_mode || 'unknown',
279
+ pid: proc.pid || 0,
280
+ uptime: proc.pm2_env?.pm_uptime || 0,
281
+ restarts: proc.pm2_env?.restart_time || 0,
282
+ status: proc.pm2_env?.status || 'unknown',
283
+ cpu: proc.monit?.cpu || 0,
284
+ memory: proc.monit?.memory || 0,
285
+ user: proc.pm2_env?.username || 'unknown',
286
+ }));
287
+ }
288
+ catch (error) {
289
+ // PM2 not installed or no processes running
290
+ return [];
291
+ }
292
+ }
265
293
  /**
266
294
  * Collect SSL certificate information from Certbot certificates
267
295
  */
package/dist/index.js CHANGED
@@ -27,8 +27,9 @@ const REGION = process.env.REGION || "unknown";
27
27
  const INSTANCE_ID = process.env.INSTANCE_ID || os_1.default.hostname();
28
28
  const COLLECTION_INTERVAL = parseInt(process.env.COLLECTION_INTERVAL || "10") * 1000;
29
29
  let instanceInfo = null;
30
- let sslCheckCounter = 0;
31
- const SSL_CHECK_FREQUENCY = 30; // Check SSL every 30 metric collections (e.g., every 5 minutes if collection is 10s)
30
+ let lastSSLCertificates = [];
31
+ let lastSSLCheckTime = 0;
32
+ const SSL_CHECK_INTERVAL = 5 * 60 * 1000; // Check SSL every 5 minutes
32
33
  async function initializeAgent() {
33
34
  try {
34
35
  console.log("🔄 Initializing Armada Watch Agent...");
@@ -53,6 +54,16 @@ async function initializeAgent() {
53
54
  console.log("✅ Agent initialized successfully");
54
55
  console.log(`đŸ“Ļ Agent version: ${AGENT_VERSION}`);
55
56
  console.log(`🔁 Collection interval: ${COLLECTION_INTERVAL / 1000}s`);
57
+ // Collect SSL certificates on startup
58
+ console.log("🔐 Checking SSL certificates on startup...");
59
+ lastSSLCertificates = await (0, collector_1.collectSSLCertificates)();
60
+ lastSSLCheckTime = Date.now();
61
+ if (lastSSLCertificates.length > 0) {
62
+ console.log(`✅ Found ${lastSSLCertificates.length} SSL certificate(s)`);
63
+ }
64
+ else {
65
+ console.log("â„šī¸ No SSL certificates found");
66
+ }
56
67
  }
57
68
  catch (error) {
58
69
  console.error("❌ Failed to initialize agent:", error);
@@ -64,14 +75,15 @@ async function sendMetrics() {
64
75
  const metrics = await (0, collector_1.collectMetrics)();
65
76
  const processes = await (0, collector_1.collectProcesses)();
66
77
  const dockerContainers = await (0, collector_1.collectDockerContainers)();
67
- // Check SSL certificates less frequently (every 5 minutes by default)
68
- let sslCertificates = [];
69
- sslCheckCounter++;
70
- if (sslCheckCounter >= SSL_CHECK_FREQUENCY) {
71
- sslCertificates = await (0, collector_1.collectSSLCertificates)();
72
- sslCheckCounter = 0;
73
- if (sslCertificates.length > 0) {
74
- console.log(`🔐 SSL Certificates checked: ${sslCertificates.length} domain(s)`);
78
+ const pm2Processes = await (0, collector_1.collectPM2Processes)();
79
+ // Check if it's time to refresh SSL certificates (every 5 minutes)
80
+ const now = Date.now();
81
+ const shouldCheckSSL = (now - lastSSLCheckTime) >= SSL_CHECK_INTERVAL;
82
+ if (shouldCheckSSL) {
83
+ lastSSLCertificates = await (0, collector_1.collectSSLCertificates)();
84
+ lastSSLCheckTime = now;
85
+ if (lastSSLCertificates.length > 0) {
86
+ console.log(`🔐 SSL Certificates refreshed: ${lastSSLCertificates.length} domain(s)`);
75
87
  }
76
88
  }
77
89
  const payload = {
@@ -82,12 +94,15 @@ async function sendMetrics() {
82
94
  },
83
95
  processes,
84
96
  dockerContainers,
85
- sslCertificates: sslCertificates.length > 0 ? sslCertificates : undefined,
97
+ pm2Processes: pm2Processes.length > 0 ? pm2Processes : undefined,
98
+ // Always send SSL certificates if we have them (from startup or last check)
99
+ sslCertificates: lastSSLCertificates.length > 0 ? lastSSLCertificates : undefined,
86
100
  };
87
101
  await axios_1.default.post(`${SERVER_URL}/api/metrics`, payload, {
88
102
  timeout: 5000,
89
103
  });
90
- console.log(`✓ Metrics sent successfully - CPU: ${metrics.cpuUsage.toFixed(1)}% | Memory: ${metrics.memoryUsage.toFixed(1)}%`);
104
+ const pm2Info = pm2Processes.length > 0 ? ` | PM2: ${pm2Processes.length} processes` : '';
105
+ console.log(`✓ Metrics sent successfully - CPU: ${metrics.cpuUsage.toFixed(1)}% | Memory: ${metrics.memoryUsage.toFixed(1)}%${pm2Info}`);
91
106
  }
92
107
  catch (error) {
93
108
  if (axios_1.default.isAxiosError(error)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gazzehamine/armada-watch-agent",
3
- "version": "1.4.0",
4
- "description": "Monitoring agent for Armada Watch - EC2 instance monitoring with SSL certificate tracking",
3
+ "version": "1.4.2",
4
+ "description": "Monitoring agent for Armada Watch - EC2 instance monitoring with SSL certificate tracking and PM2 process monitoring",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
7
7
  "armada-watch-agent": "dist/index.js"