2 #include "adaptive_resortable_list.h"
4 int do_proc_vmstat(int update_every, usec_t dt) {
7 static procfile *ff = NULL;
8 static int do_swapio = -1, do_io = -1, do_pgfaults = -1, do_numa = -1;
9 static int has_numa = -1;
11 static ARL_BASE *arl_base = NULL;
12 static unsigned long long numa_foreign = 0ULL;
13 static unsigned long long numa_hint_faults = 0ULL;
14 static unsigned long long numa_hint_faults_local = 0ULL;
15 static unsigned long long numa_huge_pte_updates = 0ULL;
16 static unsigned long long numa_interleave = 0ULL;
17 static unsigned long long numa_local = 0ULL;
18 static unsigned long long numa_other = 0ULL;
19 static unsigned long long numa_pages_migrated = 0ULL;
20 static unsigned long long numa_pte_updates = 0ULL;
21 static unsigned long long pgfault = 0ULL;
22 static unsigned long long pgmajfault = 0ULL;
23 static unsigned long long pgpgin = 0ULL;
24 static unsigned long long pgpgout = 0ULL;
25 static unsigned long long pswpin = 0ULL;
26 static unsigned long long pswpout = 0ULL;
28 if(unlikely(!arl_base)) {
29 do_swapio = config_get_boolean_ondemand("plugin:proc:/proc/vmstat", "swap i/o", CONFIG_ONDEMAND_ONDEMAND);
30 do_io = config_get_boolean("plugin:proc:/proc/vmstat", "disk i/o", 1);
31 do_pgfaults = config_get_boolean("plugin:proc:/proc/vmstat", "memory page faults", 1);
32 do_numa = config_get_boolean_ondemand("plugin:proc:/proc/vmstat", "system-wide numa metric summary", CONFIG_ONDEMAND_ONDEMAND);
34 arl_base = arl_create(NULL, 60);
35 arl_expect(arl_base, "numa_foreign", &numa_foreign);
36 arl_expect(arl_base, "numa_hint_faults_local", &numa_hint_faults_local);
37 arl_expect(arl_base, "numa_hint_faults", &numa_hint_faults);
38 arl_expect(arl_base, "numa_huge_pte_updates", &numa_huge_pte_updates);
39 arl_expect(arl_base, "numa_interleave", &numa_interleave);
40 arl_expect(arl_base, "numa_local", &numa_local);
41 arl_expect(arl_base, "numa_other", &numa_other);
42 arl_expect(arl_base, "numa_pages_migrated", &numa_pages_migrated);
43 arl_expect(arl_base, "numa_pte_updates", &numa_pte_updates);
44 arl_expect(arl_base, "pgfault", &pgfault);
45 arl_expect(arl_base, "pgmajfault", &pgmajfault);
46 arl_expect(arl_base, "pgpgin", &pgpgin);
47 arl_expect(arl_base, "pgpgout", &pgpgout);
48 arl_expect(arl_base, "pswpin", &pswpin);
49 arl_expect(arl_base, "pswpout", &pswpout);
53 char filename[FILENAME_MAX + 1];
54 snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/vmstat");
55 ff = procfile_open(config_get("plugin:proc:/proc/vmstat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
56 if(unlikely(!ff)) return 1;
59 ff = procfile_readall(ff);
60 if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
62 uint32_t lines = procfile_lines(ff), l;
65 for(l = 0; l < lines ;l++) {
66 uint32_t words = procfile_linewords(ff, l);
67 if(unlikely(words < 2)) {
68 if(unlikely(words)) error("Cannot read /proc/vmstat line %u. Expected 2 params, read %u.", l, words);
72 char *name = procfile_lineword(ff, l, 0);
73 char *value = procfile_lineword(ff, l, 1);
74 if(unlikely(!name || !*name || !value || !*value)) continue;
76 if(unlikely(arl_check(arl_base, name, value)))
80 // --------------------------------------------------------------------
82 if(pswpin || pswpout || do_swapio == CONFIG_ONDEMAND_YES) {
83 do_swapio = CONFIG_ONDEMAND_YES;
85 static RRDSET *st_swapio = NULL;
86 if(unlikely(!st_swapio)) {
87 st_swapio = rrdset_create("system", "swapio", NULL, "swap", NULL, "Swap I/O", "kilobytes/s", 250, update_every, RRDSET_TYPE_AREA);
89 rrddim_add(st_swapio, "in", NULL, sysconf(_SC_PAGESIZE), 1024, RRDDIM_INCREMENTAL);
90 rrddim_add(st_swapio, "out", NULL, -sysconf(_SC_PAGESIZE), 1024, RRDDIM_INCREMENTAL);
92 else rrdset_next(st_swapio);
94 rrddim_set(st_swapio, "in", pswpin);
95 rrddim_set(st_swapio, "out", pswpout);
96 rrdset_done(st_swapio);
99 // --------------------------------------------------------------------
102 static RRDSET *st_io = NULL;
103 if(unlikely(!st_io)) {
104 st_io = rrdset_create("system", "io", NULL, "disk", NULL, "Disk I/O", "kilobytes/s", 150, update_every, RRDSET_TYPE_AREA);
106 rrddim_add(st_io, "in", NULL, 1, 1, RRDDIM_INCREMENTAL);
107 rrddim_add(st_io, "out", NULL, -1, 1, RRDDIM_INCREMENTAL);
109 else rrdset_next(st_io);
111 rrddim_set(st_io, "in", pgpgin);
112 rrddim_set(st_io, "out", pgpgout);
116 // --------------------------------------------------------------------
119 static RRDSET *st_pgfaults = NULL;
120 if(unlikely(!st_pgfaults)) {
121 st_pgfaults = rrdset_create("mem", "pgfaults", NULL, "system", NULL, "Memory Page Faults", "page faults/s", 500, update_every, RRDSET_TYPE_LINE);
122 st_pgfaults->isdetail = 1;
124 rrddim_add(st_pgfaults, "minor", NULL, 1, 1, RRDDIM_INCREMENTAL);
125 rrddim_add(st_pgfaults, "major", NULL, -1, 1, RRDDIM_INCREMENTAL);
127 else rrdset_next(st_pgfaults);
129 rrddim_set(st_pgfaults, "minor", pgfault);
130 rrddim_set(st_pgfaults, "major", pgmajfault);
131 rrdset_done(st_pgfaults);
134 // --------------------------------------------------------------------
136 // Ondemand criteria for NUMA. Since this won't change at run time, we
137 // check it only once. We check whether the node count is >= 2 because
138 // single-node systems have uninteresting statistics (since all accesses
140 if(unlikely(has_numa == -1)) {
141 has_numa = (get_numa_node_count() >= 2 &&
142 (numa_local || numa_foreign || numa_interleave || numa_other || numa_pte_updates ||
143 numa_huge_pte_updates || numa_hint_faults || numa_hint_faults_local || numa_pages_migrated)) ? 1 : 0;
146 if(do_numa == CONFIG_ONDEMAND_YES || (do_numa == CONFIG_ONDEMAND_ONDEMAND && has_numa)) {
147 do_numa = CONFIG_ONDEMAND_YES;
149 static RRDSET *st_numa = NULL;
150 if(unlikely(!st_numa)) {
151 st_numa = rrdset_create("mem", "numa", NULL, "numa", NULL, "NUMA events", "events/s", 800, update_every, RRDSET_TYPE_LINE);
152 st_numa->isdetail = 1;
154 // These depend on CONFIG_NUMA in the kernel.
155 rrddim_add(st_numa, "local", NULL, 1, 1, RRDDIM_INCREMENTAL);
156 rrddim_add(st_numa, "foreign", NULL, 1, 1, RRDDIM_INCREMENTAL);
157 rrddim_add(st_numa, "interleave", NULL, 1, 1, RRDDIM_INCREMENTAL);
158 rrddim_add(st_numa, "other", NULL, 1, 1, RRDDIM_INCREMENTAL);
160 // The following stats depend on CONFIG_NUMA_BALANCING in the
162 rrddim_add(st_numa, "pte updates", NULL, 1, 1, RRDDIM_INCREMENTAL);
163 rrddim_add(st_numa, "huge pte updates", NULL, 1, 1, RRDDIM_INCREMENTAL);
164 rrddim_add(st_numa, "hint faults", NULL, 1, 1, RRDDIM_INCREMENTAL);
165 rrddim_add(st_numa, "hint faults local", NULL, 1, 1, RRDDIM_INCREMENTAL);
166 rrddim_add(st_numa, "pages migrated", NULL, 1, 1, RRDDIM_INCREMENTAL);
168 else rrdset_next(st_numa);
170 rrddim_set(st_numa, "local", numa_local);
171 rrddim_set(st_numa, "foreign", numa_foreign);
172 rrddim_set(st_numa, "interleave", numa_interleave);
173 rrddim_set(st_numa, "other", numa_other);
175 rrddim_set(st_numa, "pte updates", numa_pte_updates);
176 rrddim_set(st_numa, "huge pte updates", numa_huge_pte_updates);
177 rrddim_set(st_numa, "hint faults", numa_hint_faults);
178 rrddim_set(st_numa, "hint faults local", numa_hint_faults_local);
179 rrddim_set(st_numa, "pages migrated", numa_pages_migrated);
181 rrdset_done(st_numa);