Package com.bw.jtools.log
Class OS
- java.lang.Object
-
- com.bw.jtools.log.OS
-
public final class OS extends java.lang.ObjectUtility class to gather statistics about the running application.
Initially this class was created to collect information about a long-running server application that should be reported via a status-service.
Most features are only supported by unix operating systems. But for some values a fallback can be used, e.g. we can use the system-time instead of real thread-time.
Needs to be extends for a more general use.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOS.InfoUtility class to collect all values at once.
A bit too specific for general usage, but good for demonstration.
-
Constructor Summary
Constructors Constructor Description OS()
-
Method Summary
Modifier and Type Method Description static longgetMaxOpenFileHandles()Gets the maximal number of open files of this process - if possible.static longgetOpenFileHandles()Gets the number of open files of this process - if possible.
Possible means running inside some "unix".static java.lang.StringgetOSName()static doublegetSystemLoadAverage()Gets the current CPU Load average - if possible.
Is this is not possible, -1 is returned.
The value depends on implementation in the OS.static longgetThreadExecutionTimeNS()Get execution time of current thread, if possible.
If this is not possible or enabled, system-wide time will be used.static voidinit()Initialize this tool class.static booleanisThreadTimeMeasurementUsed()Returns true if getThreadExecutionTimeNS is based on real thread-time.
-
-
-
Method Detail
-
getOpenFileHandles
public static long getOpenFileHandles()
Gets the number of open files of this process - if possible.
Possible means running inside some "unix".- Returns:
- the amount of open file handles or -1 if value is not available.
-
getMaxOpenFileHandles
public static long getMaxOpenFileHandles()
Gets the maximal number of open files of this process - if possible.
Possible means running, that we are running inside some "unix".- Returns:
- The maximal amount of open file handles or -1 if value is not available.
-
getSystemLoadAverage
public static double getSystemLoadAverage()
Gets the current CPU Load average - if possible.
Is this is not possible, -1 is returned.
The value depends on implementation in the OS.- Returns:
- The average system load.
-
getOSName
public static java.lang.String getOSName()
-
getThreadExecutionTimeNS
public static long getThreadExecutionTimeNS()
Get execution time of current thread, if possible.
If this is not possible or enabled, system-wide time will be used.- Returns:
- the elapsed time in nanoseconds.
-
isThreadTimeMeasurementUsed
public static boolean isThreadTimeMeasurementUsed()
Returns true if getThreadExecutionTimeNS is based on real thread-time.- Returns:
- True if thread-time-measurement is used.
-
init
public static void init()
Initialize this tool class. Should be called once before usage, because otherwise it will not work ;)
-
-