从/proc收集的Linux显示系统统计信息

时间:2020-01-09 10:41:30  来源:igfitidea点击:

如何显示来自/proc的信息,例如内存,平均负载,正常运行时间,页面活动,上下文,磁盘状态,使用Shell或Perl脚本的中断?
您可以编写一个shell或perl脚本来从/proc文件系统中获取所有信息。
但是Linux带有procinfo命令来从/proc目录中收集一些系统数据,并在屏幕上很好地打印格式。

安装procinfo命令

打开命令行终端(选择应用程序>附件>终端),然后在Debian或Ubuntu Linux下执行以下命令:

$ sudo apt-get update

$ sudo apt-get install procinfo

使用apt-get update命令告诉apt通过查询配置的存储库来刷新其软件包信息,然后安装procinfo软件包。
如果您使用的是CentOS/RHEL/Fedora/Redhat Linux,请执行:

# yum install procinfo

如何使用procinfo命令?

只需执行以下命令,执行:

# procinfo

procinfo显示从/proc收集的系统统计信息

其中,显示的信息是:

  • `Memory':显示系统中的可用和已用内存量
  • Bootup:系统启动的时间。
  • Load average平均负载:正在运行的平均作业数,然后是可运行进程数和进程总数,最后是最后运行的进程的PID。最后运行的进程的pid可能始终是procinfos PID。
  • user:在用户空间中运行作业所花费的时间。
  • " nice":在用户空间中运行精细作业所花费的时间。
  • system:在内核空间中运行所花费的时间。注意:内核不计算服务中断所花费的时间(procinfo对此无能为力)。
  • idle:无所事事的时间。
  • uptime:系统启动的时间。以上四个应该或多或少地加在一起。
  • " page in":从磁盘分页到核心的磁盘块数。 1块等于1 kiB。
  • " page out":从内核到磁盘分页的磁盘块数。这包括常规的磁盘写入。
  • " swap in":交换中分页的内存页数。
  • " swap out":调出要交换的内存页数。
  • context:自启动以来或每个时间间隔的上下文切换次数。
  • 磁盘统计信息(sda,hda,sdb等):对磁盘的读写次数,无论是CD-ROM,硬盘驱动器还是USB。显示所有磁盘,如果它们是hdX或sdX,或者它们的读/写计数为非零。
  • Interrupts:自启动以来或每个时间间隔内,每个IRQ列出的服务中断数。

连续全屏运行procinfo

-f选项可以在屏幕上连续运行procinfo,默认值为更新之间的5秒。

-n选项可用于设置暂停更新时间。
在此示例中,procinfo将在更新之间暂停20秒:

# procinfo -f -n 20

您可以通过按d,D,S,r,b和q来更改其行为,切换标记会退出程序。
这些标志还对应于它们的同名命令行选项

-d     For memory, CPU times, paging, swapping, disk, context and interrupt stats, display values per second rather than totals. This option implies -f.

       -D     Same as -d, except that memory stats are displayed as totals.

       -S     When running with -d or -D, always show values per second, even when running with -n N with N greater than one second.

       -b     Display numbers of bytes rather than number of I/O requests.

       -r     This option adds an extra line to the memory info showing 'real' free memory, just as free(1) does. The numbers produced assume that Buffers and Cache are disposable.