2022-12-21 16:12:15 +00:00
|
|
|
package sysmon.plugins.base;
|
2021-09-11 19:55:48 +00:00
|
|
|
|
|
|
|
import org.pf4j.Extension;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import oshi.SystemInfo;
|
|
|
|
import oshi.hardware.HardwareAbstractionLayer;
|
|
|
|
import oshi.software.os.OSFileStore;
|
|
|
|
import sysmon.shared.Measurement;
|
|
|
|
import sysmon.shared.MetricExtension;
|
|
|
|
import sysmon.shared.MetricResult;
|
|
|
|
|
2022-11-07 12:33:35 +00:00
|
|
|
import java.util.*;
|
2021-09-11 19:55:48 +00:00
|
|
|
|
|
|
|
@Extension
|
|
|
|
public class BaseFilesystemExtension implements MetricExtension {
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(BaseDiskExtension.class);
|
|
|
|
|
|
|
|
// Extension details
|
|
|
|
private final String name = "base_filesystem";
|
|
|
|
private final String description = "Base Filesystem 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 = "10s";
|
2021-09-11 19:55:48 +00:00
|
|
|
private List<?> excludeType = new ArrayList<String>() {{
|
|
|
|
add("tmpfs");
|
|
|
|
add("ahafs");
|
|
|
|
}};
|
|
|
|
private List<?> excludeMount = new ArrayList<String>() {{
|
|
|
|
add("/boot/efi");
|
|
|
|
}};
|
|
|
|
|
|
|
|
private SystemInfo systemInfo;
|
2022-11-16 11:21:33 +00:00
|
|
|
private List<OSFileStore> fileStores;
|
|
|
|
private int refreshCounter = 0;
|
2021-09-11 19:55:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled() {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
2021-11-06 19:32:54 +00:00
|
|
|
@Override
|
|
|
|
public boolean isThreaded() {
|
|
|
|
return threaded;
|
|
|
|
}
|
|
|
|
|
2021-09-11 19:55:48 +00:00
|
|
|
@Override
|
|
|
|
public boolean isSupported() {
|
|
|
|
systemInfo = BasePlugin.getSystemInfo();
|
|
|
|
//hardwareAbstractionLayer = BasePlugin.getHardwareAbstractionLayer();
|
|
|
|
return systemInfo != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
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-11 19:55:48 +00:00
|
|
|
@Override
|
|
|
|
public String getDescription() {
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-11 19:55:48 +00:00
|
|
|
if(map.containsKey("exclude_type")) {
|
|
|
|
excludeType = (List<?>) map.get("exclude_type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(map.containsKey("exclude_mount")) {
|
|
|
|
excludeMount = (List<?>) map.get("exclude_mount");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public MetricResult getMetrics() {
|
|
|
|
|
|
|
|
ArrayList<String> alreadyProcessed = new ArrayList<>();
|
|
|
|
ArrayList<Measurement> measurementList = new ArrayList<>();
|
2022-11-16 11:21:33 +00:00
|
|
|
|
|
|
|
if(fileStores == null || refreshCounter++ > 360) {
|
|
|
|
fileStores = systemInfo.getOperatingSystem().getFileSystem().getFileStores(true);
|
|
|
|
}
|
2021-09-11 19:55:48 +00:00
|
|
|
|
|
|
|
for(OSFileStore store : fileStores) {
|
|
|
|
|
|
|
|
String name = store.getName();
|
|
|
|
String type = store.getType();
|
|
|
|
String mount = store.getMount();
|
|
|
|
|
|
|
|
if(excludeType.contains(type)) {
|
|
|
|
log.debug("Excluding type: " + type);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(excludeMount.contains(mount)) {
|
|
|
|
log.debug("Excluding mount: " + mount);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(alreadyProcessed.contains(name)) {
|
|
|
|
log.debug("Skipping name: " + name);
|
|
|
|
continue;
|
|
|
|
}
|
2022-11-16 11:21:33 +00:00
|
|
|
|
2021-09-11 19:55:48 +00:00
|
|
|
alreadyProcessed.add(name);
|
2022-11-16 11:21:33 +00:00
|
|
|
store.updateAttributes();
|
2021-09-11 19:55:48 +00:00
|
|
|
|
2022-11-07 12:33:35 +00:00
|
|
|
TreeMap<String, String> tagsMap = new TreeMap<String, String>() {{
|
2021-09-11 19:55:48 +00:00
|
|
|
put("name", name);
|
|
|
|
put("type", type);
|
|
|
|
put("mount", mount);
|
|
|
|
}};
|
|
|
|
|
2022-11-07 12:33:35 +00:00
|
|
|
TreeMap<String, Object> fieldsMap = new TreeMap<String, Object>() {{
|
2021-09-11 19:55:48 +00:00
|
|
|
put("free_bytes", store.getFreeSpace());
|
|
|
|
put("total_bytes", store.getTotalSpace());
|
|
|
|
put("free_inodes", store.getFreeInodes());
|
|
|
|
put("total_inodes", store.getTotalInodes());
|
|
|
|
}};
|
|
|
|
|
|
|
|
measurementList.add(new Measurement(tagsMap, fieldsMap));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new MetricResult(name, measurementList);
|
|
|
|
}
|
|
|
|
|
2022-09-06 13:08:52 +00:00
|
|
|
}
|