2

I've been given a task to break apart the services on one of our main VMs (Amazon EC2) and appropriate additional VMs to suit the services needs.

The type of services that I am dealing with are mostly php cronjobs, that coincide with our web application. They are resource and IO heavy, thus the need to offload them elsewhere.

These jobs do not have consistent PIDs, they spark in and out of existence as needed, so something like "grepping" for the args output from ps is the only way I can think of to store this data. In other words, what is consistent is grepping for the the process like so: ps -eo pid,pcpu,%mem,vsize,args | grep "php[ ]/path/to/script.php" However, some of the processes only run for a few seconds and then die.

The goal is that I need to get a handle on how to best provision VMs based on the resources these processes are actually using, in order to save money.

To quote: "Estimate the server usage based on a 1 week average"

Mike
  • 21
  • 1

1 Answers1

0

Honestly the request sounds a bit suspicious to me. Can't you just move things and see what load is like on the new system? That being said, onto your actual issue.

You need to find out the resource usage of processes (and not the whole system).

Option 1:
You can actually launch the processes with some sort of profiler or tracing tool (i.e. perf and strace, and get pretty accurate data. This could be a lot of work, and is probably over kill for estimating the aggregate of a bunch of processes.

Option 2:
Capture data about the processes shortly after launching it using the counters the kernel provides per processes. These can be found under /proc/<pid>/.... More likely you will want to use a tool like pidstat to gather this data for you. For example:

[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

$! in bash captures the pid of the last run job (find in this example). So you could wrap your cron jobs in a script like this, record the data to disk, and then analyze it with excel, R, or pandas.

Kyle Brandt
  • 82,107
  • 71
  • 302
  • 444