Package io.antmedia

Class SystemUtils

java.lang.Object
io.antmedia.SystemUtils

public class SystemUtils extends Object
This utility is designed for accessing server's system information more easier.
Author:
The Red5 Project (red5@osflash.org), DZS|All-In-One (coolest2guy@gmail.com)
  • Field Details

    • HEAPDUMP_HPROF

      public static final String HEAPDUMP_HPROF
      See Also:
    • MAX_CONTAINER_MEMORY_LIMIT_BYTES

      public static final long MAX_CONTAINER_MEMORY_LIMIT_BYTES
      See Also:
    • MAX_MEMORY_CGROUP_V2

      public static final String MAX_MEMORY_CGROUP_V2
      See Also:
    • osName

      public static final String osName
      Obtain Operating System's name.
    • osArch

      public static final String osArch
      Obtain Operating System's Architecture.
    • jvmVersion

      public static final String jvmVersion
      Obtain Java JRE version.
    • osProcessorX

      public static final int osProcessorX
      Obtain Operating System's processor.
    • HOTSPOT_BEAN_NAME

      private static final String HOTSPOT_BEAN_NAME
      See Also:
    • hotspotMBean

      private static HotSpotDiagnosticMXBean hotspotMBean
    • logger

      protected static final org.slf4j.Logger logger
    • MAC_OS_X

      public static final int MAC_OS_X
      See Also:
    • LINUX

      public static final int LINUX
      See Also:
    • WINDOWS

      public static final int WINDOWS
      See Also:
    • OS_TYPE

      public static final int OS_TYPE
    • containerized

      public static Boolean containerized
  • Constructor Details

    • SystemUtils

      public SystemUtils()
  • Method Details

    • jvmMaxMemory

      public static long jvmMaxMemory()
      Obtain JVM's Maximum Memory.
      Parameters:
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • jvmTotalMemory

      public static long jvmTotalMemory()
      Obtain JVM's Total Memory.
      Returns:
      bytes size
    • jvmFreeMemory

      public static long jvmFreeMemory()
      Obtain JVM's Free Memory.
      Parameters:
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • jvmInUseMemory

      public static long jvmInUseMemory()
      Obtain JVM's In Use Memory.
      Parameters:
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • osCommittedVirtualMemory

      public static long osCommittedVirtualMemory()
      Obtain Virtual Memory from Operating System's RAM.
      Parameters:
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • osTotalPhysicalMemory

      public static long osTotalPhysicalMemory()
      Obtain Total Physical Memory from Operating System's RAM.
      Returns:
      bytes size
    • getTotalPhysicalMemorySize

      public static long getTotalPhysicalMemorySize()
    • osFreePhysicalMemory

      public static long osFreePhysicalMemory()
      Obtain Free Physical Memory from Operating System's RAM.
      Parameters:
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • osAvailableMemory

      public static long osAvailableMemory()
      Returns:
      the amount of available physical memory
    • osInUsePhysicalMemory

      public static long osInUsePhysicalMemory()
      Obtain In Use Physical Memory from Operating System's RAM.
      Parameters:
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • osTotalSwapSpace

      public static long osTotalSwapSpace()
      Obtain Total Swap Space from Operating System's RAM.
      Parameters:
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • osFreeSwapSpace

      public static long osFreeSwapSpace()
      Obtain Free Swap Space from Operating System's RAM.
      Parameters:
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • osInUseSwapSpace

      public static long osInUseSwapSpace()
      Obtain In Use Swap Space from Operating System's RAM.
      Parameters:
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • osHDUsableSpace

      public static long osHDUsableSpace(String path)
      Obtain Harddrive's Usable Space.
      Parameters:
      path - actual path
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • osHDTotalSpace

      public static long osHDTotalSpace(String path)
      Obtain Harddrive's Overall Space.
      Parameters:
      path - actual path
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • osHDFreeSpace

      public static long osHDFreeSpace(String path)
      Obtain Harddrive's Available Space.
      Parameters:
      path - actual path
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • osHDInUseSpace

      public static long osHDInUseSpace(String path)
      Obtain Harddrive's In Use Space.
      Parameters:
      path - actual path
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • convertByteSize

      public static String convertByteSize(Long bytes, String size, boolean txtByte)
      Requirement support for... ------------------------------- jvmMaxMemory() jvmTotalMemory() jvmFreeMemory() jvmInUseMemory() osCommittedVirtualMemory() osFreePhysicalMemory() osTotalPhysicalMemory() osInUsePhysicalMemory() osFreeSwapSpace() osTotalSwapSpace() osInUseSwapSpace() osHDUsableSpace() osHDTotalSpace() osHDFreeSpace() osHDInUseSpace() -------------------------------
    • convertByteSizeToDisk

      public static String convertByteSizeToDisk(Long bytes, String size, boolean txtByte)
    • convertByteSize

      public static long convertByteSize(long bytes, String size)
    • convertByteSize

      public static String convertByteSize(Long bytes, String size, Boolean txtByte, boolean isDisk)
      Permit to convert bytes to ALMOST any upper bytes with/without extension (Currently at existing TeraByte but one step ahead, PetaByte)
      Parameters:
      bytes - length of bytes
      size - null, AUTO, B, KB, MB, GB, TB, or PB (PetaByte does not exist yet) Is not case sensitive.
      txtByte - true if include byte extension, false exclude extension
      Returns:
      bytes size
    • error

      protected static void error(Exception e)
      Error Exception issued switch.
      Parameters:
      e - Throws exception errors
    • error

      protected static void error(int error, String info)
      Custom Error issued switch.
      Parameters:
      error - Error #
      info - Extra info from error executed
    • getSystemCpuLoad

      public static Integer getSystemCpuLoad()
      Returns the "% recent cpu usage" for the whole system.
      Returns:
    • getSystemLoadAverageLastMinute

      public static double getSystemLoadAverageLastMinute()
    • getProcessCpuLoad

      public static Integer getProcessCpuLoad()
      Returns the "% recent cpu usage" for the Java Virtual Machine process. the method returns a negative value.
      Returns:
    • getProcessCpuTime

      public static Long getProcessCpuTime()
      Returns the CPU time used by the process on which the Java virtual machine is running in microseconds.
      Returns:
    • getHeapDump

      public static void getHeapDump(String filepath)
    • getHotspotMBean

      private static HotSpotDiagnosticMXBean getHotspotMBean()
    • availablePhysicalBytes

      public static long availablePhysicalBytes()
    • isContainerized

      public static boolean isContainerized()
    • getMemoryLimitFromCgroup

      public static Long getMemoryLimitFromCgroup() throws IOException
      Throws:
      IOException
    • getMemAvailableFromCgroup

      public static Long getMemAvailableFromCgroup() throws IOException
      Throws:
      IOException
    • readCgroupFile

      public static String readCgroupFile(String filePath) throws IOException
      Throws:
      IOException