Re: Option for machine-readable output (e.g. JSON) from top?

"Craig Small" <[email protected]> ("csmall") Tue, 4 Jun 2024 20:29:50 +1000
Newsgroups gmane.linux.procps.devel
Message-ID <CALy8Cw7L4Y-e_9ER6uQgQV_Yh4hVqGBQ6t1qwPGQNBUJvmE9dw@mail.gmail.com>
On Mon, 3 Jun 2024 at 02:08, Andy Fingerhut <[email protected]> wrot=
e:
> If top had an option to output in an easily-machine-readable format, e.g.=
 JSON data, and in that JSON data the numeric values were always in a consi=
stent unit, e.g. resident memory was always in KiBytes or MiBytes, with no =
suffix for a unit, then the output would be much easier to consume by other=
 programs.
>
> Does an open source program like this exist already, and I simply haven't=
 been able to find it in my recent searches?
I don't know of anything that does this.

> Would this be reasonable to consider for a future version of top?  Or wou=
ld that be considered to be outside of its scope, and a different program w=
ould be better suited for such a task?
It would be problematic to do that in top. It has a lot of ncurses
screens and the updates are controlled by it, not by the consuming
process.
The output is also "ncurses-like" e.g. it has the concept of location.

It also depends on what information you're trying to get; is it the
top window summary or the bottom window process detail?

So the broad idea of having something that is easy machine-readable is
a good one, but top isn't the right place.

For process information, ps would be a better option. I've been
considering adding an option to add a printf like option. A JSON
output format is do-able but is some work.

 - Craig