mpstat

  • english
  • spanish

One of the most basic variables to monitor on a system is CPU usage, something we usually do interactively with top or with vmstat when we want to script the process.

But there’s a problem with multi-CPU systems, with either physical or virtual CPUs, because in these cases vmstat shows the average usage across all CPUs. Depending on the software or hardware architecture, a CPU at 100% can become a bottleneck and produce process blockings ever if the other CPUs are completely idle, while vmstat would show us just a 50% CPU usage. This is quite typical with single CPU systems with HyperThreading technology.

An alternative to vmstat for these situations is mpstat, from the sysstat package, that shows the individual per-CPU usage rates. Very useful when writing a script for displaying graphs with Cacti or raising alarms with Nagios.

# mpstat -P ALL
Linux 2.6.9-023stab046.2-enterprise (domain.com) 	25/09/08
20:39:02     CPU   %user   %nice %system %iowait    %irq   %soft   %idle    intr/s
20:39:02     all    0,79    0,00    0,17    5,74    0,00    0,00   93,30      0,00
20:39:02       0    0,87    0,01    0,19    6,85    0,00    0,00   92,09      0,00
20:39:02       1    0,87    0,00    0,18    5,94    0,00    0,00   93,00      0,00
20:39:02       2    0,74    0,00    0,16    5,14    0,00    0,00   93,96      0,00
20:39:02       3    0,68    0,00    0,16    5,02    0,00    0,00   94,15      0,00

Picos de CPU raros en Leopard

  • english
  • spanish

I was quite upset since yesterday because of this: a little while after booting my MacBook, CPU load went up over 50%, always. It was easy to detect because, besides the system being less responsive, FanControl put the fans over 5000rpm which makes a lot of noise.

The “Activity Monitor” showed that one of the two cores was always running at 100% and the other had the usual load, so the average was around 55-60%. However, none of the tasks on the task list table was over 4-6% CPU. No idea who was to blame.

I tried removing every gadget I had (like Growl, iScrobbler, InsomniaX…) from the start-up items, even rebooting and logging in with a “clean”, new user. Just the same.

Today I’ve tried directly with the terminal, and with ps have discovered that syslog was running at 100% CPU, so I knew where to look: on /var/log, the last system.log was over 250Mb while the previous ones (after bunzip2-ing) weighted less than 10Mb each. The file was full with AppFresh’s errors, not that important but they had this nasty side-effect. After killing syslogd CPU levels went back to normal, but the system re-launched it and CPU use spiked again. Removing the last system.log file wouldn’t solve the problem, either.

So with a clearer idea of what was going on I googled about it and found this post with a comment that suggested lowering the max allowed size for the asl.db file (mine was almost 50Mb). I’ve followed these instructions, killed syslogd again, and problem solved! My MacBook is as silent and resonsive as before. :)