I need CPU utilization for each core. I want text-based output in the terminal. htop technically contains the information I need, but the output is not suitable for my use case as I need to pipe the output to another command for parsing. Is there a way to get this information in a more machine-readable text format?

EDIT: Any well known format would be nice, e.g. CSV/TSV, JSON, XML. Or something simple would be perfectly fine, like newline-delimited lines. Just something I can easily parse. I can possibly parse the htop output, as it is text. However, that feels wrong because it's sort of "graphical" looking and I can't be sure future versions won't change the look.

  • Hi Andy, welcome to Ask Different. Could you be more precise on what kind of "more machine-readable" text format you need?
    – jaume
    Jun 11 '20 at 9:45

There are ways to get this information from htop, but they basically involve screen scraping, as it is designed primarily for interactive use.

Instead, check out the glances command-line tool, which can do what you want.

It can be installed via homebrew:

brew install glances

Something like the following may work for you:

glances --stdout now,percpu --time 10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .