从顶部输出logging前5行 – 服务器冻结

有人可以提供关于如何从顶部输出中logging前5行的提示吗? 我正在考虑grep,但不知道如何挑选行。

我需要了解。 有时会冻结服务器。 也许有一些工具呢?

谢谢 ;)

你可以做你所要求的:

~$ top -n1 | head -5 

除了Janne的命令列表和symcbean的build议来检查你的系统日志之外,我build议在顶部

  ... It shows the occupation of the most critical hardware resources (from a performance point of view) on system level, ie cpu, memory, disk and network. It also shows which processes are responsible for the indicated load with respect to cpu- and memory load on process level. Disk load is shown if per process "storage accounting" is active in the kernel or if the kernel patch `cnt' has been installed. Network load is only shown per process if the kernel patch `cnt' has been installed... [...] Every interval (default: 10 seconds) information is shown about the resource occupation on system level (cpu, memory, disks and network layers), followed by a list of processes which have been active during the last interval (note that all processes that were unchanged during the last interval are not shown, unless the key 'a' has been pressed). If the list of active processes does not entirely fit on the screen, only the top of the list is shown (sorted in order of activity). 

此外,您可以及时向后检查这是您的服务器的情况,因为它将数据存储在它的日志文件中。 例如,在服务器loadavg传递任意限制时启动的脚本中有以下代码片段。 顶层信息和其他相关系统信息通过邮件发送到我的帐户:

 atop -r /var/log/atop.log -M -b "$(date +'%H:%M' -d '30 minutes ago')" -e "$(date -d now +'%H:%M')" 

基本上我会得到服务器实际状态的报告,以及过去30分钟内发生的情况(每隔10分钟的详细信息)

首先,服务器冻结不太可能是由用户进程造成的。 其次,即使是这样,为什么会成为造成这个问题的前五名之一呢?

如果你已经检查了日志并没有发现任何东西,那就试着用一个看门狗为日志写一个心跳,然后检查系统是否真的冻结了(而不是被远程访问时被认为是暂停的)。

冻结多长时间? 多频繁? 回来的时候是否有负载? 你在哪里观察这些冻结? 这是专用还是虚拟机?

top | head -n 12 >>your_file.txt top | head -n 12 >>your_file.txt可以做到这一点,但是有一些注意事项:它会保存所有的控制字符和ANSI字符,所以用less浏览器输出不会很好。 而且,说实话,这不是抓反叛进程的最好方法。

对于有关服务器性能工具(如snmp + mrtg)的整体趋势 ,Cacti或Munin可能非常有用 – 它们描绘了CPU使用情况,内存使用情况等。 对于命令行,使用带有sadc守护进程和sar reporting实用程序的sysstat软件包也可以为您提供有关您的服务器如何执行的视图。 psacct软件包添加了BSD会计,并可以为您提供有关每个用户/处理时间花费的总体统计信息。

对于实时查看只需保持login在您的服务器上,并遵循像iostat -x 1vmstattop

考虑设置一个单独的系统日志服务器如果您有备用硬件(或已安装中央系统日志服务器),请使用它! 您只需configuration您的服务器,将其系统日志和其他日志发送到您的系统日志服务器。 有时候这些冻结(如果是由于内核恐慌引起的)可能会发生,所以你的服务器不能把信息写到磁盘上,但是可以把最后的单词发送给系统日志服务器。

用memtest86testing你的服务器,如果你可以让你的服务器离线一个晚上左右,让它运行memtest86 ,看它是否有错误的内存或其他东西。

对不起,我不能比这更有帮助,因为你实际上没有告诉我们有关你的问题。