2022-12-21 16:12:15 +00:00
|
|
|
package sysmon.plugins.base;
|
2021-09-02 19:40:22 +00:00
|
|
|
|
|
|
|
import org.pf4j.Extension;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import oshi.SystemInfo;
|
|
|
|
import oshi.software.os.OSProcess;
|
|
|
|
import sysmon.shared.Measurement;
|
|
|
|
import sysmon.shared.MetricExtension;
|
|
|
|
import sysmon.shared.MetricResult;
|
|
|
|
|
2021-09-10 10:15:33 +00:00
|
|
|
import java.util.*;
|
2021-09-02 19:40:22 +00:00
|
|
|
|
|
|
|
@Extension
|
|
|
|
public class BaseProcessExtension implements MetricExtension {
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(BaseProcessorExtension.class);
|
|
|
|
|
2021-09-10 10:15:33 +00:00
|
|
|
// Extension details
|
|
|
|
private final String name = "base_process";
|
|
|
|
private final String description = "Base Process Metrics";
|
|
|
|
|
|
|
|
// Configuration / Options
|
|
|
|
private boolean enabled = true;
|
2021-11-06 19:32:54 +00:00
|
|
|
private boolean threaded = false;
|
2022-11-07 12:33:35 +00:00
|
|
|
private String interval = "60s";
|
|
|
|
|
2021-09-10 10:15:33 +00:00
|
|
|
private List<?> includeList = new ArrayList<Object>() {{
|
2021-09-02 19:40:22 +00:00
|
|
|
add("java");
|
2022-04-07 08:41:08 +00:00
|
|
|
add("node");
|
|
|
|
add("httpd");
|
|
|
|
add("mongod");
|
2021-09-13 15:13:58 +00:00
|
|
|
add("mysqld");
|
|
|
|
add("influxd");
|
2022-04-07 08:41:08 +00:00
|
|
|
add("haproxy");
|
|
|
|
add("beam.smp");
|
|
|
|
add("filebeat");
|
|
|
|
add("corosync");
|
|
|
|
add("rsyslogd");
|
|
|
|
add("postgres");
|
2023-06-24 19:32:37 +00:00
|
|
|
add("mariadbd");
|
2022-04-07 08:41:08 +00:00
|
|
|
add("memcached");
|
2022-09-19 12:15:48 +00:00
|
|
|
add("db2sysc");
|
|
|
|
add("dsmserv");
|
|
|
|
add("mmfsd");
|
2023-06-24 19:32:37 +00:00
|
|
|
add("systemd");
|
|
|
|
add("nginx");
|
2021-09-02 19:40:22 +00:00
|
|
|
}};
|
|
|
|
|
2022-10-28 08:17:51 +00:00
|
|
|
private final long minUptimeInSeconds = 600;
|
2021-09-02 19:40:22 +00:00
|
|
|
private SystemInfo systemInfo;
|
|
|
|
|
2021-09-14 07:00:34 +00:00
|
|
|
|
2021-09-10 10:15:33 +00:00
|
|
|
@Override
|
|
|
|
public boolean isEnabled() {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
2021-11-06 19:32:54 +00:00
|
|
|
@Override
|
|
|
|
public boolean isThreaded() {
|
|
|
|
return threaded;
|
|
|
|
}
|
|
|
|
|
2021-09-02 19:40:22 +00:00
|
|
|
@Override
|
|
|
|
public boolean isSupported() {
|
|
|
|
systemInfo = BasePlugin.getSystemInfo();
|
|
|
|
return systemInfo != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
2021-09-10 10:15:33 +00:00
|
|
|
return name;
|
2021-09-02 19:40:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-06 13:08:52 +00:00
|
|
|
@Override
|
|
|
|
public String getInterval() {
|
2022-11-07 12:33:35 +00:00
|
|
|
return interval;
|
2022-09-06 13:08:52 +00:00
|
|
|
}
|
|
|
|
|
2021-09-02 19:40:22 +00:00
|
|
|
@Override
|
|
|
|
public String getDescription() {
|
2021-09-10 10:15:33 +00:00
|
|
|
return description;
|
2021-09-02 19:40:22 +00:00
|
|
|
}
|
|
|
|
|
2021-09-10 10:15:33 +00:00
|
|
|
@Override
|
|
|
|
public void setConfiguration(Map<String, Object> map) {
|
|
|
|
if(map.containsKey("enabled")) {
|
|
|
|
enabled = (boolean) map.get("enabled");
|
|
|
|
}
|
2021-11-06 19:32:54 +00:00
|
|
|
if(map.containsKey("threaded")) {
|
|
|
|
threaded = (boolean) map.get("threaded");
|
|
|
|
}
|
2022-11-07 12:33:35 +00:00
|
|
|
if(map.containsKey("interval")) {
|
|
|
|
interval = (String) map.get("interval");
|
|
|
|
}
|
2021-09-10 10:15:33 +00:00
|
|
|
if(map.containsKey("include")) {
|
|
|
|
includeList = (List<?>) map.get("include");
|
|
|
|
}
|
|
|
|
}
|
2021-09-02 19:40:22 +00:00
|
|
|
|
2021-09-13 15:13:58 +00:00
|
|
|
|
2021-09-02 19:40:22 +00:00
|
|
|
@Override
|
|
|
|
public MetricResult getMetrics() {
|
|
|
|
|
|
|
|
ArrayList<Measurement> measurementList = new ArrayList<>();
|
|
|
|
|
|
|
|
List<OSProcess> processList = systemInfo.getOperatingSystem().getProcesses();
|
|
|
|
for(OSProcess p : processList) {
|
|
|
|
|
|
|
|
// Skip all the kernel processes
|
|
|
|
if(p.getResidentSetSize() < 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-09-14 07:00:34 +00:00
|
|
|
// Skip short-lived processes
|
|
|
|
if(p.getUpTime() < (minUptimeInSeconds * 1000)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-09-17 09:53:57 +00:00
|
|
|
// Skip process names not found in our includeList, only if the list is not empty or null
|
|
|
|
if(includeList != null && !includeList.isEmpty() && !includeList.contains(p.getName())) {
|
2021-09-02 19:40:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-09-17 09:53:57 +00:00
|
|
|
log.debug("pid: " + p.getProcessID() + ", name: " + p.getName() + ", virt: " + p.getVirtualSize() + " rss: " + p.getResidentSetSize());
|
2021-09-02 19:40:22 +00:00
|
|
|
|
2022-11-07 12:33:35 +00:00
|
|
|
TreeMap<String, String> tagsMap = new TreeMap<String, String>() {{
|
2021-09-13 15:13:58 +00:00
|
|
|
put("pid", String.valueOf(p.getProcessID()));
|
2021-09-17 09:53:57 +00:00
|
|
|
put("name", p.getName());
|
2021-09-13 15:13:58 +00:00
|
|
|
}};
|
|
|
|
|
2022-11-07 12:33:35 +00:00
|
|
|
TreeMap<String, Object> fieldsMap = new TreeMap<String, Object>() {{
|
2021-09-13 15:13:58 +00:00
|
|
|
put("mem_rss", p.getResidentSetSize());
|
|
|
|
put("mem_vsz", p.getVirtualSize());
|
|
|
|
put("kernel_time", p.getKernelTime());
|
|
|
|
put("user_time", p.getUserTime());
|
|
|
|
put("read_bytes", p.getBytesRead());
|
|
|
|
put("write_bytes", p.getBytesWritten());
|
|
|
|
put("files", p.getOpenFiles());
|
|
|
|
put("threads", p.getThreadCount());
|
|
|
|
put("user", p.getUser());
|
|
|
|
put("group", p.getGroup());
|
|
|
|
put("prio", p.getPriority());
|
|
|
|
}};
|
2021-09-02 19:40:22 +00:00
|
|
|
|
|
|
|
measurementList.add(new Measurement(tagsMap, fieldsMap));
|
|
|
|
}
|
|
|
|
|
|
|
|
//log.info("Size of measurements: " + measurementList.size());
|
2021-09-10 10:15:33 +00:00
|
|
|
return new MetricResult(name, measurementList);
|
2021-09-02 19:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|