栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

个人日常linux常用命令(一)查看进程和磁盘使用情况

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

个人日常linux常用命令(一)查看进程和磁盘使用情况

本人在排查问题是最常见的就是磁盘使用问题和进程启动参数、cpu以及内存使用率。将个人最常使用命令的记录下来,方便日常查看。
备注:这是仅仅是记录个人最常使用的命令, 并未对linux排查进程和磁盘问题进行深入和全面的总结。 仅供个人使用参考而已。

1, 进程信息 1.1 查看进程启动信息

pid、lstart、 etime之间没有空格, 该命令适合知道进程程序命令,查询pid, 启动时间,已经运行市场,占用cpu时间,启动参数信息

ps -eo pid,lstart,etime,time,cmd |grep nginx 


启动etime的具体含义可以通过man ps |grep etime查看具体含义以及输出格式信息

#man ps |grep etime
       CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process.  This is not ideal, and it does not conform to the standards that ps
       %t     etime    ELAPSED
                             partly dead, waiting to be fully destroyed by its parent.  Sometimes the process args will be unavailable; when this happens, ps will instead print the executable name
       c           C         processor utilization. Currently, this is the integer value of the percent usage over the lifetime of the process.  (see %cpu).
       etime       ELAPSED   elapsed time since the process was started, in the form [[DD-]hh:]mm:ss.
       etimes      ELAPSED   elapsed time since the process was started, in seconds.```
2.2 按照内存使用率排序

ps aux --sort=-%mem |head -n 30
只显示使用内存较高的前30个进程

2, 磁盘使用情况

主要查看磁盘空间使用率和磁盘inode使用率, 因为任意一个使用率超过85%都会引起k8s的image gc问题(具体k8s如何判断磁盘使用率参考k8s问题,这里不赘述)。

2.1 空间使用率

用df -h命令查看了一下磁盘空间使用情况

df -i查看了一下分区的索引节点(inode)使用情况

2.3 查询占用空间最大的目录

du --max-depth=1 -h|sort -hr

#du --max-depth=1 -h|sort -hr
du: cannot access ‘./proc/93817’: No such file or directory
du: cannot access ‘./proc/122934/task/122934/fd/4’: No such file or directory
du: cannot access ‘./proc/122934/task/122934/fdinfo/4’: No such file or directory
du: cannot access ‘./proc/122934/fd/4’: No such file or directory
du: cannot access ‘./proc/122934/fdinfo/4’: No such file or directory
du: cannot access ‘./proc/122936’: No such file or directory
du: cannot access ‘./proc/122958’: No such file or directory
du: cannot access ‘./proc/122960’: No such file or directory
du: cannot access ‘./proc/122961’: No such file or directory341G    .
199G    ./dir1
133G    ./var
3.8G    ./usr
2.8G    ./home
1.5G    ./dir2
1.2G    ./root
513M    ./opt
96M     ./boot
37M     ./etc
6.3M    ./run
3.4M    ./data
616K    ./tmp
16K     ./lost+found
4.0K    ./srv
4.0K    ./mnt
4.0K    ./media
4.0K    ./dir1mount
4.0K    ./dev
0       ./sys
0       ./proc

可以返现/dir1占用空间最大(这里需要区分一下/dir1目录占用的是哪个磁盘的空间,在我本机上有3块磁盘 /dev/vda1 /dev/vdb. /dev/vdc. 升级上dir1在/dev/vdb磁盘的, /dev/dba1是os的根目录, 因此如果包磁盘根目录满了,清理/dir1是无效的,因为他不占用根目录的空间, 命令df -h会显示相关目录和磁盘的信息)

然后可以再次进入最大的占用空间的目录, /dir1继续查看到底谁占用空间最大,再决定清理那个文件

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/345650.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号