TransWikia.com

Collect data on CPU usage per core at regular time intervals?

Ask Different Asked on November 17, 2021

Is there any easy way to get CPU usage on a per core basis at a certain interval throughout the day? (e.g. every 60 seconds)

Notes

  • happy to use a script (e.g. ruby, python) and run it in the terminal
  • would be great if the output were a simple csv, but open to using more sophisticated tools/outputs if they exist and are easy to use
  • the ultimate goal is to take to plot a time series of per-core utilisation over the day (or week/month) (that is, a line chart with as many lines as cores)
  • The answer on Get cpu usage per core on the command line can’t be used in a loop

Example output:

A csv that resembles:

time, core_1, core_2, core_3, core_4 (etc)
"2020-07-18 15:45:00 UTC", 15%, 12%, 0%, 1%
"2020-07-18 15:46:00 UTC", 100%, 100%, 10%, 3%
"2020-07-18 15:47:00 UTC", 10%, 2%, 0%, 0%
etc etc

One Answer

There is a tool that can collect this information called glances, which is a command line based monitoring tool that can track all sorts of parameters.

It can be installed via homebrew:

brew install glances

You may need to tinker with the options to get something you're happy with, or parse the data downstream with a different tool, but it can output timestamped, percpu usage (in 60 second intervals) in the following way:

glances --stdout now,percpu --time 60

The results aren't quite what you outlined, but the output can be processed with other tools to get them into a format that you can use.

Answered by Scot on November 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP