5 char *numastat_filename;
10 static struct node *numa_root = NULL;
12 static int find_all_nodes() {
13 int numa_node_count = 0;
14 char name[FILENAME_MAX + 1];
15 snprintfz(name, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/devices/system/node");
16 char *dirname = config_get("plugin:proc:/sys/devices/system/node", "directory to monitor", name);
18 DIR *dir = opendir(dirname);
20 error("Cannot read NUMA node directory '%s'", dirname);
24 struct dirent *de = NULL;
25 while((de = readdir(dir))) {
26 if(de->d_type != DT_DIR)
29 if(strncmp(de->d_name, "node", 4) != 0)
32 if(!isdigit(de->d_name[4]))
37 struct node *m = callocz(1, sizeof(struct node));
38 m->name = strdupz(de->d_name);
42 snprintfz(name, FILENAME_MAX, "%s/%s/numastat", dirname, de->d_name);
43 if(stat(name, &st) == -1) {
49 m->numastat_filename = strdupz(name);
57 return numa_node_count;
60 int do_proc_sys_devices_system_node(int update_every, usec_t dt) {
63 static int numa_node_count = 0;
65 if(unlikely(numa_root == NULL)) {
66 numa_node_count = find_all_nodes(update_every);
67 if(unlikely(numa_root == NULL))
71 static int do_numastat = -1;
74 if(unlikely(do_numastat == -1)) {
75 do_numastat = config_get_boolean_ondemand("plugin:proc:/sys/devices/system/node", "enable per-node numa metrics", CONFIG_ONDEMAND_ONDEMAND);
78 if(do_numastat == CONFIG_ONDEMAND_YES || (do_numastat == CONFIG_ONDEMAND_ONDEMAND && numa_node_count >= 2)) {
79 for(m = numa_root; m; m = m->next) {
80 if(m->numastat_filename) {
81 if(unlikely(!m->numastat_ff)) {
82 m->numastat_ff = procfile_open(m->numastat_filename, " ", PROCFILE_FLAG_DEFAULT);
83 if(unlikely(!m->numastat_ff))
87 m->numastat_ff = procfile_readall(m->numastat_ff);
88 if(unlikely(!m->numastat_ff || procfile_lines(m->numastat_ff) < 1 || procfile_linewords(m->numastat_ff, 0) < 1))
91 procfile *ff = m->numastat_ff;
93 RRDSET *st = m->numastat_st;
95 st = rrdset_create("mem", m->name, NULL, "numa", NULL, "NUMA events", "events/s", 1000, update_every, RRDSET_TYPE_LINE);
98 rrddim_add(st, "local_node", "local", 1, 1, RRDDIM_INCREMENTAL);
99 rrddim_add(st, "numa_foreign", "foreign", 1, 1, RRDDIM_INCREMENTAL);
100 rrddim_add(st, "interleave_hit", "interleave", 1, 1, RRDDIM_INCREMENTAL);
101 rrddim_add(st, "other_node", "other", 1, 1, RRDDIM_INCREMENTAL);
105 else rrdset_next(st);
107 uint32_t lines = procfile_lines(ff), l;
108 for(l = 0; l < lines; l++) {
109 uint32_t words = procfile_linewords(ff, l);
110 if(unlikely(words < 2)) {
111 if(unlikely(words)) error("Cannot read %s numastat line %u. Expected 2 params, read %u.", m->name, l, words);
115 char *name = procfile_lineword(ff, l, 0);
116 char *value = procfile_lineword(ff, l, 1);
117 if (unlikely(!name || !*name || !value || !*value)) continue;
119 rrddim_set(st, name, strtoull(value, NULL, 10));