Add memory information to systemd.unit.get item key

XMLWordPrintable

      When displaying a SystemD service status, we can see its memory consumption.

       

      # systemctl status zabbix-agent2.service
      ● zabbix-agent2.service - Zabbix Agent 2
           Loaded: loaded (/usr/lib/systemd/system/zabbix-agent2.service; enabled; preset: disabled)
           Active: active (running) since Wed 2026-05-06 12:03:38 -03; 45min ago
         Main PID: 3516641 (zabbix_agent2)
            Tasks: 16
           Memory: 20.5M (peak: 25.5M)
              CPU: 9.180s
           CGroup: /system.slice/zabbix-agent2.service
                   └─3516641 /usr/sbin/zabbix_agent2 -c /etc/zabbix/zabbix_agent2.confMay 06 12:03:38 ... systemd[1]: Started Zabbix Agent 2.
      May 06 12:03:38 ... zabbix_agent2[3516641]: Starting Zabbix Agent 2 (7.4.3)
      May 06 12:03:38 ... zabbix_agent2[3516641]: Zabbix Agent2 hostname: [...]
      May 06 12:03:38 ... zabbix_agent2[3516641]: Press Ctrl+C to exit.

       

       

       

      Since Zabbix Agent2 can monitor SystemD services, it reads the SystemD dbus and returns many data from each service. However, it does not return memory information for each service.
      When querying a service with Zabbix Agent2, it provides data such as this:

      # zabbix_agent2 -t systemd.unit.get["zabbix-agent2.service"]
      systemd.unit.get[zabbix-agent2.service]       [s|{"AccessSELinuxContext":"","ActivationDetails":[],"ActiveEnterTimestamp":1775477148532049,"ActiveEnterTimestampMonotonic":7007559,"ActiveExitTimestamp":0,"ActiveExitTimestampMonotonic":0,"ActiveState":{"state":1,"text":"active"},"After":["syslog.target","sysinit.target","system.slice","network.target","basic.target","systemd-journald.socket"],"AllowIsolate":false,"AssertResult":true,"AssertTimestamp":1775477148531027,"AssertTimestampMonotonic":7006537,"Asserts":[],"Before":["shutdown.target","multi-user.target"],"BindsTo":[],"BoundBy":[],"CanClean":[],"CanFreeze":true,"CanIsolate":false,"CanReload":false,"CanStart":true,"CanStop":true,"CollectMode":"inactive","ConditionResult":true,"ConditionTimestamp":1775477148531022,"ConditionTimestampMonotonic":7006535,"Conditions":[],"ConflictedBy":[],"Conflicts":["shutdown.target"],"ConsistsOf":[],"DefaultDependencies":true,"Description":"Zabbix Agent 2","Documentation":[],"DropInPaths":[],"FailureAction":"none","FailureActionExitStatus":-1,"Following":"","FragmentPath":"/usr/lib/systemd/system/zabbix-agent2.service","FreezerState":"running","Id":"zabbix-agent2.service","IgnoreOnIsolate":false,"InactiveEnterTimestamp":0,"InactiveEnterTimestampMonotonic":0,"InactiveExitTimestamp":1775477148532049,"InactiveExitTimestampMonotonic":7007559,"InvocationID":"V/dTPBKbReyxkD0WbEFA8w==","Job":[0,"/"],"JobRunningTimeoutUSec":18446744073709551615,"JobTimeoutAction":"none","JobTimeoutRebootArgument":"","JobTimeoutUSec":18446744073709551615,"JoinsNamespaceOf":[],"LoadError":["",""],"LoadState":{"state":1,"text":"loaded"},"Markers":[],"Names":["zabbix-agent2.service"],"NeedDaemonReload":false,"OnFailure":[],"OnFailureJobMode":"replace","OnFailureOf":[],"OnSuccess":[],"OnSuccessJobMode":"fail","OnSuccessOf":[],"PartOf":[],"Perpetual":false,"PropagatesReloadTo":[],"PropagatesStopTo":[],"RebootArgument":"","Refs":[],"RefuseManualStart":false,"RefuseManualStop":false,"ReloadPropagatedFrom":[],"RequiredBy":[],"Requires":["sysinit.target","system.slice"],"RequiresMountsFor":[],"Requisite":[],"RequisiteOf":[],"SliceOf":[],"SourcePath":"","StartLimitAction":"none","StartLimitBurst":5,"StartLimitIntervalUSec":10000000,"StateChangeTimestamp":1775477148532049,"StateChangeTimestampMonotonic":7007559,"StopPropagatedFrom":[],"StopWhenUnneeded":false,"SubState":"running","SuccessAction":"none","SuccessActionExitStatus":-1,"Transient":false,"TriggeredBy":[],"Triggers":[],"UnitFilePreset":"disabled","UnitFileState":{"state":1,"text":"enabled"},"UpheldBy":[],"Upholds":[],"WantedBy":["multi-user.target"],"Wants":[]}]

       

       

      According to the Zabbix documentation, the Agent's "systemd.unit.get" key "returns all properties of a systemd unit".

      This is not really accurate. It does not return memory properties from a SystemD service.
      There is no memory information, even though it is provided by SystemD.

      $ systemctl show --property=MemoryCurrent --value zabbix-agent2.service
      21876736

       

      Therefore, by default, it's not possible to create a dependent item to extract this information.

      To get the service memory information, it is necessary to either add a custom UserParameter or allow a system.run[...] key to query this data. Both methods require reconfiguring Zabbix Agent2 and restarting it which may not be optimal for many host setups.

      Please, add the memory information to the systemd.unit.get item key, and create a new dependent item (such as "{#UNIT.NAME}: Service Memory Usage") for the SystemD standard template.
      I find this information very usefull to know if a service is consuming too much memory.

            Assignee:
            Zabbix Integration Team
            Reporter:
            MArk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: