Linux 将 VMStat 数据记录到文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11294611/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 07:12:19  来源:igfitidea点击:

Logging VMStat data to file

linuxunix

提问by Sutty1000

I am trying to create some capacity planning reports and one of the requrements is to have info on Memory usage for a few Unix Servers.

我正在尝试创建一些容量规划报告,其中一项要求是了解一些 Unix 服务器的内存使用情况。

Now my knowledge of Unix is very low. I usually just log on and run a few scripts.

现在我对Unix的了解非常少。我通常只是登录并运行一些脚本。

But for this report I need to gather VMStat data and produce reports based on previous the previous weeks data broken down by hour which is an average of Vmstat data taken every 10 seconds.

但是对于这份报告,我需要收集 VMStat 数据并根据前几周按小时细分的数据生成报告,该数据是每 10 秒获取的 Vmstat 数据的平均值。

So first question: is VMStat logging on by default and if so what location on the server is the data output to?

所以第一个问题:VMStat 是否默认登录,如果是,则数据输出到服务器上的哪个位置?

If not how can I set this up?

如果不是,我该如何设置?

Thanks

谢谢

采纳答案by jim mcnamara

vmstatis a command that you run.

vmstat是您运行的命令。

To generate one week of Virtual Memory stats spaced out at ten second intervals (less the last one) is 60,479 10 second intervals

生成以 10 秒间隔(减去最后一个)间隔的一周的虚拟内存统计数据是 60,479 10 秒间隔

So the command you want is:

所以你想要的命令是:

nohup vmstat 10 604879 > myvmstatfile.dat &

This will make a very big file myvmstatfile.dat

这将生成一个非常大的文件 myvmstatfile.dat

EDIT: RobKielty (The &will put this job in the background, the nohupwill prevent the task from hanging up when you logout of the command shell. If you ran this command it would be prudent to monitor the disk partition to which this file was being written to. Use df -h /path/to/directory/where/outputfile/residesto monitor the disk space usage.)

编辑:RobKielty(&将把这个工作放在后台,nohup当你从命令外壳注销时将防止任务挂起。如果你运行这个命令,最好监视这个文件正在写入的磁盘分区to。df -h /path/to/directory/where/outputfile/resides用于监控磁盘空间使用情况。)

I have no idea what you need to do with the data, so I can't help you there.

我不知道你需要用这些数据做什么,所以我不能帮你。

Create a crontabentry (crontab -e) like this

像这样创建一个crontab条目 (crontab -e)

0 0 * * 0  /path/to/my/vmstat_script.sh 

The file vmstat_script.shwill contain the the follow bash script commands.

该文件vmstat_script.sh将包含以下 bash 脚本命令。

#!/bin/bash
# vmstat_script.sh
vmstat 10 604879 > myvmstatfile.dat
mv myvmstatfile.dat myvmstatfile.dat.`date +%Y-%m-%d`

This will create one file per week with a name like myvmstatfile.dat.2012-07-01

这将每周创建一个文件,名称如下 myvmstatfile.dat.2012-07-01

回答by Gaurav Pandey

The command I use for monitoring the Linux vm metrics is below: nohup vmstat 10 720| (while read; do echo "$(date +%d-%m-%Y" "%H:%M:%S) $REPLY"; done) >> nameofLogfile.log

我用于监控 Linux vm 指标的命令如下: nohup vmstat 10 720| (读取时;执行 echo "$(date +%d-%m-%Y" "%H:%M:%S) $REPLY"; done) >> nameofLogfile.log

Here nohup is used for running the process in background. It will run for 2 hours with interval of 10 secs. This is the best command for generating graphs and reports as timestamp will also be included in logs along with different metrics, so that we can filter the logs accordingly.

这里 nohup 用于在后台运行进程。它将以 10 秒的间隔运行 2 小时。这是生成图表和报告的最佳命令,因为时间戳也将与不同的指标一起包含在日志中,以便我们可以相应地过滤日志。