org.hyperic.sigar.FileSystem Java Examples

The following examples show how to use org.hyperic.sigar.FileSystem. 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: SystemRuntime.java    From sigar-system_runtime with MIT License 6 votes vote down vote up
public void file() throws Exception {
    FileSystem fslist[] = sigar.getFileSystemList();
    for (int i = 0; i < fslist.length; i++) {
        System.out.println("分区的盘符名称" + i);
        FileSystem fs = fslist[i];
        // 分区的盘符名称
        System.out.println("盘符名称:    " + fs.getDevName());
        // 分区的盘符名称
        System.out.println("盘符路径:    " + fs.getDirName());
        System.out.println("盘符标志:    " + fs.getFlags());//
        // 文件系统类型,比如 FAT32、NTFS
        System.out.println("盘符类型:    " + fs.getSysTypeName());
        // 文件系统类型名,比如本地硬盘、光驱、网络文件系统等
        System.out.println("盘符类型名:    " + fs.getTypeName());
        // 文件系统类型
        System.out.println("盘符文件系统类型:    " + fs.getType());
        FileSystemUsage usage = null;
        usage = sigar.getFileSystemUsage(fs.getDirName());
        System.out.println(fs.getDevName() + "读出:    " + usage.getDiskReads());
        System.out.println(fs.getDevName() + "写入:    " + usage.getDiskWrites());
    }
    return;
}
 
Example #2
Source File: PerformanceService.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
/**
 * getConfigInfo.
 * 
 * @return
 */
public Map<String, String> getConfigInfo() throws UnknownHostException, SigarException {
    log.info("getConfigInfo.");
    Map<String, String> configMap = new HashMap<>();
    String ip = getIp();
    log.debug("local ip:    " + ip);
    configMap.put("ip", ip);
    Mem mem = sigar.getMem();
    log.debug("memory total:    " + mem.getTotal() / 1024L + "K av");
    log.debug("memory used now:    " + mem.getUsed() / 1024L + "K used");
    configMap.put("memoryTotalSize", Long.toString(mem.getTotal() / 1024L));
    configMap.put("memoryUsedSize", Long.toString(mem.getUsed() / 1024L));
    CpuPerc cpu = sigar.getCpuPerc();
    CpuInfo[] infos = sigar.getCpuInfoList();
    log.debug("CPU mhz:    " + infos[0].getMhz());
    log.debug("CPU core number:    " + infos.length);
    configMap.put("cpuSize", Integer.toString(infos[0].getMhz()));
    configMap.put("cpuAmount", Integer.toString(infos.length));
    long total;
    long use;
    FileSystem[] fslist = sigar.getFileSystemList();
    log.debug("****fs " + fslist.length);
    use = sigar.getFileSystemUsage(constants.getMonitorDisk()).getUsed();
    total = sigar.getFileSystemUsage(constants.getMonitorDisk()).getTotal();
    log.debug("diskTotalSize:    " + total);
    log.debug("diskUsedSize:    " + use);
    configMap.put("diskTotalSize", Long.toString(total));
    configMap.put("diskUsedSize", Long.toString(use));
    return configMap;
}
 
Example #3
Source File: MachineDescriptionOperations.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
private StringBuilder getInfoFromSigar() throws Exception {

        StringBuilder sb = new StringBuilder();
        Sigar sigar = new Sigar();

        sb.append("Fully Qualified Domain Name:\n\t" + sigar.getFQDN().toString());
        sb.append("\nSystem uptime:\n\t" + new Double(sigar.getUptime().getUptime()).intValue()
                  + " seconds");
        sb.append("\nDate:\n\t" + new Date());
        sb.append("\nNetwork settings:" + format(sigar.getNetInfo().toString(), 1));

        sb.append("\nCPU info:");
        CpuInfo[] cpuInfoList = sigar.getCpuInfoList();
        for (int i = 0; i < cpuInfoList.length; i++) {
            CpuInfo cpuInfo = cpuInfoList[i];
            sb.append("\n\tCPU " + i + ": ");
            sb.append(format(cpuInfo.toString(), 2));
        }

        double totalMemory = (new Long(sigar.getMem().getTotal()).doubleValue() / 1024 / 1024 / 1024);
        sb.append("\nTotal memory:\n\t"
                  + new BigDecimal(totalMemory).setScale(2, BigDecimal.ROUND_DOWN).floatValue() + " GB");

        String[] nicList = sigar.getNetInterfaceList();
        sb.append("\nNIC info: ");
        for (int i = 0; i < nicList.length; i++) {
            NetInterfaceConfig nic = sigar.getNetInterfaceConfig(nicList[i]);
            sb.append("\n\tNIC " + i + ": ");
            sb.append(format(nic.toString(), 2));
        }

        FileSystem[] fileSystemList = sigar.getFileSystemList();
        sb.append("\nFile system info: ");
        for (int i = 0; i < fileSystemList.length; i++) {
            FileSystem fileSystem = fileSystemList[i];

            sb.append("\n\t" + fileSystem.getDevName() + " is a");
            if (fileSystem.getType() == FileSystem.TYPE_LOCAL_DISK) {
                sb.append(" local");
            } else if (fileSystem.getType() == FileSystem.TYPE_NETWORK) {
                sb.append(" network");
            } else if (fileSystem.getType() == FileSystem.TYPE_RAM_DISK) {
                sb.append(" ram disk");
            } else if (fileSystem.getType() == FileSystem.TYPE_SWAP) {
                sb.append(" swap");
            }

            sb.append(" " + fileSystem.getSysTypeName() + ", dir name '" + fileSystem.getDirName()
                      + "', options '" + fileSystem.getOptions() + "'");
        }

        sb.append("\nResource limits:" + format(sigar.getResourceLimit().toString(), "max", 1));
        return sb;
    }
 
Example #4
Source File: IOReadingInstancesFactory.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
/**
 * Get device names for monitoring - disk(AIX) or logical volume names
 * <p><em>Note</em>: For AIX for example a disk names should be returned.
 * As later Sigar invokes getDiskUsage(name). Check on Linux
 * </p>
 * @param sigarWrapper
 * @param readBytes
 * @return
 * @throws SigarException
 */
private static List<String> getDevicesForIoMonitoring(
                                                       SigarWrapper sigarWrapper,
                                                       boolean readBytes ) throws SigarException {

    List<String> devices = new LinkedList<String>();
    StringBuilder problematicMounts = new StringBuilder();

    if (IS_AIX_OS) {
        String[] cmdCommand = new String[]{ "/bin/sh", "-c", "lspv 2>&1" };
        String result = null;
        try {
            Process p = Runtime.getRuntime().exec(cmdCommand);
            result = IoUtils.streamToString(p.getInputStream()).trim();
        } catch (Exception e) {
            throw new RuntimeException("Error getting devices to monitor for IO (Read/Write) transfer. lspv command invoke error",
                                       e);
        }
        String[] lines = result.split("[\r\n]+");
        int lineNum = 0;
        for (String line : lines) {
            lineNum++;
            LOG.trace("Get AIX device[" + lineNum + "]: " + line);
            String[] words = line.split("[\\s]+");
            if (words.length > 0) {
                LOG.trace(" Found disk: " + words[0]);
                if (getReadWriteBytes(sigarWrapper, words[0], readBytes) == -1) {
                    problematicMounts.append("'" + words[0] + "', ");
                } else {
                    devices.add(words[0]);
                }
            }
        }
    } else {
        FileSystem[] fslist = sigarWrapper.getSigarInstance().getFileSystemList();
        for (int i = 0; i < fslist.length; i++) {
            if (fslist[i].getType() == FileSystem.TYPE_LOCAL_DISK) {
                if (getReadWriteBytes(sigarWrapper, fslist[i].getDevName(), readBytes) == -1) {
                    problematicMounts.append("'" + fslist[i].getDevName() + "', ");
                } else {
                    devices.add(fslist[i].getDevName());
                }
            }
        }
    }

    if (problematicMounts.length() > 0) {

        LOG.warn("Unable to get " + (readBytes
                                               ? "Read"
                                               : "Write")
                 + "Bytes on devices: "
                 + problematicMounts.substring(0, problematicMounts.length() - 2));
    }
    return devices;
}
 
Example #5
Source File: sigar.java    From sigar-system_runtime with MIT License 4 votes vote down vote up
private static void file() throws Exception {
    Sigar sigar = new Sigar();
    FileSystem fslist[] = sigar.getFileSystemList();
    for (int i = 0; i < fslist.length; i++) {
        System.out.println("分区的盘符名称" + i);
        FileSystem fs = fslist[i];
        // 分区的盘符名称
        System.out.println("盘符名称:    " + fs.getDevName());
        // 分区的盘符名称
        System.out.println("盘符路径:    " + fs.getDirName());
        System.out.println("盘符标志:    " + fs.getFlags());//
        // 文件系统类型,比如 FAT32、NTFS
        System.out.println("盘符类型:    " + fs.getSysTypeName());
        // 文件系统类型名,比如本地硬盘、光驱、网络文件系统等
        System.out.println("盘符类型名:    " + fs.getTypeName());
        // 文件系统类型
        System.out.println("盘符文件系统类型:    " + fs.getType());
        FileSystemUsage usage = null;
        usage = sigar.getFileSystemUsage(fs.getDirName());
        switch (fs.getType()) {
        case 0: // TYPE_UNKNOWN :未知
            break;
        case 1: // TYPE_NONE
            break;
        case 2: // TYPE_LOCAL_DISK : 本地硬盘
            // 文件系统总大小
            System.out.println(fs.getDevName() + "总大小:    " + usage.getTotal() + "KB");
            // 文件系统剩余大小
            System.out.println(fs.getDevName() + "剩余大小:    " + usage.getFree() + "KB");
            // 文件系统可用大小
            System.out.println(fs.getDevName() + "可用大小:    " + usage.getAvail() + "KB");
            // 文件系统已经使用量
            System.out.println(fs.getDevName() + "已经使用量:    " + usage.getUsed() + "KB");
            double usePercent = usage.getUsePercent() * 100D;
            // 文件系统资源的利用率
            System.out.println(fs.getDevName() + "资源的利用率:    " + usePercent + "%");
            break;
        case 3:// TYPE_NETWORK :网络
            break;
        case 4:// TYPE_RAM_DISK :闪存
            break;
        case 5:// TYPE_CDROM :光驱
            break;
        case 6:// TYPE_SWAP :页面交换
            break;
        }
        System.out.println(fs.getDevName() + "读出:    " + usage.getDiskReads());
        System.out.println(fs.getDevName() + "写入:    " + usage.getDiskWrites());
    }
    return;
}
 
Example #6
Source File: FileSystemInfo.java    From maintain with MIT License 4 votes vote down vote up
public FileSystemInfo(FileSystem fileSystem, FileSystemUsage fileSystemUsage) {
	this.fileSystem = fileSystem;
	this.fileSystemUsage = fileSystemUsage;
}
 
Example #7
Source File: FileSystemInfo.java    From maintain with MIT License 4 votes vote down vote up
public FileSystem getFileSystem() {
	return fileSystem;
}
 
Example #8
Source File: FileSystemInfo.java    From maintain with MIT License 4 votes vote down vote up
public void setFileSystem(FileSystem fileSystem) {
	this.fileSystem = fileSystem;
}
 
Example #9
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) throws SigarException {
	if (!monitoringController.isMonitoringEnabled()) {
		return;
	}
	if (!monitoringController.isProbeActivated(SignatureFactory.createDiskUsageSignature())) {
		return;
	}

	for (final FileSystem fileSystem : this.sigar.getFileSystemList()) {
		if (fileSystem.getType() == FileSystem.TYPE_LOCAL_DISK) {
			final String deviceName = fileSystem.getDevName();
			final ITimeSource timesource = monitoringController.getTimeSource();
			final TimeUnit timeUnit = timesource.getTimeUnit();
			final DiskUsageStatistic currentDiskUsageStatistic = this.getCurrentDiskUsageStatistic(timesource, deviceName);

			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);
			}
		}
	}
}