I'm currently using top to gather the most resource intensive processes and sending them to influxdb. Currently, the command is like this:
top -bn1 -c -w250
Which basically runs top a single time (-bn1), with the full name of the command (-c) and without truncating (width 250). I run this every 15 seconds and process each output with a script.
However, I've noticed that running top itself like that is getting quite heavy. It's frequently the most intensive process. I suspect the reason for that is because since it gets terminated and restarts from zero every 15 seconds, it probably has to reload many things it only needs when starting up. That would explain why its CPU consumption drops considerably on the following iterations when executed during interactive mode.
So I tried to run it continuously in batch mode (removing -n1 argument) and storing the output in a file. But the file is getting huge, because it's not being overwritten at each iteration (instead, each output is being appended). Is it possible to store only the last iteration's output while not terminating the program?
My current attempt:
top -bc -d15 -w250 > /var/log/top.log

ps auxwwwto dump all processes since you didn't state your purpose?topshows itself quite high in the top not only during start, I can state this as someone who had used it a lot during a career. Well, collecting statistics takes CPU time too, as well as presenting it to the user. What I don't understand is why you are sticking to top? Why notsaroratopwhich are designed to record the usage trace and then present the load state of a machine as historical information which you can walk to see "what happened" then. Why not filterps(like,ps -eo %cpu,etimes,command | awk '$1 > 5.0 {OFS=","; print $1,$2,$3 }'(5.0 is a lowest percent to show)?