5

There are a number of questions on this StackExchange about memory consumption, notably:

  1. How to check which process is using most memory
  2. How to display top results sorted by memory usage in real time?
  3. How to find which processes are taking all the memory?

However, all of them seem to be driving at what's using the most memory right now. I'd like to have a workflow that tells me what's using the most memory (or perhaps the top 3 to 4 processes) over a period of time (e.g. 1 hour, 12 hours).

Is there a way to accomplish this with top, htop or something else?

blong
  • 209
  • 1
    Have you seen the answer here? – user1717828 Sep 14 '15 at 14:38
  • I like that answer (it's small and elegant), but I'm looking for something that will identify specific processes. For example, is the memory hog my HTTP server? Database? Other service? Any thoughts @user1717828 ? – blong Sep 14 '15 at 15:20
  • I haven't put together a full answer, but tell me if this idea is good to get you started: run ps aux k -%mem to see a list of processes sorted by memory, then pipe it in awk '{print $2,$3}' to see just the PID and memory consumption. Put all that into a log file like the linked solution: while true; do ps aux k -%mem | awk '{print $2,$3}' >> memory.log; sleep 1; done. After a few hours you'll have an enormous text file which you can parse to bin the consumptions for different processes. Sorry this comment is so long, but I don't have time to write the parse program right now. – user1717828 Sep 14 '15 at 15:40
  • Cacti is a nice tool that allows you to monitor memory usage over time and under a variety of circumstances. Cacti requires some effort to configure, but its graphing capability may be of use to you. – marshki Sep 14 '15 at 18:58
  • @marshki Cacti seems nice (it's open source), but at the moment I'm looking for a command-line solution. If anyone else is interested in Cacti, the source appears to live here: http://sourceforge.net/projects/cacti/ – blong Sep 16 '15 at 17:54
  • @user1717828 Yes, that's a great start. Thank you! Of course, I'll want to capture the command name too ( ... awk '{print $11}' ). Whichever one of us get's to tinker with this first (I might get a chance in an hour or so), we should post this as the answer :) – blong Sep 16 '15 at 17:55
  • @blong challenge *accepted* – user1717828 Sep 16 '15 at 19:17

0 Answers0