Package org.apache.flink.runtime.util
Class EnvironmentInformation
- java.lang.Object
-
- org.apache.flink.runtime.util.EnvironmentInformation
-
public class EnvironmentInformation extends Object
Utility class that gives access to the execution environment of the JVM, like the executing user, startup options, or the JVM version.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EnvironmentInformation.RevisionInformation
Revision information encapsulates information about the source code revision of the Flink code.
-
Field Summary
Fields Modifier and Type Field Description static String
UNKNOWN
static String
UNKNOWN_COMMIT_ID
static String
UNKNOWN_COMMIT_ID_ABBREV
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Instant
getBuildTime()
static String
getBuildTimeString()
static String
getGitCommitId()
static String
getGitCommitIdAbbrev()
static Instant
getGitCommitTime()
static String
getGitCommitTimeString()
static String
getHadoopUser()
Gets the name of the user that is running the JVM.static String
getHadoopVersionString()
static String
getJvmStartupOptions()
Gets the system parameters and environment parameters that were passed to the JVM on startup.static String[]
getJvmStartupOptionsArray()
Gets the system parameters and environment parameters that were passed to the JVM on startup.static String
getJvmVersion()
Gets the version of the JVM in the form "VM_Name - Vendor - Spec/Version".static long
getMaxJvmHeapMemory()
The maximum JVM heap size, in bytes.static long
getOpenFileHandlesLimit()
Tries to retrieve the maximum number of open file handles.static EnvironmentInformation.RevisionInformation
getRevisionInformation()
Returns the code revision (commit and commit date) of Flink, as generated by the Maven builds.static String
getScalaVersion()
Returns the version of the used Scala compiler as String.static long
getSizeOfFreeHeapMemory()
Gets an estimate of the size of the free heap memory.static long
getSizeOfFreeHeapMemoryWithDefrag()
Gets an estimate of the size of the free heap memory.static String
getTemporaryFileDirectory()
Gets the directory for temporary files, as returned by the JVM system property "java.io.tmpdir".static String
getVersion()
Returns the version of the code as String.static void
logEnvironmentInfo(org.slf4j.Logger log, String componentName, String[] commandLineArgs)
Logs information about the environment, like code revision, current user, Java version, and JVM parameters.
-
-
-
Field Detail
-
UNKNOWN_COMMIT_ID
@VisibleForTesting public static final String UNKNOWN_COMMIT_ID
- See Also:
- Constant Field Values
-
UNKNOWN_COMMIT_ID_ABBREV
@VisibleForTesting public static final String UNKNOWN_COMMIT_ID_ABBREV
- See Also:
- Constant Field Values
-
UNKNOWN
public static final String UNKNOWN
- See Also:
- Constant Field Values
-
-
Method Detail
-
getVersion
public static String getVersion()
Returns the version of the code as String.- Returns:
- The project version string.
-
getScalaVersion
public static String getScalaVersion()
Returns the version of the used Scala compiler as String.- Returns:
- The scala version string.
-
getBuildTime
public static Instant getBuildTime()
- Returns:
- The Instant this version of the software was built.
-
getBuildTimeString
public static String getBuildTimeString()
- Returns:
- The Instant this version of the software was built as a String using the Europe/Berlin timezone.
-
getGitCommitId
public static String getGitCommitId()
- Returns:
- The last known commit id of this version of the software.
-
getGitCommitIdAbbrev
public static String getGitCommitIdAbbrev()
- Returns:
- The last known abbreviated commit id of this version of the software.
-
getGitCommitTime
public static Instant getGitCommitTime()
- Returns:
- The Instant of the last commit of this code.
-
getGitCommitTimeString
public static String getGitCommitTimeString()
- Returns:
- The Instant of the last commit of this code as a String using the Europe/Berlin timezone.
-
getRevisionInformation
public static EnvironmentInformation.RevisionInformation getRevisionInformation()
Returns the code revision (commit and commit date) of Flink, as generated by the Maven builds.- Returns:
- The code revision.
-
getHadoopUser
public static String getHadoopUser()
Gets the name of the user that is running the JVM.- Returns:
- The name of the user that is running the JVM.
-
getMaxJvmHeapMemory
public static long getMaxJvmHeapMemory()
The maximum JVM heap size, in bytes.This method uses the -Xmx value of the JVM, if set. If not set, it returns (as a heuristic) 1/4th of the physical memory size.
- Returns:
- The maximum JVM heap size, in bytes.
-
getSizeOfFreeHeapMemoryWithDefrag
public static long getSizeOfFreeHeapMemoryWithDefrag()
Gets an estimate of the size of the free heap memory.NOTE: This method is heavy-weight. It triggers a garbage collection to reduce fragmentation and get a better estimate at the size of free memory. It is typically more accurate than the plain version
getSizeOfFreeHeapMemory()
.- Returns:
- An estimate of the size of the free heap memory, in bytes.
-
getSizeOfFreeHeapMemory
public static long getSizeOfFreeHeapMemory()
Gets an estimate of the size of the free heap memory. The estimate may vary, depending on the current level of memory fragmentation and the number of dead objects. For a better (but more heavy-weight) estimate, usegetSizeOfFreeHeapMemoryWithDefrag()
.- Returns:
- An estimate of the size of the free heap memory, in bytes.
-
getJvmVersion
public static String getJvmVersion()
Gets the version of the JVM in the form "VM_Name - Vendor - Spec/Version".- Returns:
- The JVM version.
-
getJvmStartupOptions
public static String getJvmStartupOptions()
Gets the system parameters and environment parameters that were passed to the JVM on startup.- Returns:
- The options passed to the JVM on startup.
-
getJvmStartupOptionsArray
public static String[] getJvmStartupOptionsArray()
Gets the system parameters and environment parameters that were passed to the JVM on startup.- Returns:
- The options passed to the JVM on startup.
-
getTemporaryFileDirectory
public static String getTemporaryFileDirectory()
Gets the directory for temporary files, as returned by the JVM system property "java.io.tmpdir".- Returns:
- The directory for temporary files.
-
getOpenFileHandlesLimit
public static long getOpenFileHandlesLimit()
Tries to retrieve the maximum number of open file handles. This method will only work on UNIX-based operating systems with Sun/Oracle Java versions.If the number of max open file handles cannot be determined, this method returns
-1
.- Returns:
- The limit of open file handles, or
-1
, if the limit could not be determined.
-
logEnvironmentInfo
public static void logEnvironmentInfo(org.slf4j.Logger log, String componentName, String[] commandLineArgs)
Logs information about the environment, like code revision, current user, Java version, and JVM parameters.- Parameters:
log
- The logger to log the information to.componentName
- The component name to mention in the log.commandLineArgs
- The arguments accompanying the starting the component.
-
getHadoopVersionString
public static String getHadoopVersionString()
-
-