14

Is there a script that will show memory usage as a graph, for example as a pie-chart, with each process being being a separate slice?

I'm not looking for something like Munin to graph memory usage over time, but rather show the memory usage per-process at a single point in time.

To make my request even more obscure, it is for a headless server (so no X applications). The simplest way would be to write a PNG file, or possibly an HTML file (which could use Javascript to allow the filtering of processes, changing between graph-types and so on)

Sam Cogan
  • 38,158
  • 6
  • 77
  • 113
dbr
  • 1,538
  • 3
  • 16
  • 18

13 Answers13

13

Per process memory accounting is tricky for a number of reasons I'll get into in a minute. For simple monitoring, gkrellmd, or nagios scripts is probably enough. If you want greater accuracy, you'll need to look harder.

smem introduces the concept of Proportional Set Size:

Because large portions of physical memory are typically shared among multiple applications, the standard measure of memory usage known as resident set size (RSS) will significantly overestimate memory usage. PSS instead measures each application's "fair share" of each shared area to give a realistic measure.

Example: You start up GNOME, causing a number of processes to start, one for each applet and program. They all link to libglib. Linux loads libglib into one block of memory and maps it into every process that wants libglib. Naive memory accounting counts the full libglib size against every process linking to it.

smem divides up the cost of libglib among the processes using it, to give a closer picture of reality. It also has a number of options to display memory usage (from website):

  1. Show basic process information smem
  2. Show system view smem -R 4G -K /path/to/vmlinux -w
  3. Show totals and percentages smem -t -p
  4. Show different columns smem -c "name user pss"
  5. Show processes filtered by mapping smem -M libxml
  6. Show mappings filtered by process smem -m -P [e]volution
  7. Read data from capture tarball smem --source capture.tar.gz
  8. Show a bar chart labeled by pid smem --bar pid -c "pss uss"
  9. Show a pie chart of RSS labeled by name smem --pie name -s rss

You will, however, need a very recent kernel (> 2.6.27).

jldugger
  • 14,122
  • 19
  • 73
  • 129
5

Can't think of anything off the shelf

however, a combo of a PHP script exec'ing ps -AH v | awk '{ print $8,$9,$10}' and using that with pChart could give you a web page that would do what you are looking for? (usage in Kb, percentage of total and process name)

Adam Gibbins
  • 7,147
  • 2
  • 28
  • 42
Mark Regensberg
  • 1,421
  • 12
  • 14
2

Have a look at sarface - it depends on sar data, and you can monitor your memory usage (and all other sar/sysstat data) live.

Xerxes
  • 4,133
  • 3
  • 26
  • 33
1

and what about collectd ?

jnrg
  • 269
  • 1
  • 6
1

Do it yourself. Make a simple shell script updating RRD database. Then draw a graph using rrdtool.

1

If you're really into lower levels of detail, don't forget collectl. Here's an example of the types of per process memory utilization it can report:

RECORD    1      cag-dl585-02     (1244758290.002) (Thu Jun 11 18:11:30 2009)

PROCESS SUMMARY (counters are /sec)
# PID  User     S VmSize  VmLck  VmRSS VmData  VmStk  VmExe  VmLib MajF MinF Command
 9089  root     S 66856K      0  2328K  1440K   212K   736K  6812K    0    0 sendmail:
 9097  smmsp    S 57600K      0  1772K  1304K   204K   736K  5904K    0    0 sendmail:
 9108  root     S  6428K      0   360K   180K    84K    88K  1944K    0    0 gpm
 9120  root     S 74808K      0  1136K   476K   520K    48K  1920K    0    0 crond
 9173  xfs      S 20904K      0  1828K  1124K    88K   104K  3084K    0    0 xfs

If you're interested in specific processes you can specify appropriate filters (including a switch to show threads).

And if you interested in memory in general it also can show slab detail and even has a vmstat format output. Why would you want to show data in vmstat format when the existing tool already does that? That's easy - with collectly you can log stats to a file and play it back later in multiple formats.

try it, you'll like it

Jeff Atwood
  • 12,994
  • 20
  • 74
  • 92
1
  1. Grep the process(s).
  2. Parse the output and save in comma separated format in a text file.
  3. open the comma separated file in excel.
  4. Draw the graph for that data using the chart utility of excel.

If you want memory snapshots at different time interval... set the cron job at desired interval and run the script.

hope that helps....

Jeff Atwood
  • 12,994
  • 20
  • 74
  • 92
0

Doesn't phpsysinfo give you the ability to see process info somehow?

djangofan
  • 4,172
  • 10
  • 45
  • 59
0

You can use #top or #sysstat

Rajat
  • 3,329
  • 21
  • 29
0

I didn't get into more detail but collectl has an option for generating delimiter separated output so in the case of gnuplot, you just generate your data with spaces in it and you're all set. It even will load nicely into excel. If you want commas you can change the delimiter and if you really want to do the rrd route (just be careful because the plots do not necessary match the data!), you can change the delimeter to colons and even change the timestamps to UTC. -mark

0

This isn't exactly what you're looking for, but perhaps you can adapt it to your needs using this reference (look for "Per Process Memory Usage").

Ivan
  • 3,172
  • 3
  • 24
  • 34
0

kSar, based on sar data, but it's java based, so is more or less platform independent and will allow you to ssh to a remote host to fetch the data.

http://ksar.atomique.net/

Greeblesnort
  • 1,739
  • 8
  • 10
0

Hmm, the gnuplot FAQ says it doesn't support pie charts, but they suggest Bernhard Reiter's piechart.

Philip Durbin
  • 1,541
  • 2
  • 15
  • 24