|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jezhumble.javasysmon.JavaSysMon
public class JavaSysMon
This class provides the main API for JavaSysMon. You must instantiate this class in order to use it, but it stores no state, so there is zero overhead to instantiating it as many times as you like, and hence no need to cache it.
When instantiated for the first time, JavaSysMon will discover which operating system it is running on and attempt to load the appropriate OS-specific extensions. If JavaSysMon doesn't support the OS you're running on, all calls to the API will return null or zero values. Probably the best one to test is osName.
You can run JavaSysMon directly as a jar file, using the command "java -jar javasysmon.jar", in which case it will display output similar to the UNIX "top" command. You can optionally specify a process id as an argument, in which case JavaSysMon will attempt to kill the process.
Constructor Summary | |
---|---|
JavaSysMon()
Creates a new JavaSysMon object through which to access the JavaSysMon API. |
Method Summary | |
---|---|
long |
cpuFrequencyInHz()
Get the CPU frequency in Hz |
CpuTimes |
cpuTimes()
Gets a snapshot which contains the total amount of time the CPU has spent in user mode, kernel mode, and idle. |
int |
currentPid()
Gets the pid of the process that is calling this method (assuming it is running in the same process). |
void |
infanticide()
Attempts to kill all the descendants of the currently running process. |
void |
killProcess(int pid)
Attempts to kill the process identified by the integer id supplied. |
void |
killProcessTree(int pid,
boolean descendantsOnly)
Kills the process tree starting at the process identified by pid. |
static void |
main(java.lang.String[] params)
This is the main entry point when running the jar directly. |
int |
numCpus()
Get the number of CPU cores. |
java.lang.String |
osName()
Get the operating system name. |
MemoryStats |
physical()
Gets the physical memory installed, and the amount free. |
ProcessInfo[] |
processTable()
Get the current process table. |
OsProcess |
processTree()
Gets the current process table in the form of a process tree. |
static void |
setMonitor(Monitor myMonitor)
Allows you to register your own implementation of Monitor . |
MemoryStats |
swap()
Gets the amount of swap available to the operating system, and the amount that is free. |
long |
uptimeInSeconds()
How long the system has been up in seconds. |
void |
visitProcessTree(int pid,
ProcessVisitor processVisitor)
Allows you to visit the process tree, starting at the node identified by pid. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JavaSysMon()
Method Detail |
---|
public static void setMonitor(Monitor myMonitor)
Monitor
.
myMonitor
- An implementation of the Monitor interface that all API calls will be delegated topublic static void main(java.lang.String[] params) throws java.lang.Exception
java.lang.Exception
public java.lang.String osName()
osName
in interface Monitor
public int numCpus()
numCpus
in interface Monitor
public long cpuFrequencyInHz()
cpuFrequencyInHz
in interface Monitor
public long uptimeInSeconds()
uptimeInSeconds
in interface Monitor
public int currentPid()
currentPid
in interface Monitor
public CpuTimes cpuTimes()
CpuTimes.getCpuUsage(com.jezhumble.javasysmon.CpuTimes)
cpuTimes
in interface Monitor
public MemoryStats physical()
physical
in interface Monitor
public MemoryStats swap()
swap
in interface Monitor
public ProcessInfo[] processTable()
processTree()
instead.
processTable
in interface Monitor
public OsProcess processTree()
public void killProcess(int pid)
killProcess
in interface Monitor
pid
- The id of the process to killpublic void visitProcessTree(int pid, ProcessVisitor processVisitor)
pid
- The identifier of the node to start visitingprocessVisitor
- The visitorpublic void killProcessTree(int pid, boolean descendantsOnly)
This method uses visitProcessTree(int, com.jezhumble.javasysmon.ProcessVisitor)
.
pid
- The identifier of the process at which to start killing the tree.descendantsOnly
- Whether or not to kill the process you start at,
or only its descendantspublic void infanticide()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |