Skip to content

Commit

Permalink
Merge pull request #19 from Appdynamics/PRE-26025
Browse files Browse the repository at this point in the history
PRE-26025 - Add CPU & memory calculation for more processes via Regex
  • Loading branch information
pstokosa authored Oct 4, 2024
2 parents 8992b8b + 49d7f35 commit 48d40f3
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.hyperic.sigar.*;
import org.hyperic.sigar.ProcCpu;
import org.hyperic.sigar.ProcMem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.slf4j.Logger;

import java.util.ArrayList;
Expand Down Expand Up @@ -95,6 +98,24 @@ public Map<String, ProcessData> populateProcessesData(List<Instance> instances,
if (residentMem != null) {
processMetrics.put(RSS, String.valueOf(residentMem));
}
} else if (processLines.size() > 1) {
Double cpuPercent = 0.0;
Double processCpuPercent;
Long residentMem = 0L;
Long processResidentMem;
for (String processLine : processLines) {
String pid = processLine.trim().split(MonitorConstants.SPACES)[0];
processCpuPercent = getProcCPU(pid);
if (processCpuPercent != null) {
cpuPercent += getProcCPU(pid);
}
processResidentMem = getProcMem(pid);
if (processResidentMem != null) {
residentMem += getProcMem(pid);
}
}
processMetrics.put(CPU_PERCENT, String.valueOf(cpuPercent));
processMetrics.put(RSS, String.valueOf(residentMem));
}
processMetrics.put(MonitorConstants.RUNNING_INSTANCES_COUNT, String.valueOf(processLines.size()));
processData.setProcessMetrics(processMetrics);
Expand Down

0 comments on commit 48d40f3

Please sign in to comment.