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/loadavg to a logfile?
在Linux机器上,我需要显示上周每小时的平均CPU利用率。这些信息是否记录在某处?或者我是否需要编写一个每15分钟唤醒一次的脚本来将/ proc / loadavg复制到日志文件中?
EDIT: I'm not allowed to use any tools other than those that come with Linux.
编辑:我不允许使用Linux以外的任何工具。
3 个解决方案
#1
12
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)可以为您执行此类操作,并生成漂亮的图表以启动...但它们可能对您的情况有点过分。
#2
25
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:
IBM Developer Works文章中的示例:
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 sysstat package for your linux distro
您通常可以在Linux发行版的sysstat包中找到它
#3
1
I would recommend looking at Multi Router Traffic Grapher (MRTG).
我建议看看多路由器流量图示器(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使用示例。
#1
12
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)可以为您执行此类操作,并生成漂亮的图表以启动...但它们可能对您的情况有点过分。
#2
25
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:
IBM Developer Works文章中的示例:
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 sysstat package for your linux distro
您通常可以在Linux发行版的sysstat包中找到它
#3
1
I would recommend looking at Multi Router Traffic Grapher (MRTG).
我建议看看多路由器流量图示器(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使用示例。