Create graph for Physical Memory grouped by states using Grafana, InfluxDB and collectd

This article shows how to make a graph showing a Linux machine’s memory. This plugin gathers physical memory utilization – used, buffered, cached, and free. In general, this module collects simple data for the physical memory like the Linux command free or top command. The purpose of this article is to make a graph showing memory usage and consumption.

main menu
example usage of physical memory

The Linux machine is using collectd to gather the memory statistics and send them to the time series back-end – InfluxDB. Grafana is used to visualize the data stored in the time series back-end InfluxDB and organize the graphs in panels and dashboards. Check out the previous articles on the subject to install and configure such software to collect, store and visualize data – Monitor and analyze with Grafana, influxdb 1.8 and collectd under CentOS Stream 9, Monitor and analyze with Grafana, influxdb 1.8 and collectd under Ubuntu 22.04 LTS and Create graph for Linux CPU usage using Grafana, InfluxDB and collectd
The collectd daemon is used to gather data on the Linux system and to send it to the back-end InfluxDB.

Key knowledge for the Memory collectd plugin

  • The collectd plugin Memory official page – https://collectd.org/wiki/index.php/Plugin:Memory
  • The Memory plugin options – https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_memory
  • to enable the Memory plugin, load the plugin with the load directive in /etc/collectd.conf
    LoadPlugin memory
    
  • The Memory plugin collects data every 10 seconds.
  • memory_value – a single Gauge value – a metric, which value that can go up and down. It is used to count the memory occupancy for the different categories (the category is saved in a tag value of one record, and the categories are Used, Free and etc.). So there are multiple gauge values with different tags for the different memory categories at a given time.
    tag key tag value description
    host server hostname The name of the source this measurement was recorded.
    type memory memory is the type, which will group the memory categories.
    type_instance memory categories The categories are buffered, cached, free, slab_recl, slab_unrecl, used.
  • A Gauge value – a metric, which value that can go up and down. More on the topic – Data sources.

    A GAUGE value is simply stored as-is. This is the right choice for values which may increase as well as decrease, such as temperatures or the amount of memory used.

  • To cross-check the value, the user can use the /proc/meminfo
    [root@srv ~]# cat /proc/meminfo |egrep -e "^(MemTotal|MemFree|Buffers|Cached|Slab|SReclaimable|SUnreclaim)"
    MemTotal:        3726476 kB
    MemFree:         2869736 kB
    Buffers:            5248 kB
    Cached:           400740 kB
    Slab:              67700 kB
    SReclaimable:      29200 kB
    SUnreclaim:        38500 kB
    

    Some of the lines are pretty clear about what they mean by “MemTotal“, “MemFree“, “Buffers” and so on.

Keep on reading!