@gazzehamine/armada-watch-agent 1.3.1 → 1.3.3

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.
Files changed (2) hide show
  1. package/dist/collector.js +30 -3
  2. package/package.json +1 -1
package/dist/collector.js CHANGED
@@ -136,9 +136,16 @@ async function collectMetrics() {
136
136
  }
137
137
  async function collectProcesses() {
138
138
  const processes = await systeminformation_1.default.processes();
139
+ // Sort by CPU first, then by memory as tiebreaker
140
+ // Don't filter by cpu > 0 since CPU usage fluctuates rapidly
139
141
  return processes.list
140
- .filter((p) => p.cpu > 0 || p.mem > 0)
141
- .sort((a, b) => b.cpu - a.cpu)
142
+ .sort((a, b) => {
143
+ // Sort by CPU descending, then by memory descending
144
+ if (b.cpu !== a.cpu) {
145
+ return b.cpu - a.cpu;
146
+ }
147
+ return b.mem - a.mem;
148
+ })
142
149
  .slice(0, 20)
143
150
  .map((p) => ({
144
151
  pid: p.pid,
@@ -157,7 +164,8 @@ async function collectDockerContainers() {
157
164
  dockerStats.forEach((stat) => {
158
165
  statsMap.set(stat.id, stat);
159
166
  });
160
- return dockerContainers.map((container) => {
167
+ // Map containers with their stats
168
+ const containersWithStats = dockerContainers.map((container) => {
161
169
  const stats = statsMap.get(container.id) || {};
162
170
  return {
163
171
  id: container.id || '',
@@ -181,6 +189,25 @@ async function collectDockerContainers() {
181
189
  },
182
190
  };
183
191
  });
192
+ // Deduplicate containers by name, keeping the most recently started one
193
+ const uniqueContainers = new Map();
194
+ containersWithStats.forEach((container) => {
195
+ const existing = uniqueContainers.get(container.name);
196
+ if (!existing) {
197
+ // First occurrence of this container name
198
+ uniqueContainers.set(container.name, container);
199
+ }
200
+ else {
201
+ // Keep the one that's running, or the most recently started
202
+ const shouldReplace = (container.state === 'running' && existing.state !== 'running') ||
203
+ (container.state === existing.state && container.started > existing.started);
204
+ if (shouldReplace) {
205
+ uniqueContainers.set(container.name, container);
206
+ }
207
+ }
208
+ });
209
+ // Return deduplicated containers as array
210
+ return Array.from(uniqueContainers.values());
184
211
  }
185
212
  catch (error) {
186
213
  // Docker not available or not running
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gazzehamine/armada-watch-agent",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Monitoring agent for Armada Watch - EC2 instance monitoring",
5
5
  "main": "dist/index.js",
6
6
  "bin": {