org.hyperic.sigar
Class Sigar

java.lang.Object
  extended by org.hyperic.sigar.Sigar
All Implemented Interfaces:
SigarProxy

public class Sigar
extends java.lang.Object
implements SigarProxy

The Sigar class provides access to the sigar objects containing system information. The Sigar object itself maintains internal state specific to each platform. It also implements the SigarProxy interface which provides caching at the Java level.


Field Summary
static java.lang.String BUILD_DATE
          The date on which sigar.jar was built.
static long FIELD_NOTIMPL
           
static java.lang.String NATIVE_BUILD_DATE
          The date on which the sigar native binary was built.
static java.lang.String NATIVE_SCM_REVISION
          The scm (svn) revision from which the sigar native binary was built.
static java.lang.String NATIVE_VERSION_STRING
          The Sigar native version.
static java.lang.String SCM_REVISION
          The scm (svn) revision from which sigar.jar was built.
static java.lang.String VERSION_STRING
          The Sigar java version.
 
Constructor Summary
Sigar()
          Allocate and initialize the native Sigar object.
 
Method Summary
 void close()
          Release any native resources associated with this sigar instance.
 void enableLogging(boolean value)
          Enabling logging in the native Sigar code.
protected  void finalize()
           
static java.lang.String formatSize(long size)
          Format size in bytes to a human readable string.
 Cpu getCpu()
          Get system cpu info.
 CpuInfo[] getCpuInfoList()
          Get list of cpu infomation.
 Cpu[] getCpuList()
          Get list of per-cpu metrics.
 CpuPerc getCpuPerc()
          Get system CPU info in percentage format.
 CpuPerc[] getCpuPercList()
          Get system per-CPU info in percentage format.
 DirStat getDirStat(java.lang.String name)
           
 DirUsage getDirUsage(java.lang.String name)
           
 DiskUsage getDiskUsage(java.lang.String name)
          Get disk usage.
 FileInfo getFileInfo(java.lang.String name)
           
 FileSystem[] getFileSystemList()
          Get list of file systems.
 FileSystemMap getFileSystemMap()
           
 FileSystemUsage getFileSystemUsage(java.lang.String name)
          Get file system usage.
 java.lang.String getFQDN()
          Reliably retrieve the FQDN for a machine
 FileInfo getLinkInfo(java.lang.String name)
           
 double[] getLoadAverage()
          Get system load average.
 Mem getMem()
          Get system memory info.
 FileSystemUsage getMountedFileSystemUsage(java.lang.String name)
          Get file system usage of a mounted directory.
 MultiProcCpu getMultiProcCpu(java.lang.String query)
           
 ProcMem getMultiProcMem(java.lang.String query)
           
 java.io.File getNativeLibrary()
           
 NetConnection[] getNetConnectionList(int flags)
          Get list of network connections.
 NetInfo getNetInfo()
          Get general network info.
 NetInterfaceConfig getNetInterfaceConfig()
          Get default network interface configuration info.
 NetInterfaceConfig getNetInterfaceConfig(java.lang.String name)
          Get network interface configuration info.
 java.lang.String[] getNetInterfaceList()
          Get the list of configured network interface names.
 NetInterfaceStat getNetInterfaceStat(java.lang.String name)
          Get network interface stats.
 java.lang.String getNetListenAddress(long port)
          Get the TCP listen address for the given port.
 java.lang.String getNetListenAddress(java.lang.String port)
           
 NetRoute[] getNetRouteList()
          Get list of network routes.
 java.lang.String getNetServicesName(int protocol, long port)
           
 NetStat getNetStat()
           
 NetStat getNetStat(byte[] address, long port)
           
 NfsClientV2 getNfsClientV2()
           
 NfsClientV3 getNfsClientV3()
           
 NfsServerV2 getNfsServerV2()
           
 NfsServerV3 getNfsServerV3()
           
static java.lang.String getPassword(java.lang.String prompt)
          Prompt for a password, disabling terminal echo during user input if possible.
 long getPid()
          Get pid of the current process.
 java.lang.String[] getProcArgs(long pid)
          Get process arguments.
 java.lang.String[] getProcArgs(java.lang.String pid)
           
 ProcCpu getProcCpu(long pid)
          Get process cpu info.
 ProcCpu getProcCpu(java.lang.String pid)
           
 ProcCred getProcCred(long pid)
          Get process credential info.
 ProcCred getProcCred(java.lang.String pid)
           
 ProcCredName getProcCredName(long pid)
          Get process credential names.
 ProcCredName getProcCredName(java.lang.String pid)
           
 java.util.Map getProcEnv(long pid)
          Get process environment.
 java.lang.String getProcEnv(long pid, java.lang.String key)
          Get process environment variable value.
 java.util.Map getProcEnv(java.lang.String pid)
           
 java.lang.String getProcEnv(java.lang.String pid, java.lang.String key)
           
 ProcExe getProcExe(long pid)
          Get process current working directory.
 ProcExe getProcExe(java.lang.String pid)
           
 ProcFd getProcFd(long pid)
          Get process file descriptor info.
 ProcFd getProcFd(java.lang.String pid)
           
 long[] getProcList()
          Get system process list.
 ProcMem getProcMem(long pid)
          Get process memory info.
 ProcMem getProcMem(java.lang.String pid)
           
 java.util.List getProcModules(long pid)
           
 java.util.List getProcModules(java.lang.String pid)
           
 long getProcPort(int protocol, long port)
          Find the pid of the process which is listening on the given port.
 long getProcPort(java.lang.String protocol, java.lang.String port)
           
 ProcStat getProcStat()
          Get system process stats.
 ProcState getProcState(long pid)
          Get process state info.
 ProcState getProcState(java.lang.String pid)
           
 ProcTime getProcTime(long pid)
          Get process time info.
 ProcTime getProcTime(java.lang.String pid)
           
 ResourceLimit getResourceLimit()
          Get system resource limits.
 long getServicePid(java.lang.String name)
          Get pid for the Windows service with the given name.
static int getSigNum(java.lang.String name)
           
 Swap getSwap()
          Get system swap info.
 Tcp getTcp()
          TCP-MIB stats
 ThreadCpu getThreadCpu()
          Get the cumulative cpu time for the calling thread.
 Uptime getUptime()
          Get system uptime info.
 Who[] getWhoList()
           
 void kill(long pid, int signum)
          Send a signal to a process.
 void kill(long pid, java.lang.String signame)
          Send a signal to a process.
 void kill(java.lang.String pid, int signum)
          Send a signal to a process.
static void load()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIELD_NOTIMPL

public static final long FIELD_NOTIMPL
See Also:
Constant Field Values

VERSION_STRING

public static final java.lang.String VERSION_STRING
The Sigar java version.

See Also:
Constant Field Values

NATIVE_VERSION_STRING

public static final java.lang.String NATIVE_VERSION_STRING
The Sigar native version.


SCM_REVISION

public static final java.lang.String SCM_REVISION
The scm (svn) revision from which sigar.jar was built.

See Also:
Constant Field Values

NATIVE_SCM_REVISION

public static final java.lang.String NATIVE_SCM_REVISION
The scm (svn) revision from which the sigar native binary was built.


BUILD_DATE

public static final java.lang.String BUILD_DATE
The date on which sigar.jar was built.

See Also:
Constant Field Values

NATIVE_BUILD_DATE

public static final java.lang.String NATIVE_BUILD_DATE
The date on which the sigar native binary was built.

Constructor Detail

Sigar

public Sigar()
Allocate and initialize the native Sigar object.

Method Detail

load

public static void load()
                 throws SigarException
Throws:
SigarException

getNativeLibrary

public java.io.File getNativeLibrary()

formatSize

public static java.lang.String formatSize(long size)
Format size in bytes to a human readable string.

Parameters:
size - The size to format.
Returns:
The formatted string.

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object

close

public void close()
Release any native resources associated with this sigar instance. The sigar object is no longer usable after it has been closed. If the close method is not called directly, the finalize method will call it if the Sigar object is garbage collected.


getPid

public long getPid()
Get pid of the current process.

Specified by:
getPid in interface SigarProxy
Throws:
SigarException - on failure.

getServicePid

public long getServicePid(java.lang.String name)
                   throws SigarException
Get pid for the Windows service with the given name. This method is implemented on Windows only as a helper for PTQL.

Specified by:
getServicePid in interface SigarProxy
Throws:
SigarException

kill

public void kill(long pid,
                 int signum)
          throws SigarException
Send a signal to a process.

Parameters:
pid - The process id.
signum - The signal number.
Throws:
SigarException - on failure.

kill

public void kill(long pid,
                 java.lang.String signame)
          throws SigarException
Send a signal to a process.

Parameters:
pid - The process id.
signame - The signal name.
Throws:
SigarException - on failure.

getSigNum

public static int getSigNum(java.lang.String name)

kill

public void kill(java.lang.String pid,
                 int signum)
          throws SigarException
Send a signal to a process.

Parameters:
pid - The process id or query.
signum - The signal number.
Throws:
SigarException - on failure.

getMem

public Mem getMem()
           throws SigarException
Get system memory info.

Specified by:
getMem in interface SigarProxy
Throws:
SigarException - on failure.

getSwap

public Swap getSwap()
             throws SigarException
Get system swap info.

Specified by:
getSwap in interface SigarProxy
Throws:
SigarException - on failure.

getCpu

public Cpu getCpu()
           throws SigarException
Get system cpu info.

Specified by:
getCpu in interface SigarProxy
Throws:
SigarException - on failure.

getCpuPerc

public CpuPerc getCpuPerc()
                   throws SigarException
Get system CPU info in percentage format. (i.e. fraction of 1)

Specified by:
getCpuPerc in interface SigarProxy
Throws:
SigarException - on failure.

getCpuPercList

public CpuPerc[] getCpuPercList()
                         throws SigarException
Get system per-CPU info in percentage format. (i.e. fraction of 1)

Specified by:
getCpuPercList in interface SigarProxy
Throws:
SigarException - on failure.

getResourceLimit

public ResourceLimit getResourceLimit()
                               throws SigarException
Get system resource limits.

Specified by:
getResourceLimit in interface SigarProxy
Throws:
SigarException - on failure.

getUptime

public Uptime getUptime()
                 throws SigarException
Get system uptime info.

Specified by:
getUptime in interface SigarProxy
Throws:
SigarException - on failure.

getLoadAverage

public double[] getLoadAverage()
                        throws SigarException
Get system load average.

Specified by:
getLoadAverage in interface SigarProxy
Returns:
The system load averages for the past 1, 5, and 15 minutes.
Throws:
SigarException - on failure.

getProcList

public long[] getProcList()
                   throws SigarException
Get system process list.

Specified by:
getProcList in interface SigarProxy
Returns:
Array of process ids.
Throws:
SigarException - on failure.

getProcStat

public ProcStat getProcStat()
                     throws SigarException
Get system process stats.

Specified by:
getProcStat in interface SigarProxy
Throws:
SigarException - on failure.

getProcMem

public ProcMem getProcMem(long pid)
                   throws SigarException
Get process memory info.

Specified by:
getProcMem in interface SigarProxy
Parameters:
pid - The process id.
Throws:
SigarException - on failure.

getProcMem

public ProcMem getProcMem(java.lang.String pid)
                   throws SigarException
Specified by:
getProcMem in interface SigarProxy
Throws:
SigarException

getMultiProcMem

public ProcMem getMultiProcMem(java.lang.String query)
                        throws SigarException
Specified by:
getMultiProcMem in interface SigarProxy
Throws:
SigarException

getProcState

public ProcState getProcState(long pid)
                       throws SigarException
Get process state info.

Specified by:
getProcState in interface SigarProxy
Parameters:
pid - The process id.
Throws:
SigarException - on failure.

getProcState

public ProcState getProcState(java.lang.String pid)
                       throws SigarException
Specified by:
getProcState in interface SigarProxy
Throws:
SigarException

getProcTime

public ProcTime getProcTime(long pid)
                     throws SigarException
Get process time info.

Specified by:
getProcTime in interface SigarProxy
Parameters:
pid - The process id.
Throws:
SigarException - on failure.

getProcTime

public ProcTime getProcTime(java.lang.String pid)
                     throws SigarException
Specified by:
getProcTime in interface SigarProxy
Throws:
SigarException

getProcCpu

public ProcCpu getProcCpu(long pid)
                   throws SigarException
Get process cpu info.

Specified by:
getProcCpu in interface SigarProxy
Parameters:
pid - The process id.
Throws:
SigarException - on failure.

getProcCpu

public ProcCpu getProcCpu(java.lang.String pid)
                   throws SigarException
Specified by:
getProcCpu in interface SigarProxy
Throws:
SigarException

getMultiProcCpu

public MultiProcCpu getMultiProcCpu(java.lang.String query)
                             throws SigarException
Specified by:
getMultiProcCpu in interface SigarProxy
Throws:
SigarException

getProcCred

public ProcCred getProcCred(long pid)
                     throws SigarException
Get process credential info.

Specified by:
getProcCred in interface SigarProxy
Parameters:
pid - The process id.
Throws:
SigarException - on failure.

getProcCred

public ProcCred getProcCred(java.lang.String pid)
                     throws SigarException
Specified by:
getProcCred in interface SigarProxy
Throws:
SigarException

getProcCredName

public ProcCredName getProcCredName(long pid)
                             throws SigarException
Get process credential names.

Specified by:
getProcCredName in interface SigarProxy
Parameters:
pid - The process id.
Throws:
SigarException - on failure.

getProcCredName

public ProcCredName getProcCredName(java.lang.String pid)
                             throws SigarException
Specified by:
getProcCredName in interface SigarProxy
Throws:
SigarException

getProcFd

public ProcFd getProcFd(long pid)
                 throws SigarException
Get process file descriptor info.

Specified by:
getProcFd in interface SigarProxy
Parameters:
pid - The process id.
Throws:
SigarException - on failure.

getProcFd

public ProcFd getProcFd(java.lang.String pid)
                 throws SigarException
Specified by:
getProcFd in interface SigarProxy
Throws:
SigarException

getProcExe

public ProcExe getProcExe(long pid)
                   throws SigarException
Get process current working directory.

Specified by:
getProcExe in interface SigarProxy
Parameters:
pid - The process id.
Throws:
SigarException - on failure.

getProcExe

public ProcExe getProcExe(java.lang.String pid)
                   throws SigarException
Specified by:
getProcExe in interface SigarProxy
Throws:
SigarException

getProcArgs

public java.lang.String[] getProcArgs(long pid)
                               throws SigarException
Get process arguments.

Specified by:
getProcArgs in interface SigarProxy
Parameters:
pid - The process id.
Returns:
Array of argument strings.
Throws:
SigarException - on failure.

getProcArgs

public java.lang.String[] getProcArgs(java.lang.String pid)
                               throws SigarException
Specified by:
getProcArgs in interface SigarProxy
Throws:
SigarException

getProcEnv

public java.util.Map getProcEnv(long pid)
                         throws SigarException
Get process environment.

Specified by:
getProcEnv in interface SigarProxy
Parameters:
pid - The process id.
Returns:
Map of environment strings.
Throws:
SigarException - on failure.

getProcEnv

public java.util.Map getProcEnv(java.lang.String pid)
                         throws SigarException
Specified by:
getProcEnv in interface SigarProxy
Throws:
SigarException

getProcEnv

public java.lang.String getProcEnv(long pid,
                                   java.lang.String key)
                            throws SigarException
Get process environment variable value. This method is intended to avoid the overhead of creating a Map with all variables if only a single variable is needed.

Specified by:
getProcEnv in interface SigarProxy
Parameters:
pid - The process id.
key - Environment variable name.
Returns:
Environment variable value.
Throws:
SigarException - on failure.

getProcEnv

public java.lang.String getProcEnv(java.lang.String pid,
                                   java.lang.String key)
                            throws SigarException
Specified by:
getProcEnv in interface SigarProxy
Throws:
SigarException

getProcModules

public java.util.List getProcModules(long pid)
                              throws SigarException
Specified by:
getProcModules in interface SigarProxy
Throws:
SigarException

getProcModules

public java.util.List getProcModules(java.lang.String pid)
                              throws SigarException
Specified by:
getProcModules in interface SigarProxy
Throws:
SigarException

getProcPort

public long getProcPort(int protocol,
                        long port)
                 throws SigarException
Find the pid of the process which is listening on the given port.

Supported Platforms: Linux, Windows 2003, Windows XP, AIX.

Specified by:
getProcPort in interface SigarProxy
Parameters:
protocol - NetFlags.CONN_TCP or NetFlags.CONN_UDP.
port - The port number.
Returns:
pid of the process.
Throws:
SigarException - on failure.

getProcPort

public long getProcPort(java.lang.String protocol,
                        java.lang.String port)
                 throws SigarException
Specified by:
getProcPort in interface SigarProxy
Parameters:
protocol - "tcp" or "udp".
port - The port number.
Returns:
pid of the process.
Throws:
SigarException - on failure.

getThreadCpu

public ThreadCpu getThreadCpu()
                       throws SigarException
Get the cumulative cpu time for the calling thread.

Throws:
SigarException

getFileSystemList

public FileSystem[] getFileSystemList()
                               throws SigarException
Get list of file systems.

Specified by:
getFileSystemList in interface SigarProxy
Throws:
SigarException - on failure.

getFileSystemUsage

public FileSystemUsage getFileSystemUsage(java.lang.String name)
                                   throws SigarException
Get file system usage.

Specified by:
getFileSystemUsage in interface SigarProxy
Parameters:
name - Name of the directory on which filesystem is mounted.
Throws:
SigarException - on failure.

getDiskUsage

public DiskUsage getDiskUsage(java.lang.String name)
                       throws SigarException
Get disk usage.

Specified by:
getDiskUsage in interface SigarProxy
Parameters:
name - Name of disk
Throws:
SigarException - on failure.

getMountedFileSystemUsage

public FileSystemUsage getMountedFileSystemUsage(java.lang.String name)
                                          throws SigarException,
                                                 NfsUnreachableException
Get file system usage of a mounted directory. This method checks that the given directory is mounted. Unlike getFileSystemUsage() which only requires that the directory exists within a mounted file system. This method will also check that NFS servers are reachable via RPC before attempting to get the file system stats to prevent application hang when an NFS server is down.

Specified by:
getMountedFileSystemUsage in interface SigarProxy
Parameters:
name - Name of the directory on which filesystem is mounted.
Throws:
SigarException - If given directory is not mounted.
NfsUnreachableException - If NFS server is unreachable.
See Also:
getFileSystemUsage(java.lang.String)

getFileSystemMap

public FileSystemMap getFileSystemMap()
                               throws SigarException
Specified by:
getFileSystemMap in interface SigarProxy
Throws:
SigarException

getFileInfo

public FileInfo getFileInfo(java.lang.String name)
                     throws SigarException
Specified by:
getFileInfo in interface SigarProxy
Throws:
SigarException

getLinkInfo

public FileInfo getLinkInfo(java.lang.String name)
                     throws SigarException
Specified by:
getLinkInfo in interface SigarProxy
Throws:
SigarException

getDirStat

public DirStat getDirStat(java.lang.String name)
                   throws SigarException
Specified by:
getDirStat in interface SigarProxy
Throws:
SigarException

getDirUsage

public DirUsage getDirUsage(java.lang.String name)
                     throws SigarException
Specified by:
getDirUsage in interface SigarProxy
Throws:
SigarException

getCpuInfoList

public CpuInfo[] getCpuInfoList()
                         throws SigarException
Get list of cpu infomation.

Specified by:
getCpuInfoList in interface SigarProxy
Throws:
SigarException - on failure.

getCpuList

public Cpu[] getCpuList()
                 throws SigarException
Get list of per-cpu metrics.

Specified by:
getCpuList in interface SigarProxy
Throws:
SigarException - on failure.

getNetRouteList

public NetRoute[] getNetRouteList()
                           throws SigarException
Get list of network routes.

Specified by:
getNetRouteList in interface SigarProxy
Throws:
SigarException - on failure.

getNetConnectionList

public NetConnection[] getNetConnectionList(int flags)
                                     throws SigarException
Get list of network connections.

Specified by:
getNetConnectionList in interface SigarProxy
Throws:
SigarException - on failure.

getNetListenAddress

public java.lang.String getNetListenAddress(long port)
                                     throws SigarException
Get the TCP listen address for the given port. If there is not a listener on the given port, null will be returned.

Specified by:
getNetListenAddress in interface SigarProxy
Throws:
SigarException

getNetListenAddress

public java.lang.String getNetListenAddress(java.lang.String port)
                                     throws SigarException
Specified by:
getNetListenAddress in interface SigarProxy
Throws:
SigarException

getNetServicesName

public java.lang.String getNetServicesName(int protocol,
                                           long port)
Specified by:
getNetServicesName in interface SigarProxy

getNetStat

public NetStat getNetStat()
                   throws SigarException
Specified by:
getNetStat in interface SigarProxy
Throws:
SigarException

getNetStat

public NetStat getNetStat(byte[] address,
                          long port)
                   throws SigarException
Throws:
SigarException

getWhoList

public Who[] getWhoList()
                 throws SigarException
Specified by:
getWhoList in interface SigarProxy
Throws:
SigarException

getTcp

public Tcp getTcp()
           throws SigarException
TCP-MIB stats

Specified by:
getTcp in interface SigarProxy
Throws:
SigarException - on failure.

getNfsClientV2

public NfsClientV2 getNfsClientV2()
                           throws SigarException
Specified by:
getNfsClientV2 in interface SigarProxy
Throws:
SigarException

getNfsServerV2

public NfsServerV2 getNfsServerV2()
                           throws SigarException
Specified by:
getNfsServerV2 in interface SigarProxy
Throws:
SigarException

getNfsClientV3

public NfsClientV3 getNfsClientV3()
                           throws SigarException
Specified by:
getNfsClientV3 in interface SigarProxy
Throws:
SigarException

getNfsServerV3

public NfsServerV3 getNfsServerV3()
                           throws SigarException
Specified by:
getNfsServerV3 in interface SigarProxy
Throws:
SigarException

getNetInfo

public NetInfo getNetInfo()
                   throws SigarException
Get general network info.

Specified by:
getNetInfo in interface SigarProxy
Throws:
SigarException - on failure.

getNetInterfaceConfig

public NetInterfaceConfig getNetInterfaceConfig(java.lang.String name)
                                         throws SigarException
Get network interface configuration info.

Specified by:
getNetInterfaceConfig in interface SigarProxy
Throws:
SigarException - on failure.

getNetInterfaceConfig

public NetInterfaceConfig getNetInterfaceConfig()
                                         throws SigarException
Get default network interface configuration info. Iterates getNetInterfaceList(), returning the first available ethernet interface.

Specified by:
getNetInterfaceConfig in interface SigarProxy
Throws:
SigarException - on failure.

getNetInterfaceStat

public NetInterfaceStat getNetInterfaceStat(java.lang.String name)
                                     throws SigarException
Get network interface stats.

Specified by:
getNetInterfaceStat in interface SigarProxy
Throws:
SigarException - on failure.

getNetInterfaceList

public java.lang.String[] getNetInterfaceList()
                                       throws SigarException
Get the list of configured network interface names.

Specified by:
getNetInterfaceList in interface SigarProxy
Throws:
SigarException - on failure.

getPassword

public static java.lang.String getPassword(java.lang.String prompt)
                                    throws java.io.IOException
Prompt for a password, disabling terminal echo during user input if possible.

Parameters:
prompt - Text printed before disabling echo
Returns:
Text entered by the user.
Throws:
java.io.IOException - If input could not be read.

getFQDN

public java.lang.String getFQDN()
                         throws SigarException
Reliably retrieve the FQDN for a machine

Specified by:
getFQDN in interface SigarProxy
Returns:
The fully qualified domain name of the machine.
Throws:
SigarException - on failure.

enableLogging

public void enableLogging(boolean value)
Enabling logging in the native Sigar code. This method will hook log4j into the Sigar native logging methods. Note that the majority of logging in the native code is only at the DEBUG level.



Copyright ? 2004-2009 Hyperic. All Rights Reserved.