Class FileDescriptorStatusProvider

java.lang.Object
com.github.jpmsilva.jsystemd.DelayableHealthProvider
com.github.jpmsilva.jsystemd.FileDescriptorStatusProvider
All Implemented Interfaces:
HealthProvider, StatusProvider

public class FileDescriptorStatusProvider extends DelayableHealthProvider implements StatusProvider
Provides information regarding the file descriptors of the process: as a StatusProvider, the open file descriptors out of the most the process can open, such as File descriptors: 812/65536, and as a HealthProvider, for the systemd watchdog, reporting the application as unhealthy when they are about to run out, if enabled.

Every open file, socket and pipe takes a file descriptor, and once they run out, the application can no longer accept connections or open files. As a leak of file descriptors never resolves by itself, restarting the application is usually the only way out. The limit is the one systemd sets with LimitNOFILE in the service unit.

The health is enabled on its own, as it lets systemd restart the application: while disabled, the application is always healthy. When enabled, it is unhealthy while the open file descriptors are at or above the given share of the limit, reporting both in the health details, under openFileDescriptors and maxFileDescriptors. As a burst of connections can also open many file descriptors for a short while, the unhealthy state can be delayed, with DelayableHealthProvider.setUnhealthyDelay(java.time.Duration).

The file descriptors are only known on Unix-like systems, and nothing is reported otherwise.

Author:
Joao Silva
  • Constructor Details

    • FileDescriptorStatusProvider

      public FileDescriptorStatusProvider(boolean health, double threshold)
      Create a new FileDescriptorStatusProvider.
      Parameters:
      health - true to report the application as unhealthy when the file descriptors are about to run out
      threshold - the share of the limit of file descriptors from which the application is unhealthy, such as 0.9 for 90%
      Throws:
      IllegalArgumentException - if the threshold is not greater than 0 and at most 1
  • Method Details

    • status

      public String status()
      Description copied from interface: StatusProvider
      Exposes status information to send to systemd.
      Specified by:
      status in interface StatusProvider
      Returns:
      the string message to add to the service status
    • evaluateHealth

      protected HealthProvider.Health evaluateHealth()
      Provides the health of the application, without the delay: unhealthy while the open file descriptors are at or above the threshold, if enabled.
      Specified by:
      evaluateHealth in class DelayableHealthProvider
      Returns:
      the health of the application