7 Discovery of systemd services

Overview

It is possible to discover systemd units (services, by default) with Zabbix.

Item key

The item to use in the discovery rule is the

  1. systemd.unit.discovery

This item key is only supported in Zabbix agent 2.

This item returns a JSON with information about systemd units, for example:

  1. [{
  2. "{#UNIT.NAME}": "mysqld.service",
  3. "{#UNIT.DESCRIPTION}": "MySQL Server",
  4. "{#UNIT.LOADSTATE}": "loaded",
  5. "{#UNIT.ACTIVESTATE}": "active",
  6. "{#UNIT.SUBSTATE}": "running",
  7. "{#UNIT.FOLLOWED}": "",
  8. "{#UNIT.PATH}": "/org/freedesktop/systemd1/unit/mysqld_2eservice",
  9. "{#UNIT.JOBID}": 0,
  10. "{#UNIT.JOBTYPE}": ""
  11. "{#UNIT.JOBPATH}": "/",
  12. "{#UNIT.UNITFILESTATE}": "enabled"
  13. }, {
  14. "{#UNIT.NAME}": "systemd-journald.socket",
  15. "{#UNIT.DESCRIPTION}": "Journal Socket",
  16. "{#UNIT.LOADSTATE}": "loaded",
  17. "{#UNIT.ACTIVESTATE}": "active",
  18. "{#UNIT.SUBSTATE}": "running",
  19. "{#UNIT.FOLLOWED}": "",
  20. "{#UNIT.PATH}": "/org/freedesktop/systemd1/unit/systemd_2djournald_2esocket",
  21. "{#UNIT.JOBID}": 0,
  22. "{#UNIT.JOBTYPE}": "",
  23. "{#UNIT.JOBPATH}": "/"
  24. "{#UNIT.UNITFILESTATE}": "enabled"
  25. }]

Supported macros

The following macros are supported for use in the discovery rule filter and prototypes of items, triggers and graphs:

MacroDescription
{#UNIT.NAME}Primary unit name.
{#UNIT.DESCRIPTION}Human readable description.
{#UNIT.LOADSTATE}Load state (i.e. whether the unit file has been loaded successfully)
{#UNIT.ACTIVESTATE}Active state (i.e. whether the unit is currently started or not)
{#UNIT.SUBSTATE}Sub state (a more fine-grained version of the active state that is specific to the unit type, which the active state is not)
{#UNIT.FOLLOWED}Unit that is being followed in its state by this unit, if there is any; otherwise an empty string.
{#UNIT.PATH}Unit object path.
{#UNIT.JOBID}Numeric job ID if there is a job queued for the job unit; 0 otherwise.
{#UNIT.JOBTYPE}Job type.
{#UNIT.JOBPATH}Job object path.
{#UNIT.UNITFILESTATE}The install state of the unit file (supported since 5.2.2).

Item prototypes

Item prototypes that can be created based on systemd service discovery include, for example:

  • Item name: {#UNIT.DESCRIPTION}; item key: systemd.unit.info["{#UNIT.NAME}"]

  • Item name: {#UNIT.DESCRIPTION}; item key: systemd.unit.info["{#UNIT.NAME}",LoadState]

systemd.unit.info agent items are supported since Zabbix 4.4.