sys_block_zram: don't use "/dev" (#17900)
sys_block_zram: don't use /dev
Ilya Mashchenko committed
Jun 14, 2024 at 19:52 UTC
e32c498941d5d92b4695626e805c84802c018038
1 file changed
+20
-25
src/collectors/proc.plugin/sys_block_zram.c
+20
-25
@@ -62,7 +62,7 @@ static inline void init_rrd(const char *name, ZRAM_DEVICE *d, int update_every)
62
"mem"
63
, chart_name
64
, chart_name
65
- , name
65
+ , "zram"
66
, "mem.zram_usage"
67
, "ZRAM Memory Usage"
68
, "MiB"
@@ -80,7 +80,7 @@ static inline void init_rrd(const char *name, ZRAM_DEVICE *d, int update_every)
80
"mem"
81
, chart_name
82
, chart_name
83
- , name
83
+ , "zram"
84
, "mem.zram_savings"
85
, "ZRAM Memory Savings"
86
, "MiB"
@@ -98,7 +98,7 @@ static inline void init_rrd(const char *name, ZRAM_DEVICE *d, int update_every)
98
"mem"
99
, chart_name
100
, chart_name
101
- , name
101
+ , "zram"
102
, "mem.zram_ratio"
103
, "ZRAM Compression Ratio (original to compressed)"
104
, "ratio"
@@ -115,7 +115,7 @@ static inline void init_rrd(const char *name, ZRAM_DEVICE *d, int update_every)
115
"mem"
116
, chart_name
117
, chart_name
118
- , name
118
+ , "zram"
119
, "mem.zram_efficiency"
120
, "ZRAM Efficiency"
121
, "percentage"
@@ -136,36 +136,31 @@ static int init_devices(DICTIONARY *devices, unsigned int zram_id, int update_ev
136
ZRAM_DEVICE device;
137
char filename[FILENAME_MAX + 1];
138
139
- snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/dev");
139
+ snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/block");
140
DIR *dir = opendir(filename);
141
142
if (unlikely(!dir))
143
return 0;
144
- while ((de = readdir(dir)))
145
- {
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));
144
+
145
+ while ((de = readdir(dir))) {
146
+ snprintfz(filename, FILENAME_MAX, "%s/sys/block/%s/mm_stat", netdata_configured_host_prefix, de->d_name);
147
+ if (unlikely(stat(filename, &st) != 0)) {
148
continue;
149
}
152
- if (major(st.st_rdev) == zram_id)
153
- {
154
- collector_info("ZRAM : Found device %s", filename);
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
- {
159
- collector_error("ZRAM : Failed to open %s: %s", filename, strerror(errno));
160
- continue;
161
- }
162
- device.file = ff;
163
- init_rrd(de->d_name, &device, update_every);
164
- dictionary_set(devices, de->d_name, &device, sizeof(ZRAM_DEVICE));
165
- count++;
150
+ ff = procfile_open(filename, " \t:", PROCFILE_FLAG_DEFAULT);
151
+ if (ff == NULL) {
152
+ collector_error("ZRAM : Failed to open %s: %s", filename, strerror(errno));
153
+ continue;
154
}
155
+
156
+ device.file = ff;
157
+ init_rrd(de->d_name, &device, update_every);
158
+ dictionary_set(devices, de->d_name, &device, sizeof(ZRAM_DEVICE));
159
+ count++;
160
}
161
+
162
closedir(dir);
163
+
164
return count;
165
}
166