Ad Widget

Collapse

ZBXNEXT-10614 - Add memory information to systemd.unit.get item key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markfree
    Senior Member
    • Apr 2019
    • 872

    #1

    ZBXNEXT-10614 - Add memory information to systemd.unit.get item key

    Feature request ZBXNEXT-10614 posted on Zabbix Support portal. With more votes, the feature may be prioritized.



    When displaying a SystemD service status, we can see its memory consumption.
    Code:
    # 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:
    Code:
    # zabbix_agent2 -t systemd.unit.get["zabbix-agent2.service"]
    systemd.unit.get[zabbix-agent2.service] [s|{"AccessSELinuxContext":"","ActivationDetails":[],"ActiveEnterTimestamp":1775477148532049,"ActiveEn terTimestampMonotonic":7007559,"ActiveExitTimestam p":0,"ActiveExitTimestampMonotonic":0,"ActiveState ":{"state":1,"text":"active"},"After":["syslog.target","sysinit.target","system.slice","n etwork.target","basic.target","systemd-journald.socket"],"AllowIsolate":false,"AssertResult":true,"AssertT imestamp":1775477148531027,"AssertTimestampMonoton ic":7006537,"Asserts":[],"Before":["shutdown.target","multi-user.target"],"BindsTo":[],"BoundBy":[],"CanClean":[],"CanFreeze":true,"CanIsolate":false,"CanReload":f alse,"CanStart":true,"CanStop":true,"CollectMode": "inactive","ConditionResult":true,"ConditionTimest amp":1775477148531022,"ConditionTimestampMonotonic ":7006535,"Conditions":[],"ConflictedBy":[],"Conflicts":["shutdown.target"],"ConsistsOf":[],"DefaultDependencies":true,"Description":"Zabb ix Agent 2","Documentation":[],"DropInPaths":[],"FailureAction":"none","FailureActionExitStatu s":-1,"Following":"","FragmentPath":"/usr/lib/systemd/system/zabbix-agent2.service","FreezerState":"running","Id":"zab bix-agent2.service","IgnoreOnIsolate":false,"InactiveE nterTimestamp":0,"InactiveEnterTimestampMonotonic" :0,"InactiveExitTimestamp":1775477148532049,"Inact iveExitTimestampMonotonic":7007559,"InvocationID": "V/dTPBKbReyxkD0WbEFA8w==","Job":[0,"/"],"JobRunningTimeoutUSec":18446744073709551615,"Job TimeoutAction":"none","JobTimeoutRebootArgument":" ","JobTimeoutUSec":18446744073709551615,"JoinsName spaceOf":[],"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":fals e,"ReloadPropagatedFrom":[],"RequiredBy":[],"Requires":["sysinit.target","system.slice"],"RequiresMountsFor":[],"Requisite":[],"RequisiteOf":[],"SliceOf":[],"SourcePath":"","StartLimitAction":"none","StartL imitBurst":5,"StartLimitIntervalUSec":10000000,"St ateChangeTimestamp":1775477148532049,"StateChangeT imestampMonotonic":7007559,"StopPropagatedFrom":[],"StopWhenUnneeded":false,"SubState":"running","Su ccessAction":"none","SuccessActionExitStatus":-1,"Transient":false,"TriggeredBy":[],"Triggers":[],"UnitFilePreset":"disabled","UnitFileState":{"sta te":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.
    Code:
    $ 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.
Working...