Monitor systemd user unit?


Does the netdata systemd plugin montor systemd units started by users other than root? I have a unit that’s run from non-root user and running the systemd plugin in debug mode i get this

[ INFO  ] discovery[file manager] discovery.go:73 instance is started
[ INFO  ] discovery[file reader] read.go:41 instance is started
[ INFO  ] discovery[file reader] read.go:42 instance is stopped
[ DEBUG ] build[manager] build.go:164 received config group ('/etc/netdata/go.d/systemdunits.conf'): 1 jobs (added: 1, removed: 0)
[ DEBUG ] build[manager] build.go:313 building systemdunits[user-unit.service] job, config: map[__provider__:file reader __source__:/etc/netdata/go.d/systemdunits.conf autodetection_retry:0 include:[user-unit.service.service] module:systemdunits name:user-unit.service priority:70000 update_every:10]
[ DEBUG ] systemdunits[user-unit.service] systemdunits.go:74 unit names patterns: [user-unit.service.service]
[ DEBUG ] systemdunits[user-unit.service] systemdunits.go:75 timeout: 2s
[ DEBUG ] systemdunits[user-unit.service] collect.go:129 calling function 'GetManagerProperty'
[ DEBUG ] systemdunits[user-unit.service] collect.go:135 systemd version: "247.3-7+deb11u4"
[ DEBUG ] systemdunits[user-unit.service] collect.go:175 calling function 'ListUnitsByPatterns'
[ DEBUG ] systemdunits[user-unit.service] collect.go:188 got total/loaded 0/0 units
[ ERROR ] systemdunits[user-unit.service] job.go:205 check failed
[ DEBUG ] run[manager] run.go:43 tick 0

Configuration of systemdunits.conf :

root@server:/etc/netdata/go.d# cat systemdunits.conf 
  - name: user-unit.service
      - 'user-unit.service'

1 Like

hello and welcome! sorry for the delay here - summer holidays n all i think a few posts might slip through the cracks :slight_smile:

let me have a look and see if i can help answer this or tag someone else in if i need to.

hmm actually am out of my depth here :slight_smile:

@ilyam8 i’d say you might know this one - any ideas?

i had a read here but am not sure tbh Systemd units state collector | Learn Netdata

[ DEBUG ] systemdunits[user-unit.service] collect.go:188 got total/loaded 0/0 units

It means that there is no unit name with user-unit.service.

Hi and thank you for your replies!

The unit definitely exists, however the netdata systemd collector seems to have issues with user units. I know that you need to do some trickery when using systemd unit files per user, like setting user DBUS , enabling lingering if you want to service that the unit controls to keep running after the user session exits etc.

I know this might not have to do anything with with netdata, I’m mentioning this just to point there are complications to consider when using systemd user services.

I’m assuming since the netdata runs as its own user it cannot access other users systemd files?

Can you try

      - '*.service'

and see if you get your unit?

You can try it in your terminal, the collector does is the same as

systemctl --all list-units PATTERN

So I think systemctl --all list-units user-unit.service will return nothing too

~# systemctl --all list-units user*
0 loaded units listed.
To show all installed unit files use 'systemctl list-unit-files'.

This was run from root as well as from netdata user.


      - '*.service'

does not show the user unit. Other ones do show up in graph.

0 loaded units listed

As you see there is no unit that matches user* pattern. Try systemctl --all list-units and find the one you need.

Well the one I need is not listed by the above commands. If I switch to the user account that has that service I can see it.

Like I said, it seems systemctl has trouble listing the services from other users from the root account due to DBUS and user session.

So I guess netdata can’t do it as well.

Ah, I see - I guess we need to connect to the user session bus, what we do now is we always connect to the system bus. I am not sure this will be possible without root privileges. Perhaps adding netdata user to some group will do, need to check.