Skip to content

Commit

Permalink
sys_block_zram: don't use "/dev" (netdata#17900)
Browse files Browse the repository at this point in the history
sys_block_zram: don't use /dev
  • Loading branch information
ilyam8 authored Jun 14, 2024
1 parent 3c507b4 commit e32c498
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions src/collectors/proc.plugin/sys_block_zram.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static inline void init_rrd(const char *name, ZRAM_DEVICE *d, int update_every)
"mem"
, chart_name
, chart_name
, name
, "zram"
, "mem.zram_usage"
, "ZRAM Memory Usage"
, "MiB"
Expand All @@ -80,7 +80,7 @@ static inline void init_rrd(const char *name, ZRAM_DEVICE *d, int update_every)
"mem"
, chart_name
, chart_name
, name
, "zram"
, "mem.zram_savings"
, "ZRAM Memory Savings"
, "MiB"
Expand All @@ -98,7 +98,7 @@ static inline void init_rrd(const char *name, ZRAM_DEVICE *d, int update_every)
"mem"
, chart_name
, chart_name
, name
, "zram"
, "mem.zram_ratio"
, "ZRAM Compression Ratio (original to compressed)"
, "ratio"
Expand All @@ -115,7 +115,7 @@ static inline void init_rrd(const char *name, ZRAM_DEVICE *d, int update_every)
"mem"
, chart_name
, chart_name
, name
, "zram"
, "mem.zram_efficiency"
, "ZRAM Efficiency"
, "percentage"
Expand All @@ -136,36 +136,31 @@ static int init_devices(DICTIONARY *devices, unsigned int zram_id, int update_ev
ZRAM_DEVICE device;
char filename[FILENAME_MAX + 1];

snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/dev");
snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/block");
DIR *dir = opendir(filename);

if (unlikely(!dir))
return 0;
while ((de = readdir(dir)))
{
snprintfz(filename, FILENAME_MAX, "%s/dev/%s", netdata_configured_host_prefix, de->d_name);
if (unlikely(stat(filename, &st) != 0))
{
collector_error("ZRAM : Unable to stat %s: %s", filename, strerror(errno));

while ((de = readdir(dir))) {
snprintfz(filename, FILENAME_MAX, "%s/sys/block/%s/mm_stat", netdata_configured_host_prefix, de->d_name);
if (unlikely(stat(filename, &st) != 0)) {
continue;
}
if (major(st.st_rdev) == zram_id)
{
collector_info("ZRAM : Found device %s", filename);
snprintfz(filename, FILENAME_MAX, "%s/sys/block/%s/mm_stat", netdata_configured_host_prefix, de->d_name);
ff = procfile_open(filename, " \t:", PROCFILE_FLAG_DEFAULT);
if (ff == NULL)
{
collector_error("ZRAM : Failed to open %s: %s", filename, strerror(errno));
continue;
}
device.file = ff;
init_rrd(de->d_name, &device, update_every);
dictionary_set(devices, de->d_name, &device, sizeof(ZRAM_DEVICE));
count++;
ff = procfile_open(filename, " \t:", PROCFILE_FLAG_DEFAULT);
if (ff == NULL) {
collector_error("ZRAM : Failed to open %s: %s", filename, strerror(errno));
continue;
}

device.file = ff;
init_rrd(de->d_name, &device, update_every);
dictionary_set(devices, de->d_name, &device, sizeof(ZRAM_DEVICE));
count++;
}

closedir(dir);

return count;
}

Expand Down

0 comments on commit e32c498

Please sign in to comment.