1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
#include "common.h"
struct mc {
char *name;
char ce_updated;
char ue_updated;
char *ce_count_filename;
char *ue_count_filename;
procfile *ce_ff;
procfile *ue_ff;
collected_number ce_count;
collected_number ue_count;
RRDDIM *ce_rd;
RRDDIM *ue_rd;
struct mc *next;
};
static struct mc *mc_root = NULL;
static void find_all_mc() {
char name[FILENAME_MAX + 1];
snprintfz(name, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/devices/system/edac/mc");
char *dirname = config_get("plugin:proc:/sys/devices/system/edac/mc", "directory to monitor", name);
DIR *dir = opendir(dirname);
if(unlikely(!dir)) {
error("Cannot read ECC memory errors directory '%s'", dirname);
return;
}
struct dirent *de = NULL;
while((de = readdir(dir))) {
if(de->d_type == DT_DIR && de->d_name[0] == 'm' && de->d_name[1] == 'c' && isdigit(de->d_name[2])) {
struct mc *m = callocz(1, sizeof(struct mc));
m->name = strdupz(de->d_name);
struct stat st;
snprintfz(name, FILENAME_MAX, "%s/%s/ce_count", dirname, de->d_name);
if(stat(name, &st) != -1)
m->ce_count_filename = strdupz(name);
snprintfz(name, FILENAME_MAX, "%s/%s/ue_count", dirname, de->d_name);
if(stat(name, &st) != -1)
m->ue_count_filename = strdupz(name);
if(!m->ce_count_filename && !m->ue_count_filename) {
freez(m->name);
freez(m);
}
else {
m->next = mc_root;
mc_root = m;
}
}
}
closedir(dir);
}
int do_proc_sys_devices_system_edac_mc(int update_every, usec_t dt) {
(void)dt;
if(unlikely(mc_root == NULL)) {
find_all_mc();
if(unlikely(mc_root == NULL))
return 1;
}
static int do_ce = -1, do_ue = -1;
calculated_number ce_sum = 0, ue_sum = 0;
struct mc *m;
if(unlikely(do_ce == -1)) {
do_ce = config_get_boolean_ondemand("plugin:proc:/sys/devices/system/edac/mc", "enable ECC memory correctable errors", CONFIG_BOOLEAN_AUTO);
do_ue = config_get_boolean_ondemand("plugin:proc:/sys/devices/system/edac/mc", "enable ECC memory uncorrectable errors", CONFIG_BOOLEAN_AUTO);
}
if(do_ce != CONFIG_BOOLEAN_NO) {
for(m = mc_root; m; m = m->next) {
if(m->ce_count_filename) {
m->ce_updated = 0;
if(unlikely(!m->ce_ff)) {
m->ce_ff = procfile_open(m->ce_count_filename, " \t", PROCFILE_FLAG_DEFAULT);
if(unlikely(!m->ce_ff))
continue;
}
m->ce_ff = procfile_readall(m->ce_ff);
if(unlikely(!m->ce_ff || procfile_lines(m->ce_ff) < 1 || procfile_linewords(m->ce_ff, 0) < 1))
continue;
m->ce_count = str2ull(procfile_lineword(m->ce_ff, 0, 0));
ce_sum += m->ce_count;
m->ce_updated = 1;
}
}
}
if(do_ue != CONFIG_BOOLEAN_NO) {
for(m = mc_root; m; m = m->next) {
if(m->ue_count_filename) {
m->ue_updated = 0;
if(unlikely(!m->ue_ff)) {
m->ue_ff = procfile_open(m->ue_count_filename, " \t", PROCFILE_FLAG_DEFAULT);
if(unlikely(!m->ue_ff))
continue;
}
m->ue_ff = procfile_readall(m->ue_ff);
if(unlikely(!m->ue_ff || procfile_lines(m->ue_ff) < 1 || procfile_linewords(m->ue_ff, 0) < 1))
continue;
m->ue_count = str2ull(procfile_lineword(m->ue_ff, 0, 0));
ue_sum += m->ue_count;
m->ue_updated = 1;
}
}
}
// --------------------------------------------------------------------
if(do_ce == CONFIG_BOOLEAN_YES || (do_ce == CONFIG_BOOLEAN_AUTO && ce_sum > 0)) {
do_ce = CONFIG_BOOLEAN_YES;
static RRDSET *ce_st = NULL;
if(unlikely(!ce_st)) {
ce_st = rrdset_create_localhost(
"mem"
, "ecc_ce"
, NULL
, "ecc"
, NULL
, "ECC Memory Correctable Errors"
, "errors"
, "proc"
, "/sys/devices/system/edac/mc"
, 6600
, update_every
, RRDSET_TYPE_LINE
);
}
else
rrdset_next(ce_st);
for(m = mc_root; m; m = m->next) {
if (m->ce_count_filename && m->ce_updated) {
if(unlikely(!m->ce_rd))
m->ce_rd = rrddim_add(ce_st, m->name, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
rrddim_set_by_pointer(ce_st, m->ce_rd, m->ce_count);
}
}
rrdset_done(ce_st);
}
// --------------------------------------------------------------------
if(do_ue == CONFIG_BOOLEAN_YES || (do_ue == CONFIG_BOOLEAN_AUTO && ue_sum > 0)) {
do_ue = CONFIG_BOOLEAN_YES;
static RRDSET *ue_st = NULL;
if(unlikely(!ue_st)) {
ue_st = rrdset_create_localhost(
"mem"
, "ecc_ue"
, NULL
, "ecc"
, NULL
, "ECC Memory Uncorrectable Errors"
, "errors"
, "proc"
, "/sys/devices/system/edac/mc"
, 6610
, update_every
, RRDSET_TYPE_LINE
);
}
else
rrdset_next(ue_st);
for(m = mc_root; m; m = m->next) {
if (m->ue_count_filename && m->ue_updated) {
if(unlikely(!m->ue_rd))
m->ue_rd = rrddim_add(ue_st, m->name, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
rrddim_set_by_pointer(ue_st, m->ue_rd, m->ue_count);
}
}
rrdset_done(ue_st);
}
return 0;
}
|