How to monitor CPU usage on Linux

What is the best way to monitor current and past CPU usage on Linux. Say I wanted to see CPU usage from last 7 days. How do I see that on Linux?

Monitoring current CPU usage on Linux

We use either top or htop

sudo top
# not installed by default #
sudo htop
sudo atop
1 Like

Apart from top/htop we can use the following tools:

top

1. mpstat - Report processors related statistics

mpstat
mpstat -P ALL

2. sar command

You need to install and use the sar command when you need to keep historical data on system resources. See

3. iostat command

Report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions:

iostat

See

And

1 Like

Is there any modern alternative to sar and kSar?

  • Try nmon if you do not want sar nmon for Linux | Main / HomePage
  • Sar is default and can create pretty graphics too GitHub - sysstat/sysstat: Performance monitoring tools for Linux
  • collectd – The system statistics collection daemon https://collectd.org/
    graph-cpu
  • Collectl http://collectl.sourceforge.net/
  • Graphite is an enterprise-ready monitoring tool that runs equally well on cheap hardware or Cloud infrastructure. Teams use Graphite to track the performance of their websites, applications, business services, and networked servers. It marked the start of a new generation of monitoring tools, making it easier than ever to store, retrieve, share, and visualize time-series data. https://graphiteapp.org/
  • Ganglia is a scalable distributed monitoring system for high-performance computing systems such as clusters and Grids. http://ganglia.info/
  • Munin is a networked resource monitoring tool that can help analyze resource trends and β€œwhat just happened to kill our performance?” problems. It is designed to be very plug and play. A default installation provides a lot of graphs with almost no work. http://munin-monitoring.org/
  • Cacti is a complete network graphing solution designed to harness the power of RRDTool’s data storage and graphing functionality. Cacti provides a fast poller, advanced graph templating, multiple data acquisition methods, and user management features out of the box. All of this is wrapped in an intuitive, easy to use interface that makes sense for LAN-sized installations up to complex networks with thousands of devices. https://www.cacti.net/
1 Like

Wow so many options. it is going to take much time to learn one good system. I appreciate sharing all wonderful tools.


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki