]> arthur.barton.de Git - netdata.git/blobdiff - src/proc_vmstat.c
dns_query_time plugin: replace "." with "_" in dimensions
[netdata.git] / src / proc_vmstat.c
old mode 100755 (executable)
new mode 100644 (file)
index 9f77462..8474873
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "log.h"
-#include "config.h"
-#include "procfile.h"
-#include "rrd.h"
-#include "plugin_proc.h"
-
-#define MAX_PROC_VMSTAT_LINE 4096
-#define MAX_PROC_VMSTAT_NAME 1024
-
-int do_proc_vmstat(int update_every, unsigned long long dt) {
-       static procfile *ff = NULL;
-       static int do_swapio = -1, do_io = -1, do_pgfaults = -1;
-
-       if(do_swapio == -1)     do_swapio = config_get_boolean("plugin:proc:/proc/vmstat", "swap i/o", 1);
-       if(do_io == -1)         do_io = config_get_boolean("plugin:proc:/proc/vmstat", "disk i/o", 1);
-       if(do_pgfaults == -1)   do_pgfaults = config_get_boolean("plugin:proc:/proc/vmstat", "memory page faults", 1);
-
-       if(dt) {};
-
-       if(!ff) ff = procfile_open("/proc/vmstat", " \t:");
-       if(!ff) return 1;
-
-       ff = procfile_readall(ff);
-       if(!ff) return 0; // we return 0, so that we will retry to open it next time
-
-       uint32_t lines = procfile_lines(ff), l;
-       uint32_t words;
-
-       unsigned long long nr_free_pages = 0, nr_inactive_anon = 0, nr_active_anon = 0, nr_inactive_file = 0, nr_active_file = 0, nr_unevictable = 0, nr_mlock = 0,
-               nr_anon_pages = 0, nr_mapped = 0, nr_file_pages = 0, nr_dirty = 0, nr_writeback = 0, nr_slab_reclaimable = 0, nr_slab_unreclaimable = 0, nr_page_table_pages = 0,
-               nr_kernel_stack = 0, nr_unstable = 0, nr_bounce = 0, nr_vmscan_write = 0, nr_vmscan_immediate_reclaim = 0, nr_writeback_temp = 0, nr_isolated_anon = 0, nr_isolated_file = 0,
-               nr_shmem = 0, nr_dirtied = 0, nr_written = 0, nr_anon_transparent_hugepages = 0, nr_dirty_threshold = 0, nr_dirty_background_threshold = 0,
-               pgpgin = 0, pgpgout = 0, pswpin = 0, pswpout = 0, pgalloc_dma = 0, pgalloc_dma32 = 0, pgalloc_normal = 0, pgalloc_movable = 0, pgfree = 0, pgactivate = 0, pgdeactivate = 0,
-               pgfault = 0, pgmajfault = 0, pgrefill_dma = 0, pgrefill_dma32 = 0, pgrefill_normal = 0, pgrefill_movable = 0, pgsteal_kswapd_dma = 0, pgsteal_kswapd_dma32 = 0,
-               pgsteal_kswapd_normal = 0, pgsteal_kswapd_movable = 0, pgsteal_direct_dma = 0, pgsteal_direct_dma32 = 0, pgsteal_direct_normal = 0, pgsteal_direct_movable = 0, 
-               pgscan_kswapd_dma = 0, pgscan_kswapd_dma32 = 0, pgscan_kswapd_normal = 0, pgscan_kswapd_movable = 0, pgscan_direct_dma = 0, pgscan_direct_dma32 = 0, pgscan_direct_normal = 0,
-               pgscan_direct_movable = 0, pginodesteal = 0, slabs_scanned = 0, kswapd_inodesteal = 0, kswapd_low_wmark_hit_quickly = 0, kswapd_high_wmark_hit_quickly = 0,
-               kswapd_skip_congestion_wait = 0, pageoutrun = 0, allocstall = 0, pgrotated = 0, compact_blocks_moved = 0, compact_pages_moved = 0, compact_pagemigrate_failed = 0,
-               compact_stall = 0, compact_fail = 0, compact_success = 0, htlb_buddy_alloc_success = 0, htlb_buddy_alloc_fail = 0, unevictable_pgs_culled = 0, unevictable_pgs_scanned = 0,
-               unevictable_pgs_rescued = 0, unevictable_pgs_mlocked = 0, unevictable_pgs_munlocked = 0, unevictable_pgs_cleared = 0, unevictable_pgs_stranded = 0, unevictable_pgs_mlockfreed = 0,
-               thp_fault_alloc = 0, thp_fault_fallback = 0, thp_collapse_alloc = 0, thp_collapse_alloc_failed = 0, thp_split = 0;
-
-       for(l = 0; l < lines ;l++) {
-               words = procfile_linewords(ff, l);
-               if(words < 2) {
-                       if(words) error("Cannot read /proc/vmstat line %d. Expected 2 params, read %d.", l, words);
-                       continue;
-               }
-
-               char *name = procfile_lineword(ff, l, 0);
-               unsigned long long value = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
-
-                    if(!nr_free_pages && strcmp(name, "nr_free_pages") == 0) nr_free_pages = value;
-               else if(!nr_inactive_anon && strcmp(name, "nr_inactive_anon") == 0) nr_inactive_anon = value;
-               else if(!nr_active_anon && strcmp(name, "nr_active_anon") == 0) nr_active_anon = value;
-               else if(!nr_inactive_file && strcmp(name, "nr_inactive_file") == 0) nr_inactive_file = value;
-               else if(!nr_active_file && strcmp(name, "nr_active_file") == 0) nr_active_file = value;
-               else if(!nr_unevictable && strcmp(name, "nr_unevictable") == 0) nr_unevictable = value;
-               else if(!nr_mlock && strcmp(name, "nr_mlock") == 0) nr_mlock = value;
-               else if(!nr_anon_pages && strcmp(name, "nr_anon_pages") == 0) nr_anon_pages = value;
-               else if(!nr_mapped && strcmp(name, "nr_mapped") == 0) nr_mapped = value;
-               else if(!nr_file_pages && strcmp(name, "nr_file_pages") == 0) nr_file_pages = value;
-               else if(!nr_dirty && strcmp(name, "nr_dirty") == 0) nr_dirty = value;
-               else if(!nr_writeback && strcmp(name, "nr_writeback") == 0) nr_writeback = value;
-               else if(!nr_slab_reclaimable && strcmp(name, "nr_slab_reclaimable") == 0) nr_slab_reclaimable = value;
-               else if(!nr_slab_unreclaimable && strcmp(name, "nr_slab_unreclaimable") == 0) nr_slab_unreclaimable = value;
-               else if(!nr_page_table_pages && strcmp(name, "nr_page_table_pages") == 0) nr_page_table_pages = value;
-               else if(!nr_kernel_stack && strcmp(name, "nr_kernel_stack") == 0) nr_kernel_stack = value;
-               else if(!nr_unstable && strcmp(name, "nr_unstable") == 0) nr_unstable = value;
-               else if(!nr_bounce && strcmp(name, "nr_bounce") == 0) nr_bounce = value;
-               else if(!nr_vmscan_write && strcmp(name, "nr_vmscan_write") == 0) nr_vmscan_write = value;
-               else if(!nr_vmscan_immediate_reclaim && strcmp(name, "nr_vmscan_immediate_reclaim") == 0) nr_vmscan_immediate_reclaim = value;
-               else if(!nr_writeback_temp && strcmp(name, "nr_writeback_temp") == 0) nr_writeback_temp = value;
-               else if(!nr_isolated_anon && strcmp(name, "nr_isolated_anon") == 0) nr_isolated_anon = value;
-               else if(!nr_isolated_file && strcmp(name, "nr_isolated_file") == 0) nr_isolated_file = value;
-               else if(!nr_shmem && strcmp(name, "nr_shmem") == 0) nr_shmem = value;
-               else if(!nr_dirtied && strcmp(name, "nr_dirtied") == 0) nr_dirtied = value;
-               else if(!nr_written && strcmp(name, "nr_written") == 0) nr_written = value;
-               else if(!nr_anon_transparent_hugepages && strcmp(name, "nr_anon_transparent_hugepages") == 0) nr_anon_transparent_hugepages = value;
-               else if(!nr_dirty_threshold && strcmp(name, "nr_dirty_threshold") == 0) nr_dirty_threshold = value;
-               else if(!nr_dirty_background_threshold && strcmp(name, "nr_dirty_background_threshold") == 0) nr_dirty_background_threshold = value;
-               else if(!pgpgin && strcmp(name, "pgpgin") == 0) pgpgin = value;
-               else if(!pgpgout && strcmp(name, "pgpgout") == 0) pgpgout = value;
-               else if(!pswpin && strcmp(name, "pswpin") == 0) pswpin = value;
-               else if(!pswpout && strcmp(name, "pswpout") == 0) pswpout = value;
-               else if(!pgalloc_dma && strcmp(name, "pgalloc_dma") == 0) pgalloc_dma = value;
-               else if(!pgalloc_dma32 && strcmp(name, "pgalloc_dma32") == 0) pgalloc_dma32 = value;
-               else if(!pgalloc_normal && strcmp(name, "pgalloc_normal") == 0) pgalloc_normal = value;
-               else if(!pgalloc_movable && strcmp(name, "pgalloc_movable") == 0) pgalloc_movable = value;
-               else if(!pgfree && strcmp(name, "pgfree") == 0) pgfree = value;
-               else if(!pgactivate && strcmp(name, "pgactivate") == 0) pgactivate = value;
-               else if(!pgdeactivate && strcmp(name, "pgdeactivate") == 0) pgdeactivate = value;
-               else if(!pgfault && strcmp(name, "pgfault") == 0) pgfault = value;
-               else if(!pgmajfault && strcmp(name, "pgmajfault") == 0) pgmajfault = value;
-               else if(!pgrefill_dma && strcmp(name, "pgrefill_dma") == 0) pgrefill_dma = value;
-               else if(!pgrefill_dma32 && strcmp(name, "pgrefill_dma32") == 0) pgrefill_dma32 = value;
-               else if(!pgrefill_normal && strcmp(name, "pgrefill_normal") == 0) pgrefill_normal = value;
-               else if(!pgrefill_movable && strcmp(name, "pgrefill_movable") == 0) pgrefill_movable = value;
-               else if(!pgsteal_kswapd_dma && strcmp(name, "pgsteal_kswapd_dma") == 0) pgsteal_kswapd_dma = value;
-               else if(!pgsteal_kswapd_dma32 && strcmp(name, "pgsteal_kswapd_dma32") == 0) pgsteal_kswapd_dma32 = value;
-               else if(!pgsteal_kswapd_normal && strcmp(name, "pgsteal_kswapd_normal") == 0) pgsteal_kswapd_normal = value;
-               else if(!pgsteal_kswapd_movable && strcmp(name, "pgsteal_kswapd_movable") == 0) pgsteal_kswapd_movable = value;
-               else if(!pgsteal_direct_dma && strcmp(name, "pgsteal_direct_dma") == 0) pgsteal_direct_dma = value;
-               else if(!pgsteal_direct_dma32 && strcmp(name, "pgsteal_direct_dma32") == 0) pgsteal_direct_dma32 = value;
-               else if(!pgsteal_direct_normal && strcmp(name, "pgsteal_direct_normal") == 0) pgsteal_direct_normal = value;
-               else if(!pgsteal_direct_movable && strcmp(name, "pgsteal_direct_movable") == 0) pgsteal_direct_movable = value;
-               else if(!pgscan_kswapd_dma && strcmp(name, "pgscan_kswapd_dma") == 0) pgscan_kswapd_dma = value;
-               else if(!pgscan_kswapd_dma32 && strcmp(name, "pgscan_kswapd_dma32") == 0) pgscan_kswapd_dma32 = value;
-               else if(!pgscan_kswapd_normal && strcmp(name, "pgscan_kswapd_normal") == 0) pgscan_kswapd_normal = value;
-               else if(!pgscan_kswapd_movable && strcmp(name, "pgscan_kswapd_movable") == 0) pgscan_kswapd_movable = value;
-               else if(!pgscan_direct_dma && strcmp(name, "pgscan_direct_dma") == 0) pgscan_direct_dma = value;
-               else if(!pgscan_direct_dma32 && strcmp(name, "pgscan_direct_dma32") == 0) pgscan_direct_dma32 = value;
-               else if(!pgscan_direct_normal && strcmp(name, "pgscan_direct_normal") == 0) pgscan_direct_normal = value;
-               else if(!pgscan_direct_movable && strcmp(name, "pgscan_direct_movable") == 0) pgscan_direct_movable = value;
-               else if(!pginodesteal && strcmp(name, "pginodesteal") == 0) pginodesteal = value;
-               else if(!slabs_scanned && strcmp(name, "slabs_scanned") == 0) slabs_scanned = value;
-               else if(!kswapd_inodesteal && strcmp(name, "kswapd_inodesteal") == 0) kswapd_inodesteal = value;
-               else if(!kswapd_low_wmark_hit_quickly && strcmp(name, "kswapd_low_wmark_hit_quickly") == 0) kswapd_low_wmark_hit_quickly = value;
-               else if(!kswapd_high_wmark_hit_quickly && strcmp(name, "kswapd_high_wmark_hit_quickly") == 0) kswapd_high_wmark_hit_quickly = value;
-               else if(!kswapd_skip_congestion_wait && strcmp(name, "kswapd_skip_congestion_wait") == 0) kswapd_skip_congestion_wait = value;
-               else if(!pageoutrun && strcmp(name, "pageoutrun") == 0) pageoutrun = value;
-               else if(!allocstall && strcmp(name, "allocstall") == 0) allocstall = value;
-               else if(!pgrotated && strcmp(name, "pgrotated") == 0) pgrotated = value;
-               else if(!compact_blocks_moved && strcmp(name, "compact_blocks_moved") == 0) compact_blocks_moved = value;
-               else if(!compact_pages_moved && strcmp(name, "compact_pages_moved") == 0) compact_pages_moved = value;
-               else if(!compact_pagemigrate_failed && strcmp(name, "compact_pagemigrate_failed") == 0) compact_pagemigrate_failed = value;
-               else if(!compact_stall && strcmp(name, "compact_stall") == 0) compact_stall = value;
-               else if(!compact_fail && strcmp(name, "compact_fail") == 0) compact_fail = value;
-               else if(!compact_success && strcmp(name, "compact_success") == 0) compact_success = value;
-               else if(!htlb_buddy_alloc_success && strcmp(name, "htlb_buddy_alloc_success") == 0) htlb_buddy_alloc_success = value;
-               else if(!htlb_buddy_alloc_fail && strcmp(name, "htlb_buddy_alloc_fail") == 0) htlb_buddy_alloc_fail = value;
-               else if(!unevictable_pgs_culled && strcmp(name, "unevictable_pgs_culled") == 0) unevictable_pgs_culled = value;
-               else if(!unevictable_pgs_scanned && strcmp(name, "unevictable_pgs_scanned") == 0) unevictable_pgs_scanned = value;
-               else if(!unevictable_pgs_rescued && strcmp(name, "unevictable_pgs_rescued") == 0) unevictable_pgs_rescued = value;
-               else if(!unevictable_pgs_mlocked && strcmp(name, "unevictable_pgs_mlocked") == 0) unevictable_pgs_mlocked = value;
-               else if(!unevictable_pgs_munlocked && strcmp(name, "unevictable_pgs_munlocked") == 0) unevictable_pgs_munlocked = value;
-               else if(!unevictable_pgs_cleared && strcmp(name, "unevictable_pgs_cleared") == 0) unevictable_pgs_cleared = value;
-               else if(!unevictable_pgs_stranded && strcmp(name, "unevictable_pgs_stranded") == 0) unevictable_pgs_stranded = value;
-               else if(!unevictable_pgs_mlockfreed && strcmp(name, "unevictable_pgs_mlockfreed") == 0) unevictable_pgs_mlockfreed = value;
-               else if(!thp_fault_alloc && strcmp(name, "thp_fault_alloc") == 0) thp_fault_alloc = value;
-               else if(!thp_fault_fallback && strcmp(name, "thp_fault_fallback") == 0) thp_fault_fallback = value;
-               else if(!thp_collapse_alloc && strcmp(name, "thp_collapse_alloc") == 0) thp_collapse_alloc = value;
-               else if(!thp_collapse_alloc_failed && strcmp(name, "thp_collapse_alloc_failed") == 0) thp_collapse_alloc_failed = value;
-               else if(!thp_split && strcmp(name, "thp_split") == 0) thp_split = value;
-       }
-
-       RRD_STATS *st;
-
-       // --------------------------------------------------------------------
-       
-       if(do_swapio) {
-               st = rrd_stats_find("system.swapio");
-               if(!st) {
-                       st = rrd_stats_create("system", "swapio", NULL, "mem", "Swap I/O", "kilobytes/s", 250, update_every, CHART_TYPE_AREA);
-
-                       rrd_stats_dimension_add(st, "in",  NULL, sysconf(_SC_PAGESIZE), 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
-                       rrd_stats_dimension_add(st, "out", NULL, -sysconf(_SC_PAGESIZE), 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
-               }
-               else rrd_stats_next(st);
-
-               rrd_stats_dimension_set(st, "in", pswpin);
-               rrd_stats_dimension_set(st, "out", pswpout);
-               rrd_stats_done(st);
-       }
-
-       // --------------------------------------------------------------------
-       
-       if(do_io) {
-               st = rrd_stats_find("system.io");
-               if(!st) {
-                       st = rrd_stats_create("system", "io", NULL, "disk", "Disk I/O", "kilobytes/s", 150, update_every, CHART_TYPE_AREA);
-
-                       rrd_stats_dimension_add(st, "in",  NULL,  1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
-                       rrd_stats_dimension_add(st, "out", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
-               }
-               else rrd_stats_next(st);
-
-               rrd_stats_dimension_set(st, "in", pgpgin);
-               rrd_stats_dimension_set(st, "out", pgpgout);
-               rrd_stats_done(st);
-       }
-
-       // --------------------------------------------------------------------
-       
-       if(do_pgfaults) {
-               st = rrd_stats_find("system.pgfaults");
-               if(!st) {
-                       st = rrd_stats_create("system", "pgfaults", NULL, "mem", "Memory Page Faults", "page faults/s", 500, update_every, CHART_TYPE_LINE);
-                       st->isdetail = 1;
-
-                       rrd_stats_dimension_add(st, "minor",  NULL,  1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
-                       rrd_stats_dimension_add(st, "major", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
-               }
-               else rrd_stats_next(st);
-
-               rrd_stats_dimension_set(st, "minor", pgfault);
-               rrd_stats_dimension_set(st, "major", pgmajfault);
-               rrd_stats_done(st);
-       }
-
-       return 0;
+#include "common.h"
+
+int do_proc_vmstat(int update_every, usec_t dt) {
+    (void)dt;
+
+    static procfile *ff = NULL;
+    static int do_swapio = -1, do_io = -1, do_pgfaults = -1, do_numa = -1;
+    static int has_numa = -1;
+
+    static ARL_BASE *arl_base = NULL;
+    static unsigned long long numa_foreign = 0ULL;
+    static unsigned long long numa_hint_faults = 0ULL;
+    static unsigned long long numa_hint_faults_local = 0ULL;
+    static unsigned long long numa_huge_pte_updates = 0ULL;
+    static unsigned long long numa_interleave = 0ULL;
+    static unsigned long long numa_local = 0ULL;
+    static unsigned long long numa_other = 0ULL;
+    static unsigned long long numa_pages_migrated = 0ULL;
+    static unsigned long long numa_pte_updates = 0ULL;
+    static unsigned long long pgfault = 0ULL;
+    static unsigned long long pgmajfault = 0ULL;
+    static unsigned long long pgpgin = 0ULL;
+    static unsigned long long pgpgout = 0ULL;
+    static unsigned long long pswpin = 0ULL;
+    static unsigned long long pswpout = 0ULL;
+
+    if(unlikely(!arl_base)) {
+        do_swapio = config_get_boolean_ondemand("plugin:proc:/proc/vmstat", "swap i/o", CONFIG_BOOLEAN_AUTO);
+        do_io = config_get_boolean("plugin:proc:/proc/vmstat", "disk i/o", 1);
+        do_pgfaults = config_get_boolean("plugin:proc:/proc/vmstat", "memory page faults", 1);
+        do_numa = config_get_boolean_ondemand("plugin:proc:/proc/vmstat", "system-wide numa metric summary", CONFIG_BOOLEAN_AUTO);
+
+
+        arl_base = arl_create("vmstat", NULL, 60);
+        arl_expect(arl_base, "pgfault", &pgfault);
+        arl_expect(arl_base, "pgmajfault", &pgmajfault);
+        arl_expect(arl_base, "pgpgin", &pgpgin);
+        arl_expect(arl_base, "pgpgout", &pgpgout);
+        arl_expect(arl_base, "pswpin", &pswpin);
+        arl_expect(arl_base, "pswpout", &pswpout);
+
+        if(do_numa == CONFIG_BOOLEAN_YES || (do_numa == CONFIG_BOOLEAN_AUTO && get_numa_node_count() >= 2)) {
+            arl_expect(arl_base, "numa_foreign", &numa_foreign);
+            arl_expect(arl_base, "numa_hint_faults_local", &numa_hint_faults_local);
+            arl_expect(arl_base, "numa_hint_faults", &numa_hint_faults);
+            arl_expect(arl_base, "numa_huge_pte_updates", &numa_huge_pte_updates);
+            arl_expect(arl_base, "numa_interleave", &numa_interleave);
+            arl_expect(arl_base, "numa_local", &numa_local);
+            arl_expect(arl_base, "numa_other", &numa_other);
+            arl_expect(arl_base, "numa_pages_migrated", &numa_pages_migrated);
+            arl_expect(arl_base, "numa_pte_updates", &numa_pte_updates);
+        }
+        else {
+            // Do not expect numa metrics when they are not needed.
+            // By not adding them, the ARL will stop processing the file
+            // when all the expected metrics are collected.
+            // Also ARL will not parse their values.
+            has_numa = 0;
+            do_numa = CONFIG_BOOLEAN_NO;
+        }
+    }
+
+    if(unlikely(!ff)) {
+        char filename[FILENAME_MAX + 1];
+        snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/vmstat");
+        ff = procfile_open(config_get("plugin:proc:/proc/vmstat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
+        if(unlikely(!ff)) return 1;
+    }
+
+    ff = procfile_readall(ff);
+    if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
+
+    size_t lines = procfile_lines(ff), l;
+
+    arl_begin(arl_base);
+    for(l = 0; l < lines ;l++) {
+        size_t words = procfile_linewords(ff, l);
+        if(unlikely(words < 2)) {
+            if(unlikely(words)) error("Cannot read /proc/vmstat line %zu. Expected 2 params, read %zu.", l, words);
+            continue;
+        }
+
+        if(unlikely(arl_check(arl_base,
+                procfile_lineword(ff, l, 0),
+                procfile_lineword(ff, l, 1)))) break;
+    }
+
+    // --------------------------------------------------------------------
+
+    if(pswpin || pswpout || do_swapio == CONFIG_BOOLEAN_YES) {
+        do_swapio = CONFIG_BOOLEAN_YES;
+
+        static RRDSET *st_swapio = NULL;
+        if(unlikely(!st_swapio)) {
+            st_swapio = rrdset_create_localhost("system", "swapio", NULL, "swap", NULL, "Swap I/O", "kilobytes/s", 250
+                                                , update_every, RRDSET_TYPE_AREA);
+
+            rrddim_add(st_swapio, "in",  NULL, sysconf(_SC_PAGESIZE), 1024, RRD_ALGORITHM_INCREMENTAL);
+            rrddim_add(st_swapio, "out", NULL, -sysconf(_SC_PAGESIZE), 1024, RRD_ALGORITHM_INCREMENTAL);
+        }
+        else rrdset_next(st_swapio);
+
+        rrddim_set(st_swapio, "in", pswpin);
+        rrddim_set(st_swapio, "out", pswpout);
+        rrdset_done(st_swapio);
+    }
+
+    // --------------------------------------------------------------------
+
+    if(do_io) {
+        static RRDSET *st_io = NULL;
+        if(unlikely(!st_io)) {
+            st_io = rrdset_create_localhost("system", "io", NULL, "disk", NULL, "Disk I/O", "kilobytes/s", 150
+                                            , update_every, RRDSET_TYPE_AREA);
+
+            rrddim_add(st_io, "in",  NULL,  1, 1, RRD_ALGORITHM_INCREMENTAL);
+            rrddim_add(st_io, "out", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
+        }
+        else rrdset_next(st_io);
+
+        rrddim_set(st_io, "in", pgpgin);
+        rrddim_set(st_io, "out", pgpgout);
+        rrdset_done(st_io);
+    }
+
+    // --------------------------------------------------------------------
+
+    if(do_pgfaults) {
+        static RRDSET *st_pgfaults = NULL;
+        if(unlikely(!st_pgfaults)) {
+            st_pgfaults = rrdset_create_localhost("mem", "pgfaults", NULL, "system", NULL, "Memory Page Faults"
+                                                  , "page faults/s", 500, update_every, RRDSET_TYPE_LINE);
+            rrdset_flag_set(st_pgfaults, RRDSET_FLAG_DETAIL);
+
+            rrddim_add(st_pgfaults, "minor",  NULL,  1, 1, RRD_ALGORITHM_INCREMENTAL);
+            rrddim_add(st_pgfaults, "major", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
+        }
+        else rrdset_next(st_pgfaults);
+
+        rrddim_set(st_pgfaults, "minor", pgfault);
+        rrddim_set(st_pgfaults, "major", pgmajfault);
+        rrdset_done(st_pgfaults);
+    }
+
+    // --------------------------------------------------------------------
+
+    // Ondemand criteria for NUMA. Since this won't change at run time, we
+    // check it only once. We check whether the node count is >= 2 because
+    // single-node systems have uninteresting statistics (since all accesses
+    // are local).
+    if(unlikely(has_numa == -1))
+        has_numa = (numa_local || numa_foreign || numa_interleave || numa_other || numa_pte_updates ||
+                     numa_huge_pte_updates || numa_hint_faults || numa_hint_faults_local || numa_pages_migrated) ? 1 : 0;
+
+    if(do_numa == CONFIG_BOOLEAN_YES || (do_numa == CONFIG_BOOLEAN_AUTO && has_numa)) {
+        do_numa = CONFIG_BOOLEAN_YES;
+
+        static RRDSET *st_numa = NULL;
+        if(unlikely(!st_numa)) {
+            st_numa = rrdset_create_localhost("mem", "numa", NULL, "numa", NULL, "NUMA events", "events/s", 800
+                                              , update_every, RRDSET_TYPE_LINE);
+            rrdset_flag_set(st_numa, RRDSET_FLAG_DETAIL);
+
+            // These depend on CONFIG_NUMA in the kernel.
+            rrddim_add(st_numa, "local", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+            rrddim_add(st_numa, "foreign", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+            rrddim_add(st_numa, "interleave", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+            rrddim_add(st_numa, "other", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+
+            // The following stats depend on CONFIG_NUMA_BALANCING in the
+            // kernel.
+            rrddim_add(st_numa, "pte updates", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+            rrddim_add(st_numa, "huge pte updates", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+            rrddim_add(st_numa, "hint faults", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+            rrddim_add(st_numa, "hint faults local", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+            rrddim_add(st_numa, "pages migrated", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+        }
+        else rrdset_next(st_numa);
+
+        rrddim_set(st_numa, "local", numa_local);
+        rrddim_set(st_numa, "foreign", numa_foreign);
+        rrddim_set(st_numa, "interleave", numa_interleave);
+        rrddim_set(st_numa, "other", numa_other);
+
+        rrddim_set(st_numa, "pte updates", numa_pte_updates);
+        rrddim_set(st_numa, "huge pte updates", numa_huge_pte_updates);
+        rrddim_set(st_numa, "hint faults", numa_hint_faults);
+        rrddim_set(st_numa, "hint faults local", numa_hint_faults_local);
+        rrddim_set(st_numa, "pages migrated", numa_pages_migrated);
+
+        rrdset_done(st_numa);
+    }
+
+    return 0;
 }