@cryptotaxi247 / netdata-1 / commits / b34affaed

fix numa plugin to work only on the expected values; fixes #1868

Costa Tsaousis (ktsaou) committed Feb 28, 2017 at 00:23 UTC b34affaed52d794f5bd1cd209dfe711cc2de787e
1 file changed +58 -27
src/sys_devices_system_node.c
+58 -27
@@ -60,26 +60,34 @@ static int find_all_nodes() {
60 int do_proc_sys_devices_system_node(int update_every, usec_t dt) {
61 (void)dt;
62
63 - static int numa_node_count = 0;
63 + static uint32_t hash_local_node = 0, hash_numa_foreign = 0, hash_interleave_hit = 0, hash_other_node = 0, hash_numa_hit = 0, hash_numa_miss = 0;
64 + static int do_numastat = -1, numa_node_count = 0;
65 + struct node *m;
66
67 if(unlikely(numa_root == NULL)) {
66 - numa_node_count = find_all_nodes(update_every);
68 + numa_node_count = find_all_nodes();
69 if(unlikely(numa_root == NULL))
70 return 1;
71 }
72
71 - static int do_numastat = -1;
72 - struct node *m;
73 -
73 if(unlikely(do_numastat == -1)) {
74 do_numastat = config_get_boolean_ondemand("plugin:proc:/sys/devices/system/node", "enable per-node numa metrics", CONFIG_BOOLEAN_AUTO);
75 +
76 + hash_local_node = simple_hash("local_node");
77 + hash_numa_foreign = simple_hash("numa_foreign");
78 + hash_interleave_hit = simple_hash("interleave_hit");
79 + hash_other_node = simple_hash("other_node");
80 + hash_numa_hit = simple_hash("numa_hit");
81 + hash_numa_miss = simple_hash("numa_miss");
82 }
83
84 if(do_numastat == CONFIG_BOOLEAN_YES || (do_numastat == CONFIG_BOOLEAN_AUTO && numa_node_count >= 2)) {
85 for(m = numa_root; m; m = m->next) {
86 if(m->numastat_filename) {
87 +
88 if(unlikely(!m->numastat_ff)) {
89 m->numastat_ff = procfile_open(m->numastat_filename, " ", PROCFILE_FLAG_DEFAULT);
90 +
91 if(unlikely(!m->numastat_ff))
92 continue;
93 }
@@ -88,38 +96,61 @@ int do_proc_sys_devices_system_node(int update_every, usec_t dt) {
96 if(unlikely(!m->numastat_ff || procfile_lines(m->numastat_ff) < 1 || procfile_linewords(m->numastat_ff, 0) < 1))
97 continue;
98
91 - procfile *ff = m->numastat_ff;
99 + if(unlikely(!m->numastat_st)) {
100 + m->numastat_st = rrdset_create_localhost(
101 + "mem"
102 + , m->name
103 + , NULL
104 + , "numa"
105 + , NULL
106 + , "NUMA events"
107 + , "events/s"
108 + , 1000
109 + , update_every
110 + , RRDSET_TYPE_LINE
111 + );
112 +
113 + rrdset_flag_set(m->numastat_st, RRDSET_FLAG_DETAIL);
114 +
115 + rrddim_add(m->numastat_st, "numa_hit", "hit", 1, 1, RRD_ALGORITHM_INCREMENTAL);
116 + rrddim_add(m->numastat_st, "numa_miss", "miss", 1, 1, RRD_ALGORITHM_INCREMENTAL);
117 + rrddim_add(m->numastat_st, "local_node", "local", 1, 1, RRD_ALGORITHM_INCREMENTAL);
118 + rrddim_add(m->numastat_st, "numa_foreign", "foreign", 1, 1, RRD_ALGORITHM_INCREMENTAL);
119 + rrddim_add(m->numastat_st, "interleave_hit", "interleave", 1, 1, RRD_ALGORITHM_INCREMENTAL);
120 + rrddim_add(m->numastat_st, "other_node", "other", 1, 1, RRD_ALGORITHM_INCREMENTAL);
121
93 - RRDSET *st = m->numastat_st;
94 - if(unlikely(!st)) {
95 - st = rrdset_create_localhost("mem", m->name, NULL, "numa", NULL, "NUMA events", "events/s", 1000
96 - , update_every, RRDSET_TYPE_LINE);
97 - rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
98 -
99 - rrddim_add(st, "local_node", "local", 1, 1, RRD_ALGORITHM_INCREMENTAL);
100 - rrddim_add(st, "numa_foreign", "foreign", 1, 1, RRD_ALGORITHM_INCREMENTAL);
101 - rrddim_add(st, "interleave_hit", "interleave", 1, 1, RRD_ALGORITHM_INCREMENTAL);
102 - rrddim_add(st, "other_node", "other", 1, 1, RRD_ALGORITHM_INCREMENTAL);
103 -
104 - m->numastat_st = st;
122 }
106 - else rrdset_next(st);
123 + else rrdset_next(m->numastat_st);
124
108 - uint32_t lines = procfile_lines(ff), l;
125 + size_t lines = procfile_lines(m->numastat_ff), l;
126 for(l = 0; l < lines; l++) {
110 - uint32_t words = procfile_linewords(ff, l);
127 + size_t words = procfile_linewords(m->numastat_ff, l);
128 +
129 if(unlikely(words < 2)) {
112 - if(unlikely(words)) error("Cannot read %s numastat line %u. Expected 2 params, read %u.", m->name, l, words);
130 + if(unlikely(words))
131 + error("Cannot read %s numastat line %zu. Expected 2 params, read %zu.", m->name, l, words);
132 continue;
133 }
134
116 - char *name = procfile_lineword(ff, l, 0);
117 - char *value = procfile_lineword(ff, l, 1);
118 - if (unlikely(!name || !*name || !value || !*value)) continue;
135 + char *name = procfile_lineword(m->numastat_ff, l, 0);
136 + char *value = procfile_lineword(m->numastat_ff, l, 1);
137
120 - rrddim_set(st, name, strtoull(value, NULL, 10));
138 + if (unlikely(!name || !*name || !value || !*value))
139 + continue;
140 +
141 + uint32_t hash = simple_hash(name);
142 + if(likely(
143 + (hash == hash_numa_hit && !strcmp(name, "numa_hit"))
144 + || (hash == hash_numa_miss && !strcmp(name, "numa_miss"))
145 + || (hash == hash_local_node && !strcmp(name, "local_node"))
146 + || (hash == hash_numa_foreign && !strcmp(name, "numa_foreign"))
147 + || (hash == hash_interleave_hit && !strcmp(name, "interleave_hit"))
148 + || (hash == hash_other_node && !strcmp(name, "other_node"))
149 + ))
150 + rrddim_set(m->numastat_st, name, (collected_number)str2kernel_uint_t(value));
151 }
122 - rrdset_done(st);
152 +
153 + rrdset_done(m->numastat_st);
154 }
155 }
156 }