LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find memory used by Services. (https://www.linuxquestions.org/questions/linux-newbie-8/find-memory-used-by-services-4175619662/)

ddenial 12-15-2017 04:48 AM

Find memory used by Services.
 
Hello

I know how to find memory used by processes by using ps or top command. But how do I find memory usage by services.

I want to see how much these each service are consuming ram.
Code:

systemctl list-unit-files --type service --state enabled
UNIT FILE                                  STATE 
abrt-journal-core.service                  enabled
abrt-oops.service                          enabled
abrt-vmcore.service                        enabled
abrt-xorg.service                          enabled
abrtd.service                              enabled
accounts-daemon.service                    enabled
akmods.service                              enabled
atd.service                                enabled
auditd.service                              enabled
autovt@.service                            enabled
avahi-daemon.service                        enabled
bluetooth.service                          enabled
chronyd.service                            enabled
crond.service                              enabled
dbus-org.bluez.service                      enabled
dbus-org.fedoraproject.FirewallD1.service  enabled
dbus-org.freedesktop.Avahi.service          enabled
dbus-org.freedesktop.ModemManager1.service  enabled
dbus-org.freedesktop.network1.service      enabled
dbus-org.freedesktop.NetworkManager.service enabled
dbus-org.freedesktop.nm-dispatcher.service  enabled
dbus-org.freedesktop.resolve1.service      enabled
dbus-org.freedesktop.timedate1.service      enabled
dbxtool.service                            enabled
display-manager.service                    enabled
dmraid-activation.service                  enabled
fedora-import-state.service                enabled
fedora-readonly.service                    enabled
firewalld.service                          enabled
gdm.service                                enabled
getty@.service                              enabled
iscsi.service                              enabled
libvirtd.service                            enabled
lvm2-monitor.service                        enabled
mcelog.service                              enabled
mdmonitor.service                          enabled
ModemManager.service                        enabled
multipathd.service                          enabled
NetworkManager-dispatcher.service          enabled
NetworkManager-wait-online.service          enabled
NetworkManager.service                      enabled
ostree-remount.service                      enabled
rngd.service                                enabled
rtkit-daemon.service                        enabled
smb.service                                enabled
spice-vdagentd.service                      enabled
sssd.service                                enabled
switcheroo-control.service                  enabled
systemd-networkd.service                    enabled
systemd-resolved.service                    enabled
timedatex.service                          enabled
udisks2.service                            enabled
vgauthd.service                            enabled
vmtoolsd.service                            enabled
vsftpd.service                              enabled

55 unit files listed.


sevendogsbsd 12-17-2017 08:04 AM

Give htop a try - it shows services and memory used on my box. Can't speak for whether it shows this data in distros using systemd because I use runit.

Mill J 12-17-2017 09:47 AM

Your using Ubuntu. right? Why don't you just use the system monitor? It's graphic and preinstalled on all the Ubuntus I have run.

ddenial 12-17-2017 02:47 PM

No. It's Fedora 27. System Monitor shows only processes. I'm referring to services.

Anyway came across this article monitoring systemd services by using systemd-cgtop. Will check and see if it works.

AwesomeMachine 12-17-2017 05:08 PM

So, you want to display only services in the output?
Code:

$ ps auxU root

syg00 12-17-2017 05:26 PM

That cgtop looks interesting - note on F27 you will have to enable most of that accounting yourself.

frankbell 12-17-2017 09:11 PM

I agree with syg00.

Look at man systemd-cgtop or check this link: https://www.freedesktop.org/software...emd-cgtop.html

Here's a bit of the output:

Code:

$ systemd-cgtop

Path                                    Tasks  %CPU  Memory  Input/s Output/s

/                                          193      -    2.1G        -        -
/system.slice/ModemManager.service          1      -        -        -        -
/system.slice/NetworkManager.service        2      -        -        -        -
/system.slice/abrt-oops.service              1      -        -        -        -

Most services, as opposed to daemons (processes) were using little or no memory.

ddenial 12-18-2017 06:01 AM

After following the steps (except last one) as mentioned on this website, I'm getting the following result:

Code:

# systemd-cgtop -m
Control Group                          Tasks  %CPU  Memory  Input/s Output/s
/                                          -    5.9    5.3G        -        -
/system.slice                            113    0.0  544.1M        -        -
/system.slice/packagekit.service          3      -    44.6M        -        -
/init.scope                                1    0.0    11.1M        -        -
/system.slice/crond.service                1      -    2.3M        -        -
/system.slice/sssd-kcm.service            1      -    2.2M        -        -
/system.slice/sssd-secrets.service        1      -    1.8M        -        -
/system.slice/smb.service                  4      -    1.7M        -        -
/system.sli…systemd-journald.service      1      -    1.1M        -        -
/system.slice/cups.service                1    0.0  396.0K        -        -
/system.slice/dbus.service                5      -  396.0K        -        -
/system.slice/NetworkManager.service      3      -  328.0K        -        -
/system.slice/sssd.service                3    0.0  196.0K        -        -
/system.slice/auditd.service              5      -  180.0K        -        -
/system.slice/udisks2.service              5      -  176.0K        -        -
/system.slice/systemd-logind.service      1      -  128.0K        -        -
/system.slice/systemd-udevd.service        1      -  128.0K        -        -
/system.slice/chronyd.service              1      -  116.0K        -        -
/system.slice/colord.service              3      -    48.0K        -        -
/system.slice/upower.service              3      -    12.0K        -        -
/system.slice/abrt-xorg.service            1      -    8.0K        -        -
/system.slice/abrt-oops.service            1      -    4.0K        -        -
/system.slice/geoclue.service              3      -    4.0K        -        -

But, If I check the total residential memory usage of samba through ps, I get this result.

Code:


# pidof smbd
971 905 904 823

# ps -o pid,user,rss,comm -C $(pidof smbd)
  PID USER      RSS COMMAND
  823 root    20800 smbd
  904 root      4956 smbd-notifyd
  905 root      4232 cleanupd

Please note that for samba systemd-cgtop show memory usage of 1.7mb, whereas ps show the usage of nearly 30mb. Also, both systemd-cgtop and pidof smbd shows same 4 tasks. But in pf command, only 3 tasks are shown, PID 971, in this case, is missing.

How come there is a difference. Appreciate if someone explains why.

Thanks

scasey 12-18-2017 11:52 AM

I don't know the answer to your last question about the missing pid (although I note that the -C wants process names, not pids, so I don't understand how it works at all... -p wants a pidlist), but isn't the ps total shown nearly 30Kb -- not 30Mb???

ddenial 12-18-2017 08:55 PM

Quote:

Originally Posted by scasey (Post 5794621)
I don't know the answer to your last question about the missing pid (although I note that the -C wants process names, not pids, so I don't understand how it works at all... -p wants a pidlist), but isn't the ps total shown nearly 30Kb -- not 30Mb???

You're right I should have used -p. For some good reason, Its now showing correctly. And I think its mb not kb.

Code:

$ systemd-cgtop -m | grep smb
/system.slice/smb.service                          4      -    22.8M        -        -

$ ps -o pid,user,rss,comm -p $(pidof smbd)
  PID USER      RSS COMMAND
  872 root    20368 smbd
 1009 root      4960 smbd-notifyd
 1010 root      4236 cleanupd
 1038 root      5580 lpqd

$ top
top - 08:20:17 up 12 min,  1 user,  load average: 0.05, 0.54, 0.51
Tasks: 277 total,  1 running, 209 sleeping,  0 stopped,  0 zombie
%Cpu(s):  0.6 us,  0.6 sy,  0.0 ni, 98.4 id,  0.2 wa,  0.1 hi,  0.0 si,  0.0 st
MiB Mem : 7920.203 total, 4493.922 free, 1943.145 used, 1483.137 buff/cache
MiB Swap:    0.000 total,    0.000 free,    0.000 used. 5575.648 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM    TIME+ COMMAND                                                                                               
  872 root      20  0  448.9m  19.9m  17.5m S  0.0  0.3  0:00.06 smbd                                                                                                 
 1009 root      20  0  421.6m  4.8m  2.6m S  0.0  0.1  0:00.00 smbd-notifyd 
 1010 root      20  0  421.6m  4.1m  1.9m S  0.0  0.1  0:00.00 cleanupd                                                                                             
 1038 root      20  0  448.9m  6.1m  3.7m S  0.0  0.1  0:00.00 lpqd

Thanks


All times are GMT -5. The time now is 05:52 PM.