fix /sys/block/zram in docker (#14759)
Ilya Mashchenko committed
Mar 20, 2023 at 17:06 UTC
6f15318bb3ebb4cb09bf95dbea1932545e32473f
1 file changed
+12
-6
collectors/proc.plugin/sys_block_zram.c
+12
-6
@@ -130,18 +130,20 @@ static inline void init_rrd(const char *name, ZRAM_DEVICE *d, int update_every)
130
131
static int init_devices(DICTIONARY *devices, unsigned int zram_id, int update_every) {
132
int count = 0;
133
- DIR *dir = opendir("/dev");
133
struct dirent *de;
134
struct stat st;
136
- char filename[FILENAME_MAX + 1];
135
procfile *ff = NULL;
136
ZRAM_DEVICE device;
137
+ char filename[FILENAME_MAX + 1];
138
+
139
+ snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/dev");
140
+ DIR *dir = opendir(filename);
141
142
if (unlikely(!dir))
143
return 0;
144
while ((de = readdir(dir)))
145
{
144
- snprintfz(filename, FILENAME_MAX, "/dev/%s", de->d_name);
146
+ snprintfz(filename, FILENAME_MAX, "%s/dev/%s", netdata_configured_host_prefix, de->d_name);
147
if (unlikely(stat(filename, &st) != 0))
148
{
149
collector_error("ZRAM : Unable to stat %s: %s", filename, strerror(errno));
@@ -150,7 +152,7 @@ static int init_devices(DICTIONARY *devices, unsigned int zram_id, int update_ev
152
if (major(st.st_rdev) == zram_id)
153
{
154
collector_info("ZRAM : Found device %s", filename);
153
- snprintfz(filename, FILENAME_MAX, "/sys/block/%s/mm_stat", de->d_name);
155
+ snprintfz(filename, FILENAME_MAX, "%s/sys/block/%s/mm_stat", netdata_configured_host_prefix, de->d_name);
156
ff = procfile_open(filename, " \t:", PROCFILE_FLAG_DEFAULT);
157
if (ff == NULL)
158
{
@@ -249,10 +251,14 @@ int do_sys_block_zram(int update_every, usec_t dt) {
251
if (unlikely(!initialized))
252
{
253
initialized = 1;
252
- ff = procfile_open("/proc/devices", " \t:", PROCFILE_FLAG_DEFAULT);
254
+
255
+ char filename[FILENAME_MAX + 1];
256
+ snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/devices");
257
+
258
+ ff = procfile_open(filename, " \t:", PROCFILE_FLAG_DEFAULT);
259
if (ff == NULL)
260
{
255
- collector_error("Cannot read /proc/devices");
261
+ collector_error("Cannot read %s", filename);
262
return 1;
263
}
264
ff = procfile_readall(ff);