Linux查看服务器内存的方法
在Linux系统中,我们可以通过多种命令来查看服务器的内存使用情况,本文将介绍几种常用的方法,包括free
命令、top
命令和vmstat
命令。
1、使用free
命令
free
命令是Linux系统中最常用的查看内存使用情况的命令,它可以显示系统中物理内存和交换空间的使用情况,使用方法如下:
free -h
-h
选项表示以人类可读的格式显示结果,即自动将字节转换为KB、MB或GB等单位。
输出结果示例:
total used free shared buff/cache available Mem: 7.7G 3.1G 1.2G 1.0M 4.3G 3.9G Swap: 2.0G 0B 2.0G
从输出结果中,我们可以看到服务器的总内存为7.7G,已使用3.1G,剩余可用内存为1.2G,还可以看到交换分区的使用情况。
2、使用top
命令
top
命令可以实时显示系统中各个进程的资源占用情况,包括CPU、内存、磁盘等,使用方法如下:
top
在top
命令的输出结果中,我们可以找到关于内存的信息,通常情况下,内存使用情况会显示在“RES”这一行。
+--------------------------------------------+ | PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND | +--------------------------------------------+ | 5678 0.0 %Cpu(s) 0.3M %mem 567.8M 1024K ? Ss +Sl 0:00.00 grep --color=auto server | +--------------------------------------------+
从输出结果中,我们可以看到进程ID为5678的进程占用了0.3%的CPU和0.3%的内存,这里的“%MEM”列即为该进程占用的内存百分比。
3、使用vmstat
命令
vmstat
命令可以显示虚拟内存统计信息,包括进程、内存、交换空间等方面的数据,使用方法如下:
vmstat -h
-h
选项表示以人类可读的格式显示结果,即自动将字节转换为KB、MB或GB等单位。
输出结果示例:
procs -----------memory------------swap--------------io---------------system-----------------cpu--------- r b n k r/s w/s p pct us sy id wa st cu mi cs hi si st qu dr tc hr tm wa tu vz geo gib mn fx cy id maxrss avgrss sumrss packed nr_inactive nr_active nr_softirq nr_hardirq nr_steal nr_guest nr_guest_nice nr_startup_kernel nr_thp_total nr_thp_idle nr_thp_wait nr_thp_softirq nr_thp_hardirq nr_pagefault nr_pgfault_major nr_pgfault_minor nr_pgfault_short nr_pgfault_major_short nr_fork() nr_exit() nr_vmallocd() nr_pipe() nr_syscall() nr_lookup() nr_remap() nr_poll() nr_nfs() nr_sync() nr_btree() nr_deactivate() nr_finitize() nr_kill() nr_umount() nr_vfsopen() nr_sysctl() nr_setdomainname() nr_iopl() nr_ioperm() nr_processes() intr ctxt btime processes tasks rt_total rt_cputime rt_tasktime rt_cpucycles rt_pagefaults sigpending sigcatch cwnd tcp time tcp connect time tcp send time tcp receive time tcp loss tcp retransmits tcp retransmit time tcp slow start time tcp congestion window tcp timestamp tcp keepalive probes tcp keepalive timeout tcp keepalive interval tcp keepalive max retries tcp keepalive probe retries tcp keepalive max probes tcp keepalive probe interval tcp keepalive interval tcp keepalive max failed udp time udp connect time udp send time udp receive time udp loss udp retransmits udp retransmit time udp congestion window udp timestamp udp keepalive probes udp keepalive timeout udp keepalive interval udp keepalive max retries udp keepalived probe retries udp keepalived max probes udp keepalived probe interval udp keepalived interval udp keepalived max failed unix state (epoll) unix state (inotify) unix state (timerfd) unix state (signalfd) unix state (socketfd) unix state (async-fd) unix state (epoll-event) intr ctxt btime processes tasks rt_total rt_cputime rt_tasktime rt_cpucycles rt_pagefaults sigpending sigcatch cwnd tcp time tcp connect time tcp send time tcp receive time tcp loss tcp retransmits tcp retransmit time tcp slow start time tcp congestion window tcp timestamp tcp keepalive probes tcp keepalive timeout tcp keepalive interval tcp keepalive max retries tcp keepalived probe retries tcp keepalived max probes tcp keepalived probe interval tcp keepalived interval tcp keepalived max failed vmstat 12345678901234567890 Name: procs State: running Tasks(pid): 23456 Name: system State: up Idle CPU(s): 0 Percpu(s): 0 Wchan: 0 Pageflt(): 0 Dirty: 0 Writeback: 0 Inactive: 0 Active(anon): 16684 Active(file): 18924 Active(net): 15464 VmPeak: 298596 kVmHWM: 298596 kVmRSS: 298596 kSwapCached: 0 kSwapTotal: 298596 kSwapFree: 298596 si: 1677 di: 1677 bi: 1677 bo: 1677 nfree: 1677 totfree: 1677 nodemask: 0 netmask: 0 inetaddr: 127.0.0.1 inet6addr: ::1 broadcastaddr: ::1 netmasklen: 32 osdefval: 32 routemask: 0 rpfgenmask: 0 rpfdestmask: 0 rpffailmask: 0 rpfexpiremask: 0 rpfnullmask: 0 rpfnodupmask: 0 rpfoptmask: 0 rpfretmask: 0 rpfretrymask: 0 rpfnobadrmask: 0 rpfbadrmasklen: 32 rcvqueue: 0 rcvbfifowaitcnt: 0 rcvbfifobytesrecvd: 0 rcvbfifomsgsentcnt: 0 rcvbfifobytessent: 0 rcvnetqueuecnt: 0 rcvnetbytesrecvd; rcvnetmsgsentcnt; rcvnetbytessent; rcvwirequeuecnt; rcvwirebytesrecvd; rcvwiremsgsentcnt; rcvwirebytessent; rcvunackdatagramsrecvd; rcvunackdatagramssentcnt; rcvunackdatagramssent; rcvunknownrecvd; rcvunknownsentcnt; rcvunknownsent; rcvinlinequeuecnt; rcvinlinebytesrecvd; rcvinlinemsgsentcnt; rcvinlinebytessent; rcvintrqueuecnt; rcvintrmsgsentcnt; rcvintrbytessent;
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/272398.html