@cryptotaxi247 / netdata-1 / commits / e10141bf5

ARL for /proc/meminfo

Costa Tsaousis (ktsaou) committed Jan 21, 2017 at 01:41 UTC e10141bf57185427bdcd1f48a6f25ccc6c45fdb4
5 files changed +81 -166
src/common.h
+1
@@ -208,6 +208,7 @@
208 #include "ipc.h"
209 #include "backends.h"
210 #include "inlined.h"
211 +#include "adaptive_resortable_list.h"
212
213 extern void netdata_fix_chart_id(char *s);
214 extern void netdata_fix_chart_name(char *s);
src/proc_meminfo.c
+78 -163
@@ -5,119 +5,12 @@ int do_proc_meminfo(int update_every, usec_t dt) {
5
6 static procfile *ff = NULL;
7 static int do_ram = -1, do_swap = -1, do_hwcorrupt = -1, do_committed = -1, do_writeback = -1, do_kernel = -1, do_slab = -1;
8 - static uint32_t MemTotal_hash = 0,
9 - MemFree_hash = 0,
10 - Buffers_hash = 0,
11 - Cached_hash = 0,
12 - //SwapCached_hash = 0,
13 - //Active_hash = 0,
14 - //Inactive_hash = 0,
15 - //ActiveAnon_hash = 0,
16 - //InactiveAnon_hash = 0,
17 - //ActiveFile_hash = 0,
18 - //InactiveFile_hash = 0,
19 - //Unevictable_hash = 0,
20 - //Mlocked_hash = 0,
21 - SwapTotal_hash = 0,
22 - SwapFree_hash = 0,
23 - Dirty_hash = 0,
24 - Writeback_hash = 0,
25 - //AnonPages_hash = 0,
26 - //Mapped_hash = 0,
27 - //Shmem_hash = 0,
28 - Slab_hash = 0,
29 - SReclaimable_hash = 0,
30 - SUnreclaim_hash = 0,
31 - KernelStack_hash = 0,
32 - PageTables_hash = 0,
33 - NFS_Unstable_hash = 0,
34 - Bounce_hash = 0,
35 - WritebackTmp_hash = 0,
36 - //CommitLimit_hash = 0,
37 - Committed_AS_hash = 0,
38 - //VmallocTotal_hash = 0,
39 - VmallocUsed_hash = 0,
40 - //VmallocChunk_hash = 0,
41 - //AnonHugePages_hash = 0,
42 - //HugePages_Total_hash = 0,
43 - //HugePages_Free_hash = 0,
44 - //HugePages_Rsvd_hash = 0,
45 - //HugePages_Surp_hash = 0,
46 - //Hugepagesize_hash = 0,
47 - //DirectMap4k_hash = 0,
48 - //DirectMap2M_hash = 0,
49 - HardwareCorrupted_hash = 0;
50 -
51 - if(unlikely(do_ram == -1)) {
52 - do_ram = config_get_boolean("plugin:proc:/proc/meminfo", "system ram", 1);
53 - do_swap = config_get_boolean_ondemand("plugin:proc:/proc/meminfo", "system swap", CONFIG_ONDEMAND_ONDEMAND);
54 - do_hwcorrupt = config_get_boolean_ondemand("plugin:proc:/proc/meminfo", "hardware corrupted ECC", CONFIG_ONDEMAND_ONDEMAND);
55 - do_committed = config_get_boolean("plugin:proc:/proc/meminfo", "committed memory", 1);
56 - do_writeback = config_get_boolean("plugin:proc:/proc/meminfo", "writeback memory", 1);
57 - do_kernel = config_get_boolean("plugin:proc:/proc/meminfo", "kernel memory", 1);
58 - do_slab = config_get_boolean("plugin:proc:/proc/meminfo", "slab memory", 1);
8
60 - MemTotal_hash = simple_hash("MemTotal");
61 - MemFree_hash = simple_hash("MemFree");
62 - Buffers_hash = simple_hash("Buffers");
63 - Cached_hash = simple_hash("Cached");
64 - //SwapCached_hash = simple_hash("SwapCached");
65 - //Active_hash = simple_hash("Active");
66 - //Inactive_hash = simple_hash("Inactive");
67 - //ActiveAnon_hash = simple_hash("ActiveAnon");
68 - //InactiveAnon_hash = simple_hash("InactiveAnon");
69 - //ActiveFile_hash = simple_hash("ActiveFile");
70 - //InactiveFile_hash = simple_hash("InactiveFile");
71 - //Unevictable_hash = simple_hash("Unevictable");
72 - //Mlocked_hash = simple_hash("Mlocked");
73 - SwapTotal_hash = simple_hash("SwapTotal");
74 - SwapFree_hash = simple_hash("SwapFree");
75 - Dirty_hash = simple_hash("Dirty");
76 - Writeback_hash = simple_hash("Writeback");
77 - //AnonPages_hash = simple_hash("AnonPages");
78 - //Mapped_hash = simple_hash("Mapped");
79 - //Shmem_hash = simple_hash("Shmem");
80 - Slab_hash = simple_hash("Slab");
81 - SReclaimable_hash = simple_hash("SReclaimable");
82 - SUnreclaim_hash = simple_hash("SUnreclaim");
83 - KernelStack_hash = simple_hash("KernelStack");
84 - PageTables_hash = simple_hash("PageTables");
85 - NFS_Unstable_hash = simple_hash("NFS_Unstable");
86 - Bounce_hash = simple_hash("Bounce");
87 - WritebackTmp_hash = simple_hash("WritebackTmp");
88 - //CommitLimit_hash = simple_hash("CommitLimit");
89 - Committed_AS_hash = simple_hash("Committed_AS");
90 - //VmallocTotal_hash = simple_hash("VmallocTotal");
91 - VmallocUsed_hash = simple_hash("VmallocUsed");
92 - //VmallocChunk_hash = simple_hash("VmallocChunk");
93 - HardwareCorrupted_hash = simple_hash("HardwareCorrupted");
94 - //AnonHugePages_hash = simple_hash("AnonHugePages");
95 - //HugePages_Total_hash = simple_hash("HugePages_Total");
96 - //HugePages_Free_hash = simple_hash("HugePages_Free");
97 - //HugePages_Rsvd_hash = simple_hash("HugePages_Rsvd");
98 - //HugePages_Surp_hash = simple_hash("HugePages_Surp");
99 - //Hugepagesize_hash = simple_hash("Hugepagesize");
100 - //DirectMap4k_hash = simple_hash("DirectMap4k");
101 - //DirectMap2M_hash = simple_hash("DirectMap2M");
102 - }
9 + static ARL_BASE *arl_base = NULL;
10 + static ARL_ENTRY *arl_hwcorrupted = NULL;
11
104 - if(unlikely(!ff)) {
105 - char filename[FILENAME_MAX + 1];
106 - snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/meminfo");
107 - ff = procfile_open(config_get("plugin:proc:/proc/meminfo", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
108 - if(unlikely(!ff))
109 - return 1;
110 - }
111 -
112 - ff = procfile_readall(ff);
113 - if(unlikely(!ff))
114 - return 0; // we return 0, so that we will retry to open it next time
115 -
116 - size_t lines = procfile_lines(ff), l;
117 -
118 - int hwcorrupted = 0;
119 -
120 - unsigned long long MemTotal = 0,
12 + static unsigned long long
13 + MemTotal = 0,
14 MemFree = 0,
15 Buffers = 0,
16 Cached = 0,
@@ -160,61 +53,83 @@ int do_proc_meminfo(int update_every, usec_t dt) {
53 //DirectMap2M = 0,
54 HardwareCorrupted = 0;
55
163 - unsigned long long *value = NULL;
56 + if(unlikely(!arl_base)) {
57 + do_ram = config_get_boolean("plugin:proc:/proc/meminfo", "system ram", 1);
58 + do_swap = config_get_boolean_ondemand("plugin:proc:/proc/meminfo", "system swap", CONFIG_ONDEMAND_ONDEMAND);
59 + do_hwcorrupt = config_get_boolean_ondemand("plugin:proc:/proc/meminfo", "hardware corrupted ECC", CONFIG_ONDEMAND_ONDEMAND);
60 + do_committed = config_get_boolean("plugin:proc:/proc/meminfo", "committed memory", 1);
61 + do_writeback = config_get_boolean("plugin:proc:/proc/meminfo", "writeback memory", 1);
62 + do_kernel = config_get_boolean("plugin:proc:/proc/meminfo", "kernel memory", 1);
63 + do_slab = config_get_boolean("plugin:proc:/proc/meminfo", "slab memory", 1);
64 +
65 + arl_base = arl_create(NULL, 60);
66 + arl_expect(arl_base, "MemTotal", &MemTotal);
67 + arl_expect(arl_base, "MemFree", &MemFree);
68 + arl_expect(arl_base, "Buffers", &Buffers);
69 + arl_expect(arl_base, "Cached", &Cached);
70 + //arl_expect(arl_base, "SwapCached", &SwapCached);
71 + //arl_expect(arl_base, "Active", &Active);
72 + //arl_expect(arl_base, "Inactive", &Inactive);
73 + //arl_expect(arl_base, "ActiveAnon", &ActiveAnon);
74 + //arl_expect(arl_base, "InactiveAnon", &InactiveAnon);
75 + //arl_expect(arl_base, "ActiveFile", &ActiveFile);
76 + //arl_expect(arl_base, "InactiveFile", &InactiveFile);
77 + //arl_expect(arl_base, "Unevictable", &Unevictable);
78 + //arl_expect(arl_base, "Mlocked", &Mlocked);
79 + arl_expect(arl_base, "SwapTotal", &SwapTotal);
80 + arl_expect(arl_base, "SwapFree", &SwapFree);
81 + arl_expect(arl_base, "Dirty", &Dirty);
82 + arl_expect(arl_base, "Writeback", &Writeback);
83 + //arl_expect(arl_base, "AnonPages", &AnonPages);
84 + //arl_expect(arl_base, "Mapped", &Mapped);
85 + //arl_expect(arl_base, "Shmem", &Shmem);
86 + arl_expect(arl_base, "Slab", &Slab);
87 + arl_expect(arl_base, "SReclaimable", &SReclaimable);
88 + arl_expect(arl_base, "SUnreclaim", &SUnreclaim);
89 + arl_expect(arl_base, "KernelStack", &KernelStack);
90 + arl_expect(arl_base, "PageTables", &PageTables);
91 + arl_expect(arl_base, "NFS_Unstable", &NFS_Unstable);
92 + arl_expect(arl_base, "Bounce", &Bounce);
93 + arl_expect(arl_base, "WritebackTmp", &WritebackTmp);
94 + //arl_expect(arl_base, "CommitLimit", &CommitLimit);
95 + arl_expect(arl_base, "Committed_AS", &Committed_AS);
96 + //arl_expect(arl_base, "VmallocTotal", &VmallocTotal);
97 + arl_expect(arl_base, "VmallocUsed", &VmallocUsed);
98 + //arl_expect(arl_base, "VmallocChunk", &VmallocChunk);
99 + arl_hwcorrupted = arl_expect(arl_base, "HardwareCorrupted", &HardwareCorrupted);
100 + //arl_expect(arl_base, "AnonHugePages", &AnonHugePages);
101 + //arl_expect(arl_base, "HugePages_Total", &HugePages_Total);
102 + //arl_expect(arl_base, "HugePages_Free", &HugePages_Free);
103 + //arl_expect(arl_base, "HugePages_Rsvd", &HugePages_Rsvd);
104 + //arl_expect(arl_base, "HugePages_Surp", &HugePages_Surp);
105 + //arl_expect(arl_base, "Hugepagesize", &Hugepagesize);
106 + //arl_expect(arl_base, "DirectMap4k", &DirectMap4k);
107 + //arl_expect(arl_base, "DirectMap2M", &DirectMap2M);
108 + }
109 +
110 + if(unlikely(!ff)) {
111 + char filename[FILENAME_MAX + 1];
112 + snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/meminfo");
113 + ff = procfile_open(config_get("plugin:proc:/proc/meminfo", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
114 + if(unlikely(!ff))
115 + return 1;
116 + }
117 +
118 + ff = procfile_readall(ff);
119 + if(unlikely(!ff))
120 + return 0; // we return 0, so that we will retry to open it next time
121 +
122 + size_t lines = procfile_lines(ff), l;
123 +
124 + arl_begin(arl_base);
125 +
126 for(l = 0; l < lines ;l++) {
127 size_t words = procfile_linewords(ff, l);
128 if(unlikely(words < 2)) continue;
129
168 - char *name = procfile_lineword(ff, l, 0);
169 - uint32_t hash = simple_hash(name);
170 -
171 - if(hash == MemTotal_hash && strsame(name, "MemTotal") == 0) value = &MemTotal;
172 - else if(hash == MemFree_hash && strsame(name, "MemFree") == 0) value = &MemFree;
173 - else if(hash == Buffers_hash && strsame(name, "Buffers") == 0) value = &Buffers;
174 - else if(hash == Cached_hash && strsame(name, "Cached") == 0) value = &Cached;
175 - //else if(hash == SwapCached_hash && strsame(name, "SwapCached") == 0) value = &SwapCached;
176 - //else if(hash == Active_hash && strsame(name, "Active") == 0) value = &Active;
177 - //else if(hash == Inactive_hash && strsame(name, "Inactive") == 0) value = &Inactive;
178 - //else if(hash == ActiveAnon_hash && strsame(name, "ActiveAnon") == 0) value = &ActiveAnon;
179 - //else if(hash == InactiveAnon_hash && strsame(name, "InactiveAnon") == 0) value = &InactiveAnon;
180 - //else if(hash == ActiveFile_hash && strsame(name, "ActiveFile") == 0) value = &ActiveFile;
181 - //else if(hash == InactiveFile_hash && strsame(name, "InactiveFile") == 0) value = &InactiveFile;
182 - //else if(hash == Unevictable_hash && strsame(name, "Unevictable") == 0) value = &Unevictable;
183 - //else if(hash == Mlocked_hash && strsame(name, "Mlocked") == 0) value = &Mlocked;
184 - else if(hash == SwapTotal_hash && strsame(name, "SwapTotal") == 0) value = &SwapTotal;
185 - else if(hash == SwapFree_hash && strsame(name, "SwapFree") == 0) value = &SwapFree;
186 - else if(hash == Dirty_hash && strsame(name, "Dirty") == 0) value = &Dirty;
187 - else if(hash == Writeback_hash && strsame(name, "Writeback") == 0) value = &Writeback;
188 - //else if(hash == AnonPages_hash && strsame(name, "AnonPages") == 0) value = &AnonPages;
189 - //else if(hash == Mapped_hash && strsame(name, "Mapped") == 0) value = &Mapped;
190 - //else if(hash == Shmem_hash && strsame(name, "Shmem") == 0) value = &Shmem;
191 - else if(hash == Slab_hash && strsame(name, "Slab") == 0) value = &Slab;
192 - else if(hash == SReclaimable_hash && strsame(name, "SReclaimable") == 0) value = &SReclaimable;
193 - else if(hash == SUnreclaim_hash && strsame(name, "SUnreclaim") == 0) value = &SUnreclaim;
194 - else if(hash == KernelStack_hash && strsame(name, "KernelStack") == 0) value = &KernelStack;
195 - else if(hash == PageTables_hash && strsame(name, "PageTables") == 0) value = &PageTables;
196 - else if(hash == NFS_Unstable_hash && strsame(name, "NFS_Unstable") == 0) value = &NFS_Unstable;
197 - else if(hash == Bounce_hash && strsame(name, "Bounce") == 0) value = &Bounce;
198 - else if(hash == WritebackTmp_hash && strsame(name, "WritebackTmp") == 0) value = &WritebackTmp;
199 - //else if(hash == CommitLimit_hash && strsame(name, "CommitLimit") == 0) value = &CommitLimit;
200 - else if(hash == Committed_AS_hash && strsame(name, "Committed_AS") == 0) value = &Committed_AS;
201 - //else if(hash == VmallocTotal_hash && strsame(name, "VmallocTotal") == 0) value = &VmallocTotal;
202 - else if(hash == VmallocUsed_hash && strsame(name, "VmallocUsed") == 0) value = &VmallocUsed;
203 - //else if(hash == VmallocChunk_hash && strsame(name, "VmallocChunk") == 0) value = &VmallocChunk;
204 - else if(hash == HardwareCorrupted_hash && strsame(name, "HardwareCorrupted") == 0) { value = &HardwareCorrupted; hwcorrupted = 1; }
205 - //else if(hash == AnonHugePages_hash && strsame(name, "AnonHugePages") == 0) value = &AnonHugePages;
206 - //else if(hash == HugePages_Total_hash && strsame(name, "HugePages_Total") == 0) value = &HugePages_Total;
207 - //else if(hash == HugePages_Free_hash && strsame(name, "HugePages_Free") == 0) value = &HugePages_Free;
208 - //else if(hash == HugePages_Rsvd_hash && strsame(name, "HugePages_Rsvd") == 0) value = &HugePages_Rsvd;
209 - //else if(hash == HugePages_Surp_hash && strsame(name, "HugePages_Surp") == 0) value = &HugePages_Surp;
210 - //else if(hash == Hugepagesize_hash && strsame(name, "Hugepagesize") == 0) value = &Hugepagesize;
211 - //else if(hash == DirectMap4k_hash && strsame(name, "DirectMap4k") == 0) value = &DirectMap4k;
212 - //else if(hash == DirectMap2M_hash && strsame(name, "DirectMap2M") == 0) value = &DirectMap2M;
213 -
214 - if(value) {
215 - *value = str2ull(procfile_lineword(ff, l, 1));
216 - value = NULL;
217 - }
130 + if(unlikely(arl_check(arl_base,
131 + procfile_lineword(ff, l, 0),
132 + procfile_lineword(ff, l, 1)))) break;
133 }
134
135 RRDSET *st;
@@ -267,7 +182,7 @@ int do_proc_meminfo(int update_every, usec_t dt) {
182
183 // --------------------------------------------------------------------
184
270 - if(hwcorrupted && (do_hwcorrupt == CONFIG_ONDEMAND_YES || (do_hwcorrupt == CONFIG_ONDEMAND_ONDEMAND && HardwareCorrupted > 0))) {
185 + if(arl_hwcorrupted->flags & ARL_ENTRY_FLAG_FOUND && (do_hwcorrupt == CONFIG_ONDEMAND_YES || (do_hwcorrupt == CONFIG_ONDEMAND_ONDEMAND && HardwareCorrupted > 0))) {
186 do_hwcorrupt = CONFIG_ONDEMAND_YES;
187
188 st = rrdset_find("mem.hwcorrupt");
src/proc_net_snmp6.c
+2 -1
@@ -1,5 +1,4 @@
1 #include "common.h"
2 -#include "adaptive_resortable_list.h"
2
3 #define RRD_TYPE_NET_SNMP6 "ipv6"
4
@@ -259,6 +258,8 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
258
259 size_t lines = procfile_lines(ff), l;
260
261 + arl_begin(arl_base);
262 +
263 for(l = 0; l < lines ;l++) {
264 size_t words = procfile_linewords(ff, l);
265 if(unlikely(words < 2)) {
src/proc_vmstat.c
-1
@@ -1,5 +1,4 @@
1 #include "common.h"
2 -#include "adaptive_resortable_list.h"
2
3 int do_proc_vmstat(int update_every, usec_t dt) {
4 (void)dt;
src/sys_fs_cgroup.c
-1
@@ -1,5 +1,4 @@
1 #include "common.h"
2 -#include "adaptive_resortable_list.h"
2
3 // ----------------------------------------------------------------------------
4 // cgroup globals