Get disk information with the SIGAR API

Source: Internet
Author: User

SIGAR (full Name System Information Gatherer and Reporter, which is the Systems information Collection Report), provides an open source, cross-platform API for collecting computer hardware and operating system information (the API's underlying interface is written in C). This article shows you how to get disk information with the SIGAR API:

Package Com.ghj.packageoftest;import Org.hyperic.sigar.filesystem;import Org.hyperic.sigar.filesystemusage;import  Org.hyperic.sigar.sigar;import org.hyperic.sigar.sigarexception;/** * Get disk information with SIGAR API * * @author Gaohuanjie */public        Class Disktool {public static void main (string[] args) throws Sigarexception {SIGAR SIGAR = new SIGAR ();        FileSystem [] Filesystemarray = Sigar.getfilesystemlist (); for (FileSystem Filesystem:filesystemarray) {System.out.println ("FileSystem dirName:" + filesystem.getdirname ()) ;//partition of the drive letter name System.out.println ("FileSystem devname:" + filesystem.getdevname ());//partition of the drive letter name System.ou T.println ("FileSystem typeName:" + filesystem.gettypename ());//File system type name, such as local hard disk, optical drive, network file system, etc. System.out.println ( "FileSystem systypename:" + filesystem.getsystypename ());//file system type, such as FAT32, NTFS System.out.println ("FileSystem            Options: "+ filesystem.getoptions ()); SYSTEM.OUT.PRINTLN ("FileSystem Flags:" + FilesystEm.getflags ());                        System.out.println ("FileSystem type:" + filesystem.gettype ());                        Filesystemusage filesystemusage = null;            try {filesystemusage = Sigar.getfilesystemusage (Filesystem.getdirname ());            } catch (Sigarexception e) {//when Filesystem.gettype () is 5 This exception occurs-the file system type is optical drive continue; } System.out.println ("Filesystemusage total:" + filesystemusage.gettotal () + "KB");//File system overall Size system . OUT.PRINTLN ("Filesystemusage free:" + filesystemusage.getfree () + "KB");//File system remaining size System.out.println ("files Ystemusage used: "+ filesystemusage.getused () +" KB ");//file system used size System.out.println (" Filesystemusage Avail: " + filesystemusage.getavail () + "KB");//File system available size System.out.println ("Filesystemusage files:" + filesystemusage.            GetFiles ());            System.out.println ("Filesystemusage freefiles:" + filesystemusage.getfreefiles ()); System.out.println ("Filesystemusage diskreadbytes:" + filesystemusage.getdiskreadbytes ());            System.out.println ("Filesystemusage diskwritebytes:" + filesystemusage.getdiskwritebytes ());            System.out.println ("Filesystemusage diskqueue:" + filesystemusage.getdiskqueue ());            System.out.println ("Filesystemusage diskservicetime:" + filesystemusage.getdiskservicetime ()); System.out.println ("Filesystemusage usepercent:" + filesystemusage.getusepercent () * 100 + "%");//File System resource utilization system.            Out.println ("Filesystemusage diskreads:" + filesystemusage.getdiskreads ());    System.out.println ("Filesystemusage diskwrites:" + filesystemusage.getdiskwrites ());        System.err.println ("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); }}}
0 min Download Sample project

Get disk information with the SIGAR API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.