我已经获得了一项任务来分解我们的主要虚拟机(Amazon EC2)之一的服务以及适当的额外虚拟机以满足服务需求。
我正在处理的服务types主要是php cronjobs,这与我们的Web应用程序一致。 它们是资源和IO的重量,因此需要把它们转移到其他地方。
这些作业没有一致的PID,它们根据需要进入和退出,所以像从ps输出的参数“grepping”是我能想到的唯一方法来存储这些数据。 换句话说,什么是一致的ps -eo pid,pcpu,%mem,vsize,args | grep "php[ ]/path/to/script.php"的过程是这样的: ps -eo pid,pcpu,%mem,vsize,args | grep "php[ ]/path/to/script.php" ps -eo pid,pcpu,%mem,vsize,args | grep "php[ ]/path/to/script.php"然而,一些进程只运行了几秒钟,然后死亡。
目标是我需要掌握如何基于这些stream程实际使用的资源最佳地configuration虚拟机,以节省资金。
引用:“基于1周平均值估计服务器使用率”
诚实的要求听起来有点可疑。 难道你不能移动的东西,看看新系统上的负载是什么样的? 这就是说,到你的实际问题。
你需要找出进程(而不是整个系统)的资源使用情况。
选项1:
实际上你可以用某种分析器或者跟踪工具来启动进程(比如perf和strace ,并且获得非常准确的数据,这可能是很多的工作,而且可能是为了估计一大堆进程的集合而被杀死的。
选项2:
使用内核为每个进程提供的计数器在启动进程之后不久捕获有关进程的数据。 这些可以在/proc/<pid>/... 。 更有可能你会想使用像pidstat这样的工具来为你收集这些数据。 例如:
[root@ny-kbrandt01 ~]# find / -iname '*' 2>&1 > /dev/null & pidstat -p $! -d -r -u -h 1 [1] 18736 Linux 2.6.32-431.el6.x86_64 (ny-kbrandt01.ds.stackexchange.com) 12/02/2014 _x86_64_ (4 CPU) # Time PID %usr %system %guest %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s Command 1417486738 18736 1.00 2.00 0.00 3.00 3 360.00 8.00 112268 1236 0.02 4592.00 0.00 0.00 find # Time PID %usr %system %guest %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s Command 1417486739 18736 1.00 3.00 0.00 4.00 2 241.00 0.00 112268 1240 0.02 4224.00 0.00 0.00 find # Time PID %usr %system %guest %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s Command 1417486740 18736 1.00 3.00 0.00 4.00 3 0.00 0.00 112268 1240 0.02 5192.00 0.00 0.00 find # Time PID %usr %system %guest %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s Command 1417486741 18736 1.00 6.00 0.00 7.00 2 46.00 0.00 112400 1284 0.02 5464.00 0.00 0.00 find # Time PID %usr %system %guest %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s Command 1417486742 18736 2.00 5.00 0.00 7.00 2 0.00 0.00 112268 1240 0.02 6892.00 0.00 0.00 find # Time PID %usr %system %guest %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s Command 1417486743 18736 3.00 7.00 0.00 10.00 2 62.00 0.00 112268 1244 0.02 8170.00 0.00 0.00 find
$! 在bash中捕获最后一个运行作业的pid(在这个例子中find)。 所以你可以把你的cron作业包装在这样的脚本中,将数据logging到磁盘上,然后用excel,R或pandas进行分析。