Friday, April 17, 2026

.::: Command Check top service, Top Memory in Linux (Centos 9, Rhel 9, Almalinux 9 include grouping & size memory & count proccess ) Top Process

 
1. total Service group 

ps -eo comm | sort | uniq -c | sort -nr | head

[root@teguhth ~]# ps -eo comm | sort | uniq -c | sort -nr | head
     13 sshd
     10 postgres
      8 nfsd
      5 metricbeat
      4 kworker/R-xfs-c
      4 kworker/R-xfs-b
      4 bash
      3 systemd
      3 filebeat
      2 sort
[root@teguhth ~]#

 
2. total Service group base on filter (maria or postgres

ps -eo comm | sort | uniq -c |  grep -i mariadb
 
ps -eo comm | sort | uniq -c |  grep -i postgres

[root@teguhth ~]# ps -eo comm | sort | uniq -c |  grep -i mariadb
      1 mariadbd
[root@teguhth ~]#
[root@teguhth ~]# ps -eo comm | sort | uniq -c |  grep -i postgres
     10 postgres
[root@teguhth ~]#


3. sample postgres has 10 process

[root@teguhth ~]# systemctl status mariadb
? mariadb.service - MariaDB 12.1.0 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             +-migrated-from-my.cnf-settings.conf
     Active: active (running) since Thu 2026-04-16 10:28:49 WIB; 3h 57min ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 1153840 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 1153841 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemct>
    Process: 1154035 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
   Main PID: 1154023 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 173 (limit: 251623)
     Memory: 23.2G
        CPU: 1h 33min 23.986s
     CGroup: /system.slice/mariadb.service
             +-1154023 /usr/sbin/mariadbd

Apr 16 10:28:29 teguhth systemd[1]: Starting MariaDB 12.1.0 database server...
Apr 16 10:28:49 teguhth systemd[1]: Started MariaDB 12.1.0 database server.

[root@teguhth ~]#

[root@teguhth ~]# systemctl status postgresql-18
? postgresql-18.service - PostgreSQL 18 database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql-18.service; enabled; preset: disabled)
     Active: active (running) since Mon 2026-04-06 15:53:01 WIB; 1 week 2 days ago
       Docs: https://www.postgresql.org/docs/18/static/
    Process: 1034 ExecStartPre=/usr/pgsql-18/bin/postgresql-18-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
   Main PID: 1076 (postgres)
      Tasks: 10 (limit: 203332)
     Memory: 13.1M
        CPU: 5min 2.652s
     CGroup: /system.slice/postgresql-18.service
             +-1076 /usr/pgsql-18/bin/postgres -D /var/lib/pgsql/18/data/
             +-1770 "postgres: logger "
             +-1862 "postgres: io worker 0"
             +-1863 "postgres: io worker 1"
             +-1864 "postgres: io worker 2"
             +-1866 "postgres: checkpointer "
             +-1867 "postgres: background writer "
             +-1881 "postgres: walwriter "
             +-1882 "postgres: autovacuum launcher "
             +-1883 "postgres: logical replication launcher "


Apr 06 15:53:00 teguhth systemd[1]: Starting PostgreSQL 18 database server...
Apr 06 15:53:01 teguhth postgres[1076]: 2026-04-06 15:53:01.557 WIB [1076] LOG:  redirecting log output to logging collector process
Apr 06 15:53:01 teguhth postgres[1076]: 2026-04-06 15:53:01.557 WIB [1076] HINT:  Future log output will appear in directory "log".
Apr 06 15:53:01 teguhth systemd[1]: Started PostgreSQL 18 database server.
[root@teguhth ~]#


4. check memory service 

ps -eo pid,ppid,cmd,%mem,rss | grep maria
ps -eo pid,ppid,cmd,%mem,rss | grep -i postgres

[root@teguhth ~]# ps -eo pid,ppid,cmd,%mem,rss | grep maria
1154023       1 /usr/sbin/mariadbd          59.6 19425036
1375881 1369890 grep --color=auto maria      0.0  2304
[root@teguhth ~]#
[root@teguhth ~]# ps -eo pid,ppid,cmd,%mem,rss | grep -i postgres
   1076       1 /usr/pgsql-18/bin/postgres   0.0  9216
   1770    1076 postgres: logger             0.0  3800
   1862    1076 postgres: io worker 0        0.0  4320
   1863    1076 postgres: io worker 1        0.0  4320
   1864    1076 postgres: io worker 2        0.0  3936
   1866    1076 postgres: checkpointer       0.0  4832
   1867    1076 postgres: background writer  0.0  4192
   1881    1076 postgres: walwriter          0.0  3936
   1882    1076 postgres: autovacuum launch  0.0  4704
   1883    1076 postgres: logical replicati  0.0  4320
[root@teguhth ~]#


5. dalam mb

ps -eo pid,ppid,%mem,rss,cmd | awk 'NR==1{print;next} {printf "%s %s %.1f %.2f MB %s\n",$1,$2,$3,$4/1024,$5}' | grep -i MariaDB
ps -eo pid,ppid,%mem,rss,cmd | awk 'NR==1{print;next} {printf "%s %s %.1f %.2f MB %s\n",$1,$2,$3,$4/1024,$5}' | grep -i postgres

[root@teguhth ~]# ps -eo pid,ppid,%mem,rss,cmd | awk 'NR==1{print;next} {printf "%s %s %.1f %.2f MB %s\n",$1,$2,$3,$4/1024,$5}' | grep -i MariaDB
1154023 1 59.7 19001.62 MB /usr/sbin/mariadbd
[root@teguhth ~]#
[root@teguhth ~]# ps -eo pid,ppid,%mem,rss,cmd | awk 'NR==1{print;next} {printf "%s %s %.1f %.2f MB %s\n",$1,$2,$3,$4/1024,$5}' | grep -i postgres
1076 1 0.0 9.00 MB /usr/pgsql-18/bin/postgres
1770 1076 0.0 3.71 MB postgres:
1862 1076 0.0 4.22 MB postgres:
1863 1076 0.0 4.22 MB postgres:
1864 1076 0.0 3.84 MB postgres:
1866 1076 0.0 4.72 MB postgres:
1867 1076 0.0 4.09 MB postgres:
1881 1076 0.0 3.84 MB postgres:
1882 1076 0.0 4.59 MB postgres:
1883 1076 0.0 4.22 MB postgres:
[root@teguhth ~]#


6. dlm giga

ps -eo pid,ppid,%mem,rss,cmd | awk 'NR==1{print;next} {printf "%s %s %.1f %.2f GB %s\n",$1,$2,$3,$4/1024/1024,$5}' | grep -i MariaDB
ps -eo pid,ppid,%mem,rss,cmd | awk 'NR==1{print;next} {printf "%s %s %.1f %.2f GB %s\n",$1,$2,$3,$4/1024/1024,$5}' | grep -i postgres

[root@teguhth ~]# ps -eo pid,ppid,%mem,rss,cmd | awk 'NR==1{print;next} {printf "%s %s %.1f %.2f GB %s\n",$1,$2,$3,$4/1024/1024,$5}' | grep -i MariaDB
1154023 1 59.7 18.57 GB /usr/sbin/mariadbd
[root@teguhth ~]#
[root@teguhth ~]# ps -eo pid,ppid,%mem,rss,cmd | awk 'NR==1{print;next} {printf "%s %s %.1f %.2f GB %s\n",$1,$2,$3,$4/1024/1024,$5}' | grep -i postgres
1076 1 0.0 0.01 GB /usr/pgsql-18/bin/postgres
1770 1076 0.0 0.00 GB postgres:
1862 1076 0.0 0.00 GB postgres:
1863 1076 0.0 0.00 GB postgres:
1864 1076 0.0 0.00 GB postgres:
1866 1076 0.0 0.00 GB postgres:
1867 1076 0.0 0.00 GB postgres:
1881 1076 0.0 0.00 GB postgres:
1882 1076 0.0 0.00 GB postgres:
1883 1076 0.0 0.00 GB postgres:
[root@teguhth ~]#


7. check memory service total (no filter) 

ps -eo comm,rss | awk '{mem[$1]+=$2} END {for (i in mem) print i, mem[i]/1024 " MB"}' | sort -k2 -nr | head

[root@teguhth ~]# ps -eo comm,rss | awk '{mem[$1]+=$2} END {for (i in mem) print i, mem[i]/1024 " MB"}' | sort -k2 -nr | head
mariadbd 19016.3 MB
metricbeat 319.082 MB
filebeat 200.777 MB
sshd 113.852 MB
vmagent 100.438 MB
tailscaled 88.0234 MB
pmm-agent 49.293 MB
postgres 46.4609 MB
systemd-journal 39.375 MB
elastic-agent 34.6875 MB
[root@teguhth ~]#


8. check memory service total with filter (mariadb or sql server)

# filter maria
ps -eo comm,rss | awk '{mem[$1]+=$2} END {for (i in mem) print i, mem[i]/1024 " MB"}' | sort -k2 -nr | grep -i maria
ps -eo comm,rss | awk '{mem[$1]+=$2} END {for (i in mem) print i, mem[i]/1024 " MB"}' | sort -k2 -nr | grep -i postgres

[root@teguhth ~]# ps -eo comm,rss | awk '{mem[$1]+=$2} END {for (i in mem) print i, mem[i]/1024 " MB"}' | sort -k2 -nr | grep -i maria
mariadbd 19195.2 MB
[root@teguhth ~]#
[root@teguhth ~]# ps -eo comm,rss | awk '{mem[$1]+=$2} END {for (i in mem) print i, mem[i]/1024 " MB"}' | sort -k2 -nr | grep -i postgres
postgres 46.4609 MB
[root@teguhth ~]#

No comments:

Post a Comment

Popular Posts