Better Cacti memory usage graphs

Cacti is a wonderful tool, but many of the default graphs are ugly. Worse, the “ucd/net Memory Usage” graph is totally useless. It displays memory which is free, or dedicated to cache or buffers. But it doesn’t display the actual used memory or total. And it uses the wrong base, assuming there are 1000 bytes in a kilobyte of memory. I can’t imagine why this graph template is even included with Cacti by default. So, I set out to make a better one.

Here is the default graph:


(Click to embiggen)

The implementation for “used memory” in the SNMP OID is inconsistent across devices. But you can fetch “total memory”, and do the math:

Used memory = Total – (Free + Cache + Buffers)

Many people have used this method to make better memory usage templates. Eric A. Hall made a much prettier graph, but it relies on an external script to fetch the data and do the math. This is unnecessary, and (slightly) slower than using Cacti CDEF functions. Hans Fugal used CDEF functions, but his graphs use an eye-searing colour scheme. He also uses the wrong base; there are 1024 bytes in a kilobyte of RAM, not 1000 as in hard drives or network data rate.

Here are mine:



My implementation uses Eric Hall’s colour scheme and Hans Fugal’s CDEF method, but graphs real memory and swap as two separate graphs. It also uses the correct unit base of 1024. These graphs are also intended for Linux. Unix operating systems won’t report Buffers or Cache, but they’ll graph correctly as long as they report Free and Total.




Only after making my own did I discover fmangeant‘s graphs. These use the CDEF method and correct base, although I’m not fond of the colours. The “Memory Usage Unix” graph would be useful if your device doesn’t report Buffers or Cache and you don’t want to see zero values on your graph.


  1. Kelvin’s avatar

    I implemented Memory Usage Real. All except Used memory are fine. For Used Memory the values are nan. How can I solve this problem?


    1. Tyler Wagner’s avatar

      Hi Kelvin,

      Used Memory is calculated from the other values. Are any of them showing NaN?

      Did you get the CDEF “Memory Usage – Calculate Memory Used” in the import?

      Are you polling at 1 minute or 5? Since this uses multiple data sources, if your poller runs every minute but you only poll for this graph every five, you’ll have a problem. The easiest solution is to make sure this

      I’ve replaced the XML files on this post with my latest versions. Changes:
      – Removed the maximum values on RAM, which default to 10 GB. That’s too low on modern equipment.
      – Changed to polling every minute. Should work on 5-minute polling. To change back, edit all Memory Usage data templates and change Step from 60 to 300 and Heartbeat from 120 to 600.


    2. Kelvin’s avatar

      The others are showing values except for Used Memory.

      Yes. The CDEF “Memory Usage – Calculate Memory Used” is also imported. I’ve also implemented in all 5 graph items under “Used” Data Source.

      You are referring to the Poller Interval under Settings? If that’s so it’s already at 5 minutes.


      1. Tyler Wagner’s avatar

        A default Cacti install has Poller Internal set to 5 minutes, but higher end users often set this to 1 minute (and update cron). After that, they edit any data source templates and add the “Hourly (1 Minute Average)” RRA, and lower Step to 60 and Heartbeat to 120. If you’re using the default config, consider editing my Data Source Templates and change Step to 300 and Heartbeat to 600 in all places.

        Please try the new XMLs on this post.

        If that fails, turn on graph debugging and post what it prints here. Mine looks like this:

        Sometimes updating or importing graph templates causes errors where CDEFs aren’t correctly applied. If you see any lines lacking the “cdef” prefixes where they do exist in my example, that’s your issue. The workaround is to edit the Graph Template, edit each item, and save.


      2. Kelvin’s avatar


        1. Tyler Wagner’s avatar

          Where does this data source “usedReal” come from? That’s not in my template, and you cannot fetch usedReal in the ucd/net MIB. That’s why it must be calculated.

          Compare our output, and you can see that my first set of GPRINTS are using the “Calculate Memory Used” CDEF. Yours is pulling from some data source I haven’t heard of.


        2. Tyler Wagner’s avatar

          Your graph template has been edited somehow. Here is mine:


          And here are the details of item #2. Notice how there is no data source, and shouldn’t be. The CDEF provides the data.



        3. Kelvin’s avatar

          Thanks for the screenshots. I changed the settings according to your screenshots and I don’t know why a new error shows. Here’s my debugging output:

          RRDTool Says:

          ERROR: Could not make sense out of ‘:cdefd#EA8F00FF:Buffers:STACK’


          1. Tyler Wagner’s avatar

            I wrapped your output in “pre” tags to make it display better here.

            The lines that say “:cdefbd#74C366FF:”Free”:STACK” are in error. They should begin with “AREA”. Try editing each of those lines and change them to AREA for the first item and STACK for the others. You may need to change them to LINE1 and then back again for this to fix itself.


          2. Kelvin’s avatar

            Got it. Thanks a lot. My graph is working well now.


          3. AK’s avatar

            Thanks for these, they just worked and are great!


          4. Steve Stevenson’s avatar

            I just tried to import your templates you had in this document. I see all the items in the cacti sections.

            /usr/bin/rrdtool create \
            /var/lib/cacti/rra/localhost_mem_total_64.rrd \
            –step 60 \
            DS:mem_total:GAUGE:120:0:U \
            RRA:AVERAGE:0.5:1:500 \
            RRA:AVERAGE:0.5:1:600 \
            RRA:AVERAGE:0.5:6:700 \
            RRA:AVERAGE:0.5:24:775 \
            RRA:AVERAGE:0.5:288:797 \
            RRA:MIN:0.5:1:500 \
            RRA:MIN:0.5:1:600 \
            RRA:MIN:0.5:6:700 \
            RRA:MIN:0.5:24:775 \
            RRA:MIN:0.5:288:797 \
            RRA:MAX:0.5:1:500 \
            RRA:MAX:0.5:1:600 \
            RRA:MAX:0.5:6:700 \
            RRA:MAX:0.5:24:775 \
            RRA:MAX:0.5:288:797 \
            RRA:LAST:0.5:1:500 \
            RRA:LAST:0.5:1:600 \
            RRA:LAST:0.5:6:700 \
            RRA:LAST:0.5:24:775 \
            RRA:LAST:0.5:288:797 \

            This is being output by cacti in the data source debugger. But the file is not being created on the file system. If I run the same from the CLI using the same user as the cacti process it creates it fine. But for whatever reason cacti is not generating this file on its own. If I create data sources from the default cacti templates/sources it is creating the rrd files with no issues. Any idea why your templates would not be allowing cacti to create them on its own?


            1. Tyler Wagner’s avatar

              No idea, sorry. I have not experienced that after importing these templates on other installs. Suggested test: export another similar template and compare the exports (Meld, colordiff, diff) side by side to see if there is anything relevant.


            2.’s avatar

              Wohh just what I was looking for, thanks for putting up.



Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.