com.jezhumble.javasysmon
Interface Monitor

All Known Implementing Classes:
JavaSysMon

public interface Monitor

This is the interface that needs to be implemented for any platform that JavaSysMon supports. If you write your own implementation, you can test it by injecting it into JavaSysMon.setMonitor(com.jezhumble.javasysmon.Monitor)


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 killProcess(int pid)
          Attempts to kill the process identified by the integer id supplied.
 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.
 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.
 

Method Detail

osName

java.lang.String osName()
Get the operating system name.

Returns:
The operating system name.

numCpus

int numCpus()
Get the number of CPU cores.

Returns:
The number of CPU cores.

cpuFrequencyInHz

long cpuFrequencyInHz()
Get the CPU frequency in Hz

Returns:
the CPU frequency in Hz

uptimeInSeconds

long uptimeInSeconds()
How long the system has been up in seconds. Doesn't generally include time that the system has been hibernating or asleep.

Returns:
The time the system has been up in seconds.

cpuTimes

CpuTimes cpuTimes()
Gets a snapshot which contains the total amount of time the CPU has spent in user mode, kernel mode, and idle. Given two snapshots, you can calculate the CPU usage during that time. There is a convenience method to perform this calculation in CpuTimes.getCpuUsage(com.jezhumble.javasysmon.CpuTimes)

Returns:
An object containing the amount of time the CPU has spent idle, in user mode and in kernel mode, in milliseconds.

physical

MemoryStats physical()
Gets the physical memory installed, and the amount free.

Returns:
An object containing the amount of physical memory installed, and the amount free.

swap

MemoryStats swap()
Gets the amount of swap available to the operating system, and the amount that is free.

Returns:
An object containing the amount of swap available to the system, and the amount free.

currentPid

int currentPid()
Gets the pid of the process that is calling this method (assuming it is running in the same process).

Returns:
The pid of the process calling this method.

processTable

ProcessInfo[] processTable()
Get the current process table. This call returns an array of objects, each of which represents a single process.

Returns:
An array of objects, each of which represents a process.

killProcess

void killProcess(int pid)
Attempts to kill the process identified by the integer id supplied. This will silently fail if you don't have the authority to kill that process. This method sends SIGTERM on the UNIX platform, and kills the process using TerminateProcess on Windows.

Parameters:
pid - The id of the process to kill


Copyright © 2009 ThoughtWorks. All Rights Reserved.