Back to Nightingale

systemd Plugin

integrations/Systemd/markdown/README.en_US.md

9.1.14.4 KB
Original Source

systemd Plugin

The Systemd plugin monitors the status and performance metrics of systemd services on Linux systems. It communicates with systemd over the D-Bus interface and collects key monitoring data such as service running states, start times, task counts, and restart counts.

System Requirements

  • Operating system: Linux
  • systemd version: 212 or later recommended (some features require newer versions)
  • Permissions: access to the systemd D-Bus interface is required

Configuration

toml
# Whether to enable the systemd plugin
enable = true

# Regular expression for units to include, defaults to ".+" (all units)
unit_include = '''.+'''

# Regular expression for units to exclude, by default excludes automount, device, mount, scope, and slice types
unit_exclude = '''.+\.(automount|device|mount|scope|slice)'''

# Whether to collect start time metrics for service units (unit: seconds)
enable_start_time_metrics = true

# Whether to collect task metrics for service units
enable_task_metrics = true

# Whether to collect restart count metrics for service units
enable_restarts_metrics = true

# Whether to use a private systemd connection
systemd_private = false

Configuration Parameters

ParameterTypeDefaultDescription
enableboolfalseWhether to enable the plugin
unit_includestring.+Regular expression for unit names to include
unit_excludestring.+\.(automount|device|mount|scope|slice)Regular expression for unit names to exclude
enable_start_time_metricsbooltrueWhether to collect service start time metrics
enable_task_metricsbooltrueWhether to collect task-related metrics
enable_restarts_metricsbooltrueWhether to collect restart count metrics
systemd_privateboolfalseWhether to use a private systemd connection

Metrics

System-level Metrics

NameTypeLabelsDescription
systemd_versiongaugeversionsystemd version information
systemd_unitsgaugestateTotal number of units in each state
systemd_system_runninggauge-Whether the system is in the running state (1 = running, 0 = not running)

Unit State Metrics

NameTypeLabelsDescription
systemd_unit_stategaugename, state, typeUnit state information
systemd_unit_start_time_secondsgaugenameUnit start timestamp (Unix timestamp)

Service Metrics

NameTypeLabelsDescription
systemd_service_restart_totalcounternameTotal number of service restarts
systemd_unit_tasks_currentgaugenameCurrent number of tasks
systemd_unit_tasks_maxgaugenameMaximum task limit

Socket Metrics

NameTypeLabelsDescription
systemd_socket_accepted_connections_totalcounternameTotal number of connections accepted by the socket
systemd_socket_current_connectionsgaugenameCurrent number of socket connections
systemd_socket_refused_connections_totalcounternameTotal number of connections refused by the socket

Timer Metrics

NameTypeLabelsDescription
systemd_timer_last_trigger_secondsgaugenameTimestamp of the timer's last trigger

Best Practices

  1. Configure filtering rules sensibly. Set appropriate include and exclude rules based on your monitoring needs to avoid collecting too much useless data:
toml
# Example: only monitor application services, exclude internal system services
unit_include = '''^(app-|web-|db-).*\.service$'''
unit_exclude = '''^(systemd|dbus|udev).*'''
  1. Enable features on demand. Selectively enable feature modules according to actual needs:
toml
# For most application monitoring scenarios
enable_start_time_metrics = true
enable_task_metrics = false      # can be disabled if you don't care about task counts
enable_restarts_metrics = true
  1. Alerting configuration. It is recommended to configure alerts for the following metrics:
  • Abnormal service state: systemd_unit_state{state!="active"} == 1
  • Frequent service restarts: increase(systemd_service_restart_total[5m]) > 3
  • Abnormal system state: systemd_system_running == 0

Troubleshooting

  1. Insufficient permissions
  • Make sure the categraf process has permission to access the systemd D-Bus interface
  • Check that the systemd service is running properly
  1. Version compatibility
  • Some metrics require systemd 212 or later
  • Check the systemd version on your system: systemctl --version
  1. D-Bus connection issues
  • Check the D-Bus service status: systemctl status dbus
  • Try setting systemd_private = true in the configuration file conf/input.systemd/systemd.toml