Search in sources :

Example 1 with HWDiskStore

use of oshi.hardware.HWDiskStore in project graylog2-server by Graylog2.

the class OshiFsProbe method init.

private void init() {
    final OperatingSystem os = service.getOs();
    final FileSystem fileSystem = os.getFileSystem();
    final HardwareAbstractionLayer hardware = service.getHal();
    for (Path location : locations) {
        Path path = location.toAbsolutePath();
        oshiFileSystems.put(path, fileSystem.getFileStores().stream().filter(fs -> path.startsWith(fs.getMount())).max(Comparator.comparingInt(p -> Paths.get(p.getMount()).getNameCount())).map(fs -> {
            // First try search for the diskstore with the logical volume or volume name
            Optional<HWDiskStore> diskStore = hardware.getDiskStores().stream().filter(ds -> ds.getName().equals(StringUtils.defaultIfEmpty(fs.getLogicalVolume(), fs.getVolume()))).findFirst();
            if (diskStore.isPresent()) {
                return new Pair<>(fs, diskStore.get());
            }
            // Try to search for the diskstore with the partition of our mountpoint
            diskStore = hardware.getDiskStores().stream().filter(ds -> ds.getPartitions().stream().anyMatch(part -> path.startsWith(part.getMountPoint()))).max(Comparator.comparingInt(ds -> ds.getPartitions().stream().filter(part -> path.startsWith(part.getMountPoint())).mapToInt(part -> Paths.get(part.getMountPoint()).getNameCount()).max().orElse(0)));
            if (diskStore.isPresent()) {
                return new Pair<>(fs, diskStore.get());
            }
            return new Pair<>(fs, generateDummyDiskStore());
        }).orElse(new Pair<>(generateDummyFileStore(), generateDummyDiskStore())));
    }
}
Also used : OperatingSystem(oshi.software.os.OperatingSystem) HardwareAbstractionLayer(oshi.hardware.HardwareAbstractionLayer) Path(java.nio.file.Path) Pair(oshi.util.tuples.Pair) java.util(java.util) ImmutableSet(com.google.common.collect.ImmutableSet) KafkaJournalConfiguration(org.graylog2.plugin.KafkaJournalConfiguration) AbstractOSFileStore(oshi.software.common.AbstractOSFileStore) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) AbstractHWDiskStore(oshi.hardware.common.AbstractHWDiskStore) OSFileStore(oshi.software.os.OSFileStore) OperatingSystem(oshi.software.os.OperatingSystem) Inject(javax.inject.Inject) FileSystem(oshi.software.os.FileSystem) Configuration(org.graylog2.Configuration) Paths(java.nio.file.Paths) HWDiskStore(oshi.hardware.HWDiskStore) HardwareAbstractionLayer(oshi.hardware.HardwareAbstractionLayer) HWPartition(oshi.hardware.HWPartition) Path(java.nio.file.Path) OshiService(org.graylog2.shared.system.stats.OshiService) FileSystem(oshi.software.os.FileSystem) AbstractHWDiskStore(oshi.hardware.common.AbstractHWDiskStore) HWDiskStore(oshi.hardware.HWDiskStore) Pair(oshi.util.tuples.Pair)

Example 2 with HWDiskStore

use of oshi.hardware.HWDiskStore in project Nukkit by Nukkit.

the class BugReportGenerator method generate.

private String generate() throws IOException {
    File reports = new File(Nukkit.DATA_PATH, "logs/bug_reports");
    if (!reports.isDirectory()) {
        reports.mkdirs();
    }
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmSS");
    String date = simpleDateFormat.format(new Date());
    SystemInfo systemInfo = new SystemInfo();
    long totalDiskSize = 0;
    StringBuilder model = new StringBuilder();
    for (HWDiskStore hwDiskStore : systemInfo.getHardware().getDiskStores()) {
        totalDiskSize += hwDiskStore.getSize();
        if (!model.toString().contains(hwDiskStore.getModel())) {
            model.append(hwDiskStore.getModel()).append(" ");
        }
    }
    StringWriter stringWriter = new StringWriter();
    throwable.printStackTrace(new PrintWriter(stringWriter));
    File mdReport = new File(reports, date + "_" + throwable.getClass().getSimpleName() + ".md");
    mdReport.createNewFile();
    String content = Utils.readFile(this.getClass().getClassLoader().getResourceAsStream("report_template.md"));
    Properties properties = getGitRepositoryState();
    System.out.println(properties.getProperty("git.commit.id.abbrev"));
    String abbrev = properties.getProperty("git.commit.id.abbrev");
    content = content.replace("${NUKKIT_VERSION}", Nukkit.VERSION);
    content = content.replace("${GIT_COMMIT_ABBREV}", abbrev);
    content = content.replace("${JAVA_VERSION}", System.getProperty("java.vm.name") + " (" + System.getProperty("java.runtime.version") + ")");
    content = content.replace("${HOSTOS}", systemInfo.getOperatingSystem().getFamily() + " [" + systemInfo.getOperatingSystem().getVersion().getVersion() + "]");
    content = content.replace("${MEMORY}", getCount(systemInfo.getHardware().getMemory().getTotal(), true));
    content = content.replace("${STORAGE_SIZE}", getCount(totalDiskSize, true));
    content = content.replace("${CPU_TYPE}", systemInfo.getHardware().getProcessor().getName());
    content = content.replace("${PHYSICAL_CORE}", String.valueOf(systemInfo.getHardware().getProcessor().getPhysicalProcessorCount()));
    content = content.replace("${LOGICAL_CORE}", String.valueOf(systemInfo.getHardware().getProcessor().getLogicalProcessorCount()));
    content = content.replace("${STACKTRACE}", stringWriter.toString());
    content = content.replace("${PLUGIN_ERROR}", String.valueOf(!throwable.getStackTrace()[0].getClassName().startsWith("cn.nukkit")).toUpperCase());
    content = content.replace("${STORAGE_TYPE}", model.toString());
    Utils.writeFile(mdReport, content);
    return mdReport.getAbsolutePath();
}
Also used : SystemInfo(oshi.SystemInfo) StringWriter(java.io.StringWriter) Properties(java.util.Properties) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) HWDiskStore(oshi.hardware.HWDiskStore) PrintWriter(java.io.PrintWriter)

Aggregations

HWDiskStore (oshi.hardware.HWDiskStore)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 SimpleDateFormat (java.text.SimpleDateFormat)1 java.util (java.util)1 Date (java.util.Date)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Configuration (org.graylog2.Configuration)1 KafkaJournalConfiguration (org.graylog2.plugin.KafkaJournalConfiguration)1 OshiService (org.graylog2.shared.system.stats.OshiService)1 SystemInfo (oshi.SystemInfo)1 HWPartition (oshi.hardware.HWPartition)1 HardwareAbstractionLayer (oshi.hardware.HardwareAbstractionLayer)1