oshi.hardware.HWDiskStore Java Examples

The following examples show how to use oshi.hardware.HWDiskStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystemMonitorUtil.java    From base-admin with MIT License 6 votes vote down vote up
/**
 * 获取Windows 磁盘使用率
 *
 * @return 磁盘使用率
 */
private static HashMap<String, Long> getWinDiskUsage() {
    HardwareAbstractionLayer hal = systemInfo.getHardware();
    HWDiskStore[] diskStores = hal.getDiskStores();
    HashMap<String, Long> hashMap = new HashMap<>();
    long total = 0;
    long used = 0;
    if (diskStores != null && diskStores.length > 0) {
        for (HWDiskStore diskStore : diskStores) {
            long size = diskStore.getSize();
            long writeBytes = diskStore.getWriteBytes();
            total += size;
            used += writeBytes;
        }
    }
    hashMap.put("total",total);
    hashMap.put("used",used);
    return hashMap;
}
 
Example #2
Source File: DiskStatistics.java    From garmadon with Apache License 2.0 6 votes vote down vote up
@Override
protected void innerCollect(StatisticsSink sink) throws Throwable {
    int i = 0;
    for (HWDiskStore disk : disks) {
        String name = disk.getName().replace("/dev/", "");
        disk.updateDiskStats();
        sink.add(name + DISK_READS_SUFFIX, disk.getReads() - previousReads[i]);
        previousReads[i] = disk.getReads();
        sink.add(name + DISK_READBYTES_SUFFIX, disk.getReadBytes() - previousReadBytes[i]);
        previousReadBytes[i] = disk.getReadBytes();
        sink.add(name + DISK_WRITES_SUFFIX, disk.getWrites() - previousWrites[i]);
        previousWrites[i] = disk.getWrites();
        sink.add(name + DISK_WRITEBYTES_SUFFIX, disk.getWriteBytes() - previousWriteBytes[i]);
        previousWriteBytes[i] = disk.getWriteBytes();
        i++;
    }
}
 
Example #3
Source File: HWIDProvider.java    From Launcher with GNU General Public License v3.0 5 votes vote down vote up
public String getHWDiskID() {
    HWDiskStore[] hwDiskStore = hardware.getDiskStores();
    long size = 0;
    HWDiskStore maxStore = null;
    for (HWDiskStore store : hwDiskStore) {
        if (store.getSize() > size) {
            maxStore = store;
            size = store.getSize();
        }
    }
    if (maxStore != null) {
        return maxStore.getSerial();
    }
    return null;
}
 
Example #4
Source File: NativeCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
private void printDiskInfo(CommandSender sender, HWDiskStore[] diskStores) {
    //disk read write
    long diskReads = Arrays.stream(diskStores).mapToLong(HWDiskStore::getReadBytes).sum();
    long diskWrites = Arrays.stream(diskStores).mapToLong(HWDiskStore::getWriteBytes).sum();

    sendMessage(sender, "Disk read bytes", LagUtils.readableBytes(diskReads));
    sendMessage(sender, "Disk write bytes", LagUtils.readableBytes(diskWrites));

    sender.sendMessage(PRIMARY_COLOR + "Disks:");
    for (HWDiskStore disk : diskStores) {
        String size = LagUtils.readableBytes(disk.getSize());
        sendMessage(sender, "    " + disk.getName(), disk.getModel() + ' ' + size);
    }
}
 
Example #5
Source File: DiskUsageSampler.java    From kieker with Apache License 2.0 5 votes vote down vote up
private DiskUsageStatistic getCurrentDiskUsageStatistic(final ITimeSource timesource, final String deviceName,
		final HWDiskStore hwDiskStore) {
	final long currentTimestamp = timesource.getTime();
	final double queue = hwDiskStore.getCurrentQueueLength();
	final long readBytes = hwDiskStore.getReadBytes();
	final long reads = hwDiskStore.getReads();
	final double serviceTime = hwDiskStore.getTimeStamp();
	final long writeBytes = hwDiskStore.getWriteBytes();
	final long writes = hwDiskStore.getWrites();

	return new DiskUsageStatistic(currentTimestamp, queue, readBytes, reads, serviceTime, writeBytes, writes);
}
 
Example #6
Source File: NativeCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
private void printDiskInfo(CommandSender sender, HWDiskStore[] diskStores) {
    //disk read write
    long diskReads = Arrays.stream(diskStores).mapToLong(HWDiskStore::getReadBytes).sum();
    long diskWrites = Arrays.stream(diskStores).mapToLong(HWDiskStore::getWriteBytes).sum();

    sendMessage(sender, "Disk read bytes", LagUtils.readableBytes(diskReads));
    sendMessage(sender, "Disk write bytes", LagUtils.readableBytes(diskWrites));

    sender.sendMessage(PRIMARY_COLOR + "Disks:");
    for (HWDiskStore disk : diskStores) {
        String size = LagUtils.readableBytes(disk.getSize());
        sendMessage(sender, "    " + disk.getName(), disk.getModel() + ' ' + size);
    }
}
 
Example #7
Source File: BugReportGenerator.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
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();
}
 
Example #8
Source File: DiskUsageSampler.java    From kieker with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void sample(final IMonitoringController monitoringController) {
	if (!monitoringController.isMonitoringEnabled() || !monitoringController.isProbeActivated(SignatureFactory.createDiskUsageSignature())) {
		return;
	}
	final HWDiskStore[] hwDistStores = this.hardwareAbstractionLayer.getDiskStores();
	for (final HWDiskStore hwDistStore : hwDistStores) {
		final String deviceName = hwDistStore.getName();
		final ITimeSource timesource = monitoringController.getTimeSource();
		final TimeUnit timeUnit = timesource.getTimeUnit();
		final DiskUsageStatistic currentDiskUsageStatistic = this.getCurrentDiskUsageStatistic(timesource,
				deviceName, hwDistStore);

		if (!this.diskUsageStatisticMap.containsKey(deviceName)) {
			this.diskUsageStatisticMap.putIfAbsent(deviceName, currentDiskUsageStatistic);
		} else {
			final DiskUsageStatistic lastObservedDiskUsageStatistic = this.diskUsageStatisticMap.get(deviceName);
			final long timeDifference = currentDiskUsageStatistic.getTimestamp()
					- lastObservedDiskUsageStatistic.getTimestamp();
			if (timeDifference <= 0) {
				throw new IllegalStateException(
						"Timestamp of new observation should be strictly larger than the previous one.");
			}
			final double currentQueue = currentDiskUsageStatistic.getQueue();
			final long readBytesDifference = currentDiskUsageStatistic.getReadBytes()
					- lastObservedDiskUsageStatistic.getReadBytes();
			final long readsDifference = currentDiskUsageStatistic.getReads()
					- lastObservedDiskUsageStatistic.getReads();
			final double currentServiceTime = currentDiskUsageStatistic.getServiceTime();
			final long writeBytesDifference = currentDiskUsageStatistic.getWriteBytes()
					- lastObservedDiskUsageStatistic.getWriteBytes();
			final long writesDifference = currentDiskUsageStatistic.getWrites()
					- lastObservedDiskUsageStatistic.getWrites();

			final double readBytesPerSecond = readBytesDifference
					/ (double) TimeUnit.SECONDS.convert(timeDifference, timeUnit);
			final double readsPerSecond = readsDifference
					/ (double) TimeUnit.SECONDS.convert(timeDifference, timeUnit);
			final double writeBytesPerSecond = writeBytesDifference
					/ (double) TimeUnit.SECONDS.convert(timeDifference, timeUnit);
			final double writesPerSecond = writesDifference
					/ (double) TimeUnit.SECONDS.convert(timeDifference, timeUnit);

			final DiskUsageRecord diskUsageRecord = new DiskUsageRecord(currentDiskUsageStatistic.getTimestamp(),
					monitoringController.getHostname(), deviceName, currentQueue, readBytesPerSecond,
					readsPerSecond, currentServiceTime, writeBytesPerSecond, writesPerSecond);
			monitoringController.newMonitoringRecord(diskUsageRecord);

			this.diskUsageStatisticMap.put(deviceName, currentDiskUsageStatistic);
		}

	}
}