PosgreSQL giám sát hoạt động của Linux bằng PosgreSQL extension system_stats

Từ PostgreSQL database có thể giám sát được hoạt động của hệ thống Linux nhờ PostgreSQL extension tên là system_stats.

system_stats được EnterpriseDB viết ra và cho mọi người xài miễn phí.

EnterpriseDB là công ty đứng sau PostgreSQL database, trả lương cho các kĩ sư phần mềm (software engineer) viết ra PostgreSQL miễn phí và EDB Postgres Advanced Server có phí.

pg_sys_os_info()

SELECT * FROM pg_sys_os_info();
-[ RECORD 1 ]-------+----------------------------------
name                | "Rocky Linux 9.3 (Blue Onyx)"    +
                    |
version             | Linux 5.14.0-362.8.1.el9_3.x86_64
host_name           | rocky93
domain_name         | (none)
handle_count        | 1760
process_count       | 204
thread_count        | 219
architecture        | x86_64
last_bootup_time    |
os_up_since_seconds | 20843

pg_sys_cpu_info()

SELECT * FROM pg_sys_cpu_info();
-[ RECORD 1 ]------+-----------------------------------------------
vendor             | GenuineIntel
description        | GenuineIntel model 141 family 6
model_name         | 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
processor_type     |
logical_processor  | 0
physical_processor | 4
no_of_cores        | 4
architecture       | x86_64
clock_speed_hz     | 2303998976
cpu_type           |
cpu_family         |
byte_order         |
l1dcache_size      | 48
l1icache_size      | 32
l2cache_size       | 1280
l3cache_size       | 24576

pg_sys_cpu_usage_info()

SELECT * FROM pg_sys_cpu_usage_info();
-[ RECORD 1 ]-------------------+----
usermode_normal_process_percent | 0
usermode_niced_process_percent  | 0
kernelmode_process_percent      | 0
idle_mode_percent               | 100
io_completion_percent           | 0
servicing_irq_percent           | 0
servicing_softirq_percent       | 0
user_time_percent               |
processor_time_percent          |
privileged_time_percent         |
interrupt_time_percent          |

pg_sys_memory_info()

SELECT * FROM pg_sys_memory_info();
-[ RECORD 1 ]----+-----------
total_memory     | 8282005504
used_memory      | 1008709632
free_memory      | 7273295872
swap_total       | 2147479552
swap_used        | 0
swap_free        | 2147479552
cache_total      | 556277760
kernel_total     |
kernel_paged     |
kernel_non_paged |
total_page_file  |
avail_page_file  |

pg_sys_io_analysis_info()

SELECT * FROM pg_sys_io_analysis_info();
 device_name | total_reads | total_writes | read_bytes | write_bytes | read_time_ms | write_time_ms
-------------+-------------+--------------+------------+-------------+--------------+---------------
 nvme0n1     |        9257 |        14802 |  224237056 |   573541888 |         1867 |         28565
 nvme0n1p1   |        1171 |           49 |    9231360 |     2409984 |           96 |            24
 nvme0n1p2   |        8014 |        14753 |  213793280 |   571131904 |         1757 |         28541
 sr0         |         108 |            0 |    4292608 |           0 |          101 |             0
 dm-0        |        7902 |        19880 |  210012672 |   571131904 |         1943 |         63123
 dm-1        |          98 |            0 |    2273280 |           0 |            6 |             0
(6 rows)

pg_sys_io_analysis_info()

SELECT * FROM pg_sys_disk_info();
-[ RECORD 1 ]----+----------------------------
mount_point      | /
file_system      | /dev/mapper/rl_rocky93-root
drive_letter     |
drive_type       |
file_system_type | xfs
total_space      | 18182307840
used_space       | 1600487424
free_space       | 16581820416
total_inodes     | 8910848
used_inodes      | 37338
free_inodes      | 8873510
-[ RECORD 2 ]----+----------------------------
mount_point      | /boot
file_system      | /dev/nvme0n1p1
drive_letter     |
drive_type       |
file_system_type | xfs
total_space      | 1006632960
used_space       | 200245248
free_space       | 806387712
total_inodes     | 524288
used_inodes      | 357
free_inodes      | 523931

pg_sys_load_avg_info()

SELECT * FROM pg_sys_load_avg_info();
-[ RECORD 1 ]------------+-----
load_avg_one_minute      | 0.06
load_avg_five_minutes    | 0.01
load_avg_ten_minutes     | 0
load_avg_fifteen_minutes |

pg_sys_process_info()

SELECT * FROM pg_sys_process_info();
-[ RECORD 1 ]------+----
total_processes    | 204
running_processes  | 1
sleeping_processes | 126
stopped_processes  | 0
zombie_processes   | 0

pg_sys_network_info()

SELECT * FROM pg_sys_network_info();
-[ RECORD 1 ]---+---------------
interface_name  | lo
ip_address      | 127.0.0.1
tx_bytes        | 0
tx_packets      | 0
tx_errors       | 0
tx_dropped      | 0
rx_bytes        | 0
rx_packets      | 0
rx_errors       | 0
rx_dropped      | 0
link_speed_mbps | 0
-[ RECORD 2 ]---+---------------
interface_name  | ens160
ip_address      | 192.168.71.177
tx_bytes        | 4270816
tx_packets      | 38546
tx_errors       | 0
tx_dropped      | 0
rx_bytes        | 92506200
rx_packets      | 84657
rx_errors       | 0
rx_dropped      | 0
link_speed_mbps | 10000

pg_sys_cpu_memory_by_process()

SELECT * FROM pg_sys_cpu_memory_by_process();
 pid |              name               | running_since_seconds | cpu_usage | memory_usage | memory_bytes
-----+---------------------------------+-----------------------+-----------+--------------+--------------
   1 | (systemd)                       |                    14 |         0 |         0.16 |     13066240
   2 | (kthreadd)                      |                    14 |         0 |            0 |            0
   3 | (rcu_gp)                        |                    14 |         0 |            0 |            0
   4 | (rcu_par_gp)                    |                    14 |         0 |            0 |            0
   5 | (slub_flushwq)                  |                    14 |         0 |            0 |            0
   6 | (netns)                         |                    14 |         0 |            0 |            0
   7 | (kworker/0:0-xfs-buf/dm-0)      |                    14 |         0 |            0 |            0
   8 | (kworker/0:0H-events_highpri)   |                    14 |         0 |            0 |            0
   9 | (kworker/u256:0-events_unbound) |                    14 |         0 |            0 |            0
  10 | (mm_percpu_wq)                  |                    14 |         0 |            0 |            0
  11 | (kworker/u256:1-events_unbound) |                    14 |         0 |            0 |            0
  12 | (rcu_tasks_kthre)               |                    14 |         0 |            0 |            0
  13 | (rcu_tasks_rude_)               |                    14 |         0 |            0 |            0
  14 | (rcu_tasks_trace)               |                    14 |         0 |            0 |            0
  15 | (ksoftirqd/0)                   |                    14 |         0 |            0 |            0
  16 | (pr/tty0)                       |                    14 |         0 |            0 |            0
  17 | (rcu_preempt)                   |                    14 |         0 |            0 |            0
  18 | (migration/0)                   |                    14 |         0 |            0 |            0
  19 | (idle_inject/0)                 |                    14 |         0 |            0 |            0
  20 | (kworker/0:1-ata_sff)           |                    14 |         0 |            0 |            0
  21 | (cpuhp/0)                       |                    14 |         0 |            0 |            0
  23 | (kdevtmpfs)                     |                    14 |         0 |            0 |            0
  24 | (inet_frag_wq)                  |                    14 |         0 |            0 |            0
  25 | (kauditd)                       |                    14 |         0 |            0 |            0
  26 | (kworker/0:2-xfs-inodegc/dm-0)  |                    14 |         0 |            0 |            0
  27 | (khungtaskd)                    |                    14 |         0 |            0 |            0
  28 | (kworker/u256:2-events_unbound) |                    14 |         0 |            0 |            0
  29 | (oom_reaper)                    |                    14 |         0 |            0 |            0
  30 | (writeback)                     |                    14 |         0 |            0 |            0
  31 | (kcompactd0)                    |                    14 |         0 |            0 |            0
  32 | (ksmd)                          |                    14 |         0 |            0 |            0
  33 | (khugepaged)                    |                    14 |         0 |            0 |            0
  34 | (cryptd)                        |                    14 |         0 |            0 |            0
  35 | (kintegrityd)                   |                    14 |         0 |            0 |            0
  36 | (kblockd)                       |                    14 |         0 |            0 |            0
  37 | (blkcg_punt_bio)                |                    14 |         0 |            0 |            0
  38 | (tpm_dev_wq)                    |                    14 |         0 |            0 |            0
  39 | (md)                            |                    14 |         0 |            0 |            0
  40 | (edac-poller)                   |                    14 |         0 |            0 |            0
  41 | (watchdogd)                     |                    14 |         0 |            0 |            0
  42 | (kworker/0:1H-xfs-log/dm-0)     |                    14 |         0 |            0 |            0
  43 | (kswapd0)                       |                    14 |         0 |            0 |            0
  48 | (kthrotld)                      |                    13 |         0 |            0 |            0
  49 | (kworker/0:3-rcu_par_gp)        |                    13 |         0 |            0 |            0
  53 | (irq/24-pciehp)                 |                    13 |         0 |            0 |            0
  54 | (irq/25-pciehp)                 |                    13 |         0 |            0 |            0
  55 | (irq/26-pciehp)                 |                    13 |         0 |            0 |            0
  56 | (irq/27-pciehp)                 |                    13 |         0 |            0 |            0
  57 | (irq/28-pciehp)                 |                    13 |         0 |            0 |            0
  58 | (irq/29-pciehp)                 |                    13 |         0 |            0 |            0
  59 | (irq/30-pciehp)                 |                    13 |         0 |            0 |            0
  60 | (irq/31-pciehp)                 |                    13 |         0 |            0 |            0
  61 | (irq/32-pciehp)                 |                    13 |         0 |            0 |            0
  62 | (irq/33-pciehp)                 |                    13 |         0 |            0 |            0
  63 | (irq/34-pciehp)                 |                    13 |         0 |            0 |            0
  64 | (irq/35-pciehp)                 |                    13 |         0 |            0 |            0
  65 | (irq/36-pciehp)                 |                    13 |         0 |            0 |            0
  66 | (irq/37-pciehp)                 |                    13 |         0 |            0 |            0
  67 | (irq/38-pciehp)                 |                    13 |         0 |            0 |            0
  68 | (irq/39-pciehp)                 |                    13 |         0 |            0 |            0
  69 | (irq/40-pciehp)                 |                    13 |         0 |            0 |            0
  70 | (irq/41-pciehp)                 |                    13 |         0 |            0 |            0
  71 | (irq/42-pciehp)                 |                    13 |         0 |            0 |            0
  72 | (irq/43-pciehp)                 |                    13 |         0 |            0 |            0
  73 | (irq/44-pciehp)                 |                    13 |         0 |            0 |            0
  74 | (irq/45-pciehp)                 |                    13 |         0 |            0 |            0
  75 | (irq/46-pciehp)                 |                    13 |         0 |            0 |            0
  76 | (irq/47-pciehp)                 |                    13 |         0 |            0 |            0
  77 | (irq/48-pciehp)                 |                    13 |         0 |            0 |            0
  78 | (irq/49-pciehp)                 |                    13 |         0 |            0 |            0
  79 | (irq/50-pciehp)                 |                    13 |         0 |            0 |            0
  80 | (irq/51-pciehp)                 |                    13 |         0 |            0 |            0
  81 | (irq/52-pciehp)                 |                    13 |         0 |            0 |            0
  82 | (irq/53-pciehp)                 |                    13 |         0 |            0 |            0
  83 | (irq/54-pciehp)                 |                    13 |         0 |            0 |            0
  84 | (irq/55-pciehp)                 |                    13 |         0 |            0 |            0
  85 | (acpi_thermal_pm)               |                    13 |         0 |            0 |            0
  86 | (kmpath_rdacd)                  |                    13 |         0 |            0 |            0
  87 | (kaluad)                        |                    13 |         0 |            0 |            0
  88 | (mld)                           |                    13 |         0 |            0 |            0
  89 | (ipv6_addrconf)                 |                    13 |         0 |            0 |            0
  91 | (kworker/u256:3-events_unbound) |                    13 |         0 |            0 |            0
  99 | (kstrp)                         |                    13 |         0 |            0 |            0
 111 | (zswap-shrink)                  |                    13 |         0 |            0 |            0
 228 | (kworker/u257:0)                |                    13 |         0 |            0 |            0
 433 | (nvme-wq)                       |                    12 |         0 |            0 |            0
 437 | (nvme-reset-wq)                 |                    12 |         0 |            0 |            0
 438 | (nvme-delete-wq)                |                    12 |         0 |            0 |            0
 440 | (nvme-auth-wq)                  |                    12 |         0 |            0 |            0
 443 | (ata_sff)                       |                    12 |         0 |            0 |            0
 445 | (scsi_eh_0)                     |                    12 |         0 |            0 |            0
 447 | (scsi_tmf_0)                    |                    12 |         0 |            0 |            0
 448 | (scsi_eh_1)                     |                    12 |         0 |            0 |            0
 449 | (scsi_tmf_1)                    |                    12 |         0 |            0 |            0
 513 | (kdmflush/253:0)                |                    12 |         0 |            0 |            0
 520 | (kdmflush/253:1)                |                    12 |         0 |            0 |            0
 538 | (xfsalloc)                      |                    11 |         0 |            0 |            0
 539 | (xfs_mru_cache)                 |                    11 |         0 |            0 |            0
 540 | (xfs-buf/dm-0)                  |                    11 |         0 |            0 |            0
 541 | (xfs-conv/dm-0)                 |                    11 |         0 |            0 |            0
 542 | (xfs-reclaim/dm-)               |                    11 |         0 |            0 |            0
 543 | (xfs-blockgc/dm-)               |                    11 |         0 |            0 |            0
 544 | (xfs-inodegc/dm-)               |                    11 |         0 |            0 |            0
 545 | (xfs-log/dm-0)                  |                    11 |         0 |            0 |            0
 546 | (xfs-cil/dm-0)                  |                    11 |         0 |            0 |            0
 547 | (xfsaild/dm-0)                  |                    11 |         0 |            0 |            0
 608 | (systemd-journal)               |                    11 |         0 |         0.12 |      9863168
 622 | (systemd-udevd)                 |                    11 |         0 |         0.12 |      9904128
 652 | (xfs-buf/nvme0n1)               |                    11 |         0 |            0 |            0
 653 | (xfs-conv/nvme0n)               |                    11 |         0 |            0 |            0
 654 | (xfs-reclaim/nvm)               |                    11 |         0 |            0 |            0
 655 | (xfs-blockgc/nvm)               |                    11 |         0 |            0 |            0
 656 | (xfs-inodegc/nvm)               |                    11 |         0 |            0 |            0
 657 | (xfs-log/nvme0n1)               |                    11 |         0 |            0 |            0
 658 | (xfs-cil/nvme0n1)               |                    11 |         0 |            0 |            0
 659 | (xfsaild/nvme0n1)               |                    11 |         0 |            0 |            0
 664 | (dbus-broker-lau)               |                    11 |         0 |         0.06 |      4755456
 665 | (kworker/0:4-ata_sff)           |                    11 |         0 |            0 |            0
 666 | (NetworkManager)                |                    11 |         0 |         0.29 |     23683072
 668 | (dbus-broker)                   |                    11 |         0 |         0.03 |      2764800
 670 | (systemd-logind)                |                    11 |         0 |         0.11 |      9347072
 674 | (systemd-hostnam)               |                    11 |         0 |         0.08 |      6791168
 676 | (nm-dispatcher)                 |                    10 |         0 |          0.1 |      8454144
 684 | (sshd)                          |                    10 |         0 |         0.12 |      9637888
 690 | (agetty)                        |                    10 |         0 |         0.01 |      1110016
 701 | (postgres)                      |                    10 |         0 |         0.34 |     27811840
 714 | (kworker/0:2H-kblockd)          |                    10 |         0 |            0 |            0
 722 | (postgres)                      |                    10 |         0 |         0.07 |      5808128
 723 | (postgres)                      |                    10 |         0 |         0.08 |      6356992
 724 | (postgres)                      |                    10 |         0 |         0.08 |      6356992
 727 | (postgres)                      |                    10 |         0 |         0.08 |      6295552
 728 | (postgres)                      |                    10 |         0 |         0.11 |      8884224
 729 | (postgres)                      |                    10 |         0 |         0.11 |      8896512
 735 | (irq/75-vmw_vmci)               |                    10 |         0 |            0 |            0
 736 | (irq/76-vmw_vmci)               |                    10 |         0 |            0 |            0
 737 | (irq/77-vmw_vmci)               |                    10 |         0 |            0 |            0
 746 | (irq/16-vmwgfx)                 |                    10 |         0 |            0 |            0
 747 | (ttm)                           |                    10 |         0 |            0 |            0
 758 | (sshd)                          |                     8 |         0 |         0.15 |     12410880
 761 | (systemd)                       |                     7 |         0 |         0.14 |     11657216
 762 | ((sd-pam))                      |                     7 |         0 |         0.04 |      3158016
 769 | (sshd)                          |                     7 |         0 |         0.08 |      6590464
 770 | (bash)                          |                     7 |         0 |         0.06 |      5271552
 791 | (su)                            |                     5 |         0 |         0.08 |      6819840
 792 | (bash)                          |                     5 |         0 |         0.06 |      5259264
 830 | (psql)                          |                     4 |         0 |         0.09 |      7385088
 831 | (postgres)                      |                     4 |         0 |         0.21 |     17199104
(147 rows)