How can I can log cpu spikes?

I will be running a custom daemon that could potentially spike the server's cpu? Is there a way to log those spikes with their start and running time?


If youre running linux or other unix variant, there is sar which is installed by default in many distributions. Many times it runs from cron on a defined interval, however you can also run it manually with a specified polling interval

For example:

sar -u 1 0

This will run sar once a second forever. The -u tells it to output the CPU usage info, the 1 is how many seconds between polls, and the 0 is how many times to poll (0 for forever).

It can also watch a specific process with the -x parameter. It can also log its data to a file for later viewing. Sar can do a lot, so consult the man page if you want to do more.


Use any monitoring system(Cacti,Zabbix,Munin,...) for monitoring daemon memory usage.