Linux 显示上周的平均 CPU 负载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/531212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux display average CPU load for last week
提问by thornate
On a Linux box, I need to display the average CPU utilisation per hour for the last week. Is that information logged somewhere? Or do I need to write a script that wakes up every 15 minutes to copy /proc/loadavgto a logfile?
在 Linux 机器上,我需要显示上周的平均 CPU 利用率。该信息是否记录在某处?或者我是否需要编写一个脚本,每 15 分钟唤醒一次以将/proc/loadavg复制 到日志文件?
EDIT: I'm not allowed to use any tools other than those that come with Linux.
编辑:除了 Linux 附带的工具之外,我不允许使用任何工具。
采纳答案by David Z
As far as I know it's not stored anywhere... It's a trivial thing to write, anyway. Just add something like
据我所知,它没有存储在任何地方......无论如何,这是一件微不足道的事情。只需添加类似的东西
cat /proc/loadavg >> /var/log/loads
to your crontab
.
到您的crontab
.
Note that there are monitoring tools (like Munin) which can do this kind of thing for you, and generate pretty graphs of it to boot... they might be overkill for your situation though.
请注意,有一些监控工具(如Munin)可以为您做这种事情,并生成漂亮的图表来启动……不过,对于您的情况,它们可能有点矫枉过正。
回答by Brian Gianforcaro
You might want to check out sar(man page), it fits your use case nicely.
您可能想查看sar(手册页),它非常适合您的用例。
System Activity Reporter (SAR)- capture important system performance metrics at periodic intervals.
系统活动报告器 (SAR)- 定期捕获重要的系统性能指标。
Example from IBM Developer Works Article:
Add an entry to your root crontab
将条目添加到您的根 crontab
# Collect measurements at 10-minute intervals
0,10,20,30,40,50 * * * * /usr/lib/sa/sa1
# Create daily reports and purge old files
0 0 * * * /usr/lib/sa/sa2 -A
Then you can simply query this information using a sar command (display all of today's info):
然后您可以使用 sar 命令简单地查询此信息(显示所有今天的信息):
root ~ # sar -A
Or just for a certain days log file:
或仅针对某天的日志文件:
root ~ # sar -f /var/log/sa/sa16
You can usually find it in the sysstatpackage for your linux distro
你通常可以在你的 linux 发行版的sysstat包中找到它
回答by cmcginty
I would recommend looking at Multi Router Traffic Grapher (MRTG).
我建议查看Multi Router Traffic Grapher (MRTG)。
Using snmpd to read the load average, it will automatically calculate averages at any time interval and length, along with nice charts for analysis.
使用 snmpd 读取负载平均值,它将自动计算任何时间间隔和长度的平均值,以及用于分析的漂亮图表。
Someone has already posted a CPU usage example.
有人已经发布了一个CPU 使用示例。