Class SystemService
java.lang.Object
de.bytestore.hostinger.internal.service.SystemService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionList<oshi.hardware.HWDiskStore>Retrieves a list of all disk drives available in the system.List<oshi.software.os.OSFileStore>Retrieves a list of all available file systems on the operating system.List<oshi.software.os.OSFileStore>getAllFileSystems(boolean locallyIO) List<oshi.software.os.OSFileStore>Retrieves a list of all file systems present on the operating system.getCachedValue(StatsType typeIO) Retrieves the cached value for the given key.getCachedValue(String keyIO) Retrieves the cached value for the given key.getCachedValue(String keyIO, boolean renewIO) Retrieves a cached value associated with the specified key.getCachedValue(String keyIO, Object defaultIO) Retrieves the cached value for the given key.getCachedValue(String keyIO, OffsetDateTime offsetDateTime) Retrieves a cached value associated with the specified key.getCachedValueHourOffset(String keyIO, Integer hourOffset) Retrieves a cached value based on a provided key and hour offset.getCachedValueList(StatsType typeIO) Retrieves a cached value list for the specified StatsType.getCachedValueListNotRenew(StatsType typeIO) Retrieves a cached list of values associated with the specified StatsType without renewing or updating the cache.getCachedValueMinuteOffset(String keyIO, Integer minutesOffset) Retrieves a cached value associated with the specified key and offset by a certain number of minutes.getCachedValueSecondOffset(String keyIO, Integer secondsOffset) Retrieves a cached value with a specified offset in seconds.doubleRetrieves the CPU temperature of the system.doubleCalculates the current CPU usage.doubleCalculates the CPU usage percentage in the system.doubleCalculates the disk usage in the system.Returns the first day of the current month as a LocalDate object.longReturns the maximum size of the heap in bytes.doubleReturns the current heap usage as a percentage.doubleCalculates the current heap usage percentage.getHWID()Retrieves the hardware identifier (HWID) of the system.Retrieves the new Hardware ID (HWID) for the current machine.List<oshi.hardware.NetworkIF>Retrieves a list of network interfaces.Returns the last day of the current month as a LocalDate object.doubleRetrieves the total memory available, rounded to two decimal places.doubleCalculates the memory usage in the system.doubleCalculates the memory usage percentage of the system.longRetrieves the total network receive of the system.longRetrieves the total network send of the system.Retrieves the name of the operating system family from the system information.longCalculates the total system disk capacity.LinkedList<com.google.gson.JsonObject>getUpdates(String branchIO) Retrieves updates for the specified branch IO.getUpdatesRaw(String branchIO) Retrieves the raw updates for the specified branch IO.Retrieves the version of the software from the build properties.humanReadableByteCountBin(long bytesA) Converts a given number of bytes into a human-readable string using binary (base-2) units.booleanDetermines if the current operating system is Windows.voidload()Initializes the system cache listeners, network interface logging, default network interface, and mappings for various system and hardware metrics.voidreload()Reloads all application modules.voidsetCachedValue(String keyIO, Object valueIO) Sets the cached value for the given key.booleanstartUpdate(String branchIO, String urlIO, DownloadCallback callbackIO, boolean forceIO) Starts the update process.
-
Constructor Details
-
SystemService
public SystemService()
-
-
Method Details
-
getCPUUsage
public double getCPUUsage()Calculates the current CPU usage.- Returns:
- The CPU usage as a percentage, represented as a long value.
-
getCPUTemperature
public double getCPUTemperature()Retrieves the CPU temperature of the system.- Returns:
- The CPU temperature in degrees Celsius, represented as a double value.
-
getInterfaces
Retrieves a list of network interfaces.- Returns:
- A List of NetworkIF objects representing the network interfaces on the system.
-
getDefaultInterface
-
getNetworkSend
public long getNetworkSend()Retrieves the total network send of the system.- Returns:
- The total network send in bytes, represented as a String value.
-
getNetworkReceive
public long getNetworkReceive()Retrieves the total network receive of the system.- Returns:
- The total network receive in bytes, represented as a double value.
-
getMemoryTotal
public double getMemoryTotal()Retrieves the total memory available, rounded to two decimal places.- Returns:
- the total memory as a double value, rounded to two decimal places.
-
getMemoryUsage
public double getMemoryUsage()Calculates the memory usage in the system.- Returns:
- The memory usage in the system, represented as a long value.
-
getTotalDiskCapacity
public long getTotalDiskCapacity()Calculates the total system disk capacity.- Returns:
- The total system disk capacity, represented as a long value.
-
getDiskUsage
public double getDiskUsage()Calculates the disk usage in the system.- Returns:
- The disk usage in the system, represented as a long value.
-
getCPUUsagePercentage
public double getCPUUsagePercentage()Calculates the CPU usage percentage in the system.- Returns:
- The CPU usage percentage in the system, represented as a double value.
-
getMemoryUsagePercentage
public double getMemoryUsagePercentage()Calculates the memory usage percentage of the system.- Returns:
- The memory usage percentage as a double value.
-
getHeapUsage
public double getHeapUsage()Returns the current heap usage as a percentage.- Returns:
- the heap usage as a percentage
-
getHeapMax
public long getHeapMax()Returns the maximum size of the heap in bytes.- Returns:
- the maximum size of the heap
-
load
public void load()Initializes the system cache listeners, network interface logging, default network interface, and mappings for various system and hardware metrics. This method sets up the core configurations to monitor system performance and fetch relevant data. The method performs the following operations: 1. Logs initialization of default system cache listener. 2. Configures URLs for update checks using the space service. 3. Adjusts the logger to log at the error level. 4. Iterates through and logs detected network interfaces, including their name, speed, and MAC address. 5. Retrieves and stores the default network interface for later use. 6. Registers system metrics and performance calculations into the `listeners` map for: - Updates - Support pin - Disk usage and disk percentage - CPU usage, temperature, and percentage - System memory usage, percentage, and total - Java heap usage and percentage - Network send and receive metrics -
getHeapUsagePercentage
public double getHeapUsagePercentage()Calculates the current heap usage percentage.- Returns:
- The heap usage percentage as a double value.
-
reload
public void reload()Reloads all application modules. This method invokes the appropriate service to perform the reinitialization or update of modules as required. -
getCachedValue
Retrieves the cached value for the given key. If the value is not found in the cache, it is fetched from the data source and added to the cache.- Parameters:
typeIO- The key for the cached value.- Returns:
- The cached value associated with the key.
-
getCachedValueListNotRenew
Retrieves a cached list of values associated with the specified StatsType without renewing or updating the cache.- Parameters:
typeIO- the StatsType whose associated cached list of values is to be retrieved- Returns:
- a LinkedList of cached values associated with the provided StatsType
-
getCachedValueList
Retrieves a cached value list for the specified StatsType.- Parameters:
typeIO- the StatsType object whose cached value list is to be retrieved- Returns:
- a LinkedList of cached values corresponding to the given StatsType
-
getCachedValue
Retrieves the cached value for the given key. If the value is not found in the cache, returns the specified default value.- Parameters:
keyIO- The key for the cached value.defaultIO- The default value to return if the key is not found in the cache.- Returns:
- The cached value associated with the key, or the default value if the key is not found.
-
getCachedValue
Retrieves the cached value for the given key. If the value is not found in the cache, it is fetched from the data source and added to the cache.- Parameters:
keyIO- The key for the cached value.- Returns:
- The cached value associated with the key.
-
getCachedValueHourOffset
Retrieves a cached value based on a provided key and hour offset.- Parameters:
keyIO- the key for retrieving the cached valuehourOffset- the number of hours to offset from the current time- Returns:
- the cached value associated with the specified key and hour offset
-
getCachedValueMinuteOffset
Retrieves a cached value associated with the specified key and offset by a certain number of minutes.- Parameters:
keyIO- the key for which the cached value is soughtminutesOffset- the number of minutes to offset from the current time for retrieving the cached value- Returns:
- the cached value for the specified key and minute offset, or null if no such cached value exists
-
getCachedValueSecondOffset
Retrieves a cached value with a specified offset in seconds.- Parameters:
keyIO- the key for retrieving the cached valuesecondsOffset- the number of seconds to offset from the current time- Returns:
- the cached value associated with the provided key and time offset
-
getCachedValue
Retrieves a cached value associated with the specified key. If renewIO is true, the cache is refreshed with the current date and time before returning the value.- Parameters:
keyIO- the key associated with the cached value to retrieverenewIO- if true, refreshes the cache entry with the current date and time- Returns:
- the cached value associated with the given key
-
getCachedValue
Retrieves a cached value associated with the specified key. If the value is not present in the cache, it calculates the value, adds it to the cache, and returns it. It also checks if the cached value should be expired based on the provided offset date time.- Parameters:
keyIO- the key for which the cached value is requiredoffsetDateTime- the date and time used to determine if the cached value is expired- Returns:
- the cached value associated with the specified key
-
humanReadableByteCountBin
Converts a given number of bytes into a human-readable string using binary (base-2) units.- Parameters:
bytesA- The number of bytes to be converted.- Returns:
- A human-readable string representation of the byte count using binary (base-2) units such as KiB, MiB, GiB, etc.
-
isWindows
public boolean isWindows()Determines if the current operating system is Windows.- Returns:
- true if the operating system is Windows, false otherwise.
-
getOperatingSystem
Retrieves the name of the operating system family from the system information.- Returns:
- A string representing the operating system family.
-
getUpdates
Retrieves updates for the specified branch IO.- Parameters:
branchIO- The branch IO for which updates are retrieved.- Returns:
- An ArrayList of JsonObject containing the updates.
- Throws:
RuntimeException- if there is an IOException while retrieving updates.
-
getUpdatesRaw
Retrieves the raw updates for the specified branch IO.- Parameters:
branchIO- The branch IO for which updates are retrieved.- Returns:
- The raw updates response as an HttpResponse object.
- Throws:
IOException- If there is an error making the HTTP request.InterruptedException- If the request is interrupted.
-
startUpdate
public boolean startUpdate(String branchIO, String urlIO, DownloadCallback callbackIO, boolean forceIO) Starts the update process.- Parameters:
branchIO- The branch IO for which updates are retrieved.urlIO- The URL for the update.forceIO- A flag indicating whether to force the update.
-
getVersion
Retrieves the version of the software from the build properties.- Returns:
- The version of the software as a String.
-
getHWID
Retrieves the hardware identifier (HWID) of the system.- Returns:
- The HWID of the system as a SHA-256 hashed string.
- Throws:
SocketException- If an error occurs while retrieving the network interface information.
-
getHWIDNew
Retrieves the new Hardware ID (HWID) for the current machine.- Returns:
- A string representing the machine's Hardware ID (HWID).
- Throws:
SocketException- If there is an error accessing network interfaces.UnknownHostException- If the local host name could not be resolved into an address.NoSuchAlgorithmException- If the algorithm needed for generating the Hardware ID is not available.
-
setCachedValue
Sets the cached value for the given key. If the key is found in the cache, updates the value and the last updated timestamp.- Parameters:
keyIO- The key for the cached value.valueIO- The new value to be cached.
-
getFirstDayMonth
Returns the first day of the current month as a LocalDate object.- Returns:
- The LocalDate representing the first day of the current month.
-
getLastDayMonth
Returns the last day of the current month as a LocalDate object.- Returns:
- The LocalDate representing the last day of the current month.
-
getAllDrives
Retrieves a list of all disk drives available in the system.- Returns:
- a list of HWDiskStore objects representing the system's disk drives.
-
getAllFileSystemsLocally
Retrieves a list of all file systems present on the operating system.- Returns:
- a list of
OSFileStoreobjects representing the file systems available on the operating system.
-
getAllFileSystems
Retrieves a list of all available file systems on the operating system.- Returns:
- a List of OSFileStore objects representing the file systems.
-
getAllFileSystems
-