Freebsd – CPU usage command for monitor script

central-processing-unitfreebsdmonitoringunix

Is there a command for FreeBSD (except the top -P) I could use to monitor my dedicated server CPU usage? I am in progress of writting my bash script which will notify me as soon as any of the CPU core will be reaching 100% usage.

Thats why I need some other command than top -P because it takes some time for the top to calculate the usage on the first run and than wouldnt work for per usage command.

Best Answer

CPU load information can be obtained in shell script from sysctl kern.cp_times. This is commulative counters, and to get load in % you need derivative, e. g. get kern.cp_times with 1 minute interval and divide counters by 60.

But more easy to use existing monitoring systems like Nagios (there are many monitoring systems, but no perfect and I can't suggest best system).

Related Topic