Skip to content

Commit 44bf2d2

Browse files
committed
in_node_exporter_metrics: add file path to error messages
Improve error logs to indicate which file path failed when reading metrics, making it easier to debug missing hardware sensors or permissions issues. Signed-off-by: Ross Golder <ross@golder.org>
1 parent f6126eb commit 44bf2d2

17 files changed

Lines changed: 79 additions & 48 deletions

plugins/in_node_exporter_metrics/ne_cpu_linux.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int cpu_thermal_update(struct flb_ne *ctx, uint64_t ts)
112112
entry = mk_list_entry(head, struct flb_slist_entry, _head);
113113

114114
/* Core ID */
115-
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
115+
ret = ne_utils_file_read_uint64(ctx, ctx->path_sysfs,
116116
entry->str,
117117
"topology", "core_id",
118118
&core_id);
@@ -121,7 +121,7 @@ static int cpu_thermal_update(struct flb_ne *ctx, uint64_t ts)
121121
}
122122

123123
/* Physical ID */
124-
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
124+
ret = ne_utils_file_read_uint64(ctx, ctx->path_sysfs,
125125
entry->str,
126126
"topology", "physical_package_id",
127127
&physical_package_id);
@@ -130,7 +130,7 @@ static int cpu_thermal_update(struct flb_ne *ctx, uint64_t ts)
130130
}
131131

132132
/* Package Metric: node_cpu_core_throttles_total */
133-
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
133+
ret = ne_utils_file_read_uint64(ctx, ctx->path_sysfs,
134134
entry->str,
135135
"thermal_throttle", "core_throttle_count",
136136
&core_throttle_count);
@@ -150,7 +150,7 @@ static int cpu_thermal_update(struct flb_ne *ctx, uint64_t ts)
150150
}
151151

152152
/* Package Metric: node_cpu_package_throttles_total */
153-
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
153+
ret = ne_utils_file_read_uint64(ctx, ctx->path_sysfs,
154154
entry->str,
155155
"thermal_throttle", "package_throttle_count",
156156
&package_throttle_count);
@@ -307,7 +307,7 @@ static int cpu_stat_update(struct flb_ne *ctx, uint64_t ts)
307307
struct flb_slist_entry *line;
308308
struct cpu_stat_info st = {0};
309309

310-
ret = ne_utils_file_read_lines(ctx->path_procfs, "/stat", &list);
310+
ret = ne_utils_file_read_lines(ctx, ctx->path_procfs, "/stat", &list);
311311
if (ret == -1) {
312312
return -1;
313313
}

plugins/in_node_exporter_metrics/ne_cpufreq_linux.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int cpufreq_update(struct flb_ne *ctx)
118118
cpu_id++;
119119

120120
/* node_cpu_frequency_hertz */
121-
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
121+
ret = ne_utils_file_read_uint64(ctx, ctx->path_sysfs,
122122
entry->str, "cpufreq", "cpuinfo_cur_freq",
123123
&val);
124124
if (ret == 0) {
@@ -128,7 +128,7 @@ static int cpufreq_update(struct flb_ne *ctx)
128128
}
129129

130130
/* node_cpu_frequency_max_hertz */
131-
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
131+
ret = ne_utils_file_read_uint64(ctx, ctx->path_sysfs,
132132
entry->str, "cpufreq", "cpuinfo_max_freq",
133133
&val);
134134
if (ret == 0) {
@@ -138,7 +138,7 @@ static int cpufreq_update(struct flb_ne *ctx)
138138
}
139139

140140
/* node_cpu_frequency_min_hertz */
141-
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
141+
ret = ne_utils_file_read_uint64(ctx, ctx->path_sysfs,
142142
entry->str, "cpufreq", "cpuinfo_min_freq",
143143
&val);
144144
if (ret == 0) {
@@ -149,7 +149,7 @@ static int cpufreq_update(struct flb_ne *ctx)
149149

150150

151151
/* node_cpu_scaling_frequency_hertz */
152-
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
152+
ret = ne_utils_file_read_uint64(ctx, ctx->path_sysfs,
153153
entry->str, "cpufreq", "scaling_cur_freq",
154154
&val);
155155
if (ret == 0) {
@@ -159,7 +159,7 @@ static int cpufreq_update(struct flb_ne *ctx)
159159
}
160160

161161
/* node_cpu_scaling_frequency_max_hertz */
162-
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
162+
ret = ne_utils_file_read_uint64(ctx, ctx->path_sysfs,
163163
entry->str, "cpufreq", "scaling_max_freq",
164164
&val);
165165
if (ret == 0) {
@@ -169,7 +169,7 @@ static int cpufreq_update(struct flb_ne *ctx)
169169
}
170170

171171
/* node_cpu_frequency_min_hertz */
172-
ret = ne_utils_file_read_uint64(ctx->path_sysfs,
172+
ret = ne_utils_file_read_uint64(ctx, ctx->path_sysfs,
173173
entry->str, "cpufreq", "scaling_min_freq",
174174
&val);
175175
if (ret == 0) {

plugins/in_node_exporter_metrics/ne_diskstats_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static int diskstats_update(struct flb_ne *ctx)
404404
mk_list_init(&list);
405405
mk_list_init(&split_list);
406406

407-
ret = ne_utils_file_read_lines(ctx->path_procfs, "/diskstats", &list);
407+
ret = ne_utils_file_read_lines(ctx, ctx->path_procfs, "/diskstats", &list);
408408
if (ret == -1) {
409409
return -1;
410410
}

plugins/in_node_exporter_metrics/ne_filefd_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int filefd_update(struct flb_ne *ctx)
5858
struct flb_slist_entry *max;
5959

6060
mk_list_init(&list);
61-
ret = ne_utils_file_read_lines(ctx->path_procfs, "/sys/fs/file-nr", &list);
61+
ret = ne_utils_file_read_lines(ctx, ctx->path_procfs, "/sys/fs/file-nr", &list);
6262
if (ret == -1) {
6363
return -1;
6464
}

plugins/in_node_exporter_metrics/ne_hwmon_linux.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ static void hwmon_process_sensor(struct flb_ne *ctx, const char *chip_path,
185185
}
186186

187187
/* read input value */
188-
ret = ne_utils_file_read_uint64(ctx->path_sysfs, sensor_path,
188+
ret = ne_utils_file_read_uint64(ctx, ctx->path_sysfs, sensor_path,
189189
NULL, NULL, &val);
190190
if (ret != 0) {
191191
return;
192192
}
193193

194194
snprintf(label_name, sizeof(label_name) - 1, "%s_label", sensor_name);
195-
if (ne_utils_file_read_sds(ctx->path_sysfs, chip_path,
195+
if (ne_utils_file_read_sds(ctx, ctx->path_sysfs, chip_path,
196196
label_name, NULL, &label) == 0) {
197197
sensor_label = label;
198198
}
@@ -206,15 +206,15 @@ static void hwmon_process_sensor(struct flb_ne *ctx, const char *chip_path,
206206
2, (char *[]) {(char *) chip_name, (char *) sensor_label});
207207

208208
snprintf(file_tmp, sizeof(file_tmp) - 1, "%s_max", sensor_name);
209-
if (ne_utils_file_read_uint64(ctx->path_sysfs, chip_path,
209+
if (ne_utils_file_read_uint64(ctx, ctx->path_sysfs, chip_path,
210210
file_tmp, NULL, &val) == 0) {
211211
cmt_gauge_set(ctx->hwmon_temp_max_celsius, tstamp,
212212
((double) val) / 1000.0,
213213
2, (char *[]) {(char *) chip_name, (char *) sensor_label});
214214
}
215215

216216
snprintf(file_tmp, sizeof(file_tmp) - 1, "%s_crit", sensor_name);
217-
if (ne_utils_file_read_uint64(ctx->path_sysfs, chip_path,
217+
if (ne_utils_file_read_uint64(ctx, ctx->path_sysfs, chip_path,
218218
file_tmp, NULL, &val) == 0) {
219219
cmt_gauge_set(ctx->hwmon_temp_crit_celsius, tstamp,
220220
((double) val) / 1000.0,
@@ -269,7 +269,7 @@ static int ne_hwmon_update(struct flb_input_instance *ins,
269269
mk_list_foreach(head, &hwmons) {
270270
entry = mk_list_entry(head, struct flb_slist_entry, _head);
271271

272-
if (ne_utils_file_read_sds(ctx->path_sysfs, entry->str,
272+
if (ne_utils_file_read_sds(ctx, ctx->path_sysfs, entry->str,
273273
"name", NULL, &chip) != 0) {
274274
continue;
275275
}

plugins/in_node_exporter_metrics/ne_loadavg_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int loadavg_update(struct flb_ne *ctx)
6767
mk_list_init(&list);
6868
mk_list_init(&split_list);
6969

70-
ret = ne_utils_file_read_lines(ctx->path_procfs, "/loadavg", &list);
70+
ret = ne_utils_file_read_lines(ctx, ctx->path_procfs, "/loadavg", &list);
7171
if (ret == -1) {
7272
return -1;
7373
}

plugins/in_node_exporter_metrics/ne_meminfo_linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int meminfo_configure(struct flb_ne *ctx)
5353
mk_list_init(&list);
5454
mk_list_init(&split_list);
5555

56-
ret = ne_utils_file_read_lines(ctx->path_procfs, "/meminfo", &list);
56+
ret = ne_utils_file_read_lines(ctx, ctx->path_procfs, "/meminfo", &list);
5757
if (ret == -1) {
5858
return -1;
5959
}
@@ -206,7 +206,7 @@ static int meminfo_update(struct flb_ne *ctx)
206206
struct flb_slist_entry *entry;
207207

208208
mk_list_init(&list);
209-
ret = ne_utils_file_read_lines(ctx->path_procfs, "/meminfo", &list);
209+
ret = ne_utils_file_read_lines(ctx, ctx->path_procfs, "/meminfo", &list);
210210
if (ret == -1) {
211211
return -1;
212212
}

plugins/in_node_exporter_metrics/ne_netdev_linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int netdev_configure(struct flb_ne *ctx)
9898
mk_list_init(&rx_list);
9999
mk_list_init(&tx_list);
100100

101-
ret = ne_utils_file_read_lines(ctx->path_procfs, "/net/dev", &list);
101+
ret = ne_utils_file_read_lines(ctx, ctx->path_procfs, "/net/dev", &list);
102102
if (ret == -1) {
103103
return -1;
104104
}
@@ -236,7 +236,7 @@ static int netdev_update(struct flb_ne *ctx)
236236
mk_list_init(&rx_list);
237237
mk_list_init(&tx_list);
238238

239-
ret = ne_utils_file_read_lines(ctx->path_procfs, "/net/dev", &list);
239+
ret = ne_utils_file_read_lines(ctx, ctx->path_procfs, "/net/dev", &list);
240240
if (ret == -1) {
241241
return -1;
242242
}

plugins/in_node_exporter_metrics/ne_netstat_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static int netstat_update(struct flb_ne *ctx)
215215
int prev_proto;
216216

217217
mk_list_init(&list);
218-
ret = ne_utils_file_read_lines(ctx->path_procfs, "/net/snmp", &list);
218+
ret = ne_utils_file_read_lines(ctx, ctx->path_procfs, "/net/snmp", &list);
219219
if (ret == -1) {
220220
return -1;
221221
}

plugins/in_node_exporter_metrics/ne_nvme_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static int nvme_get_entry_value(struct flb_ne *ctx,
105105
if (check_path_for_sysfs(ctx, nvme_info->str, entry_path) != 0) {
106106
return -1;
107107
}
108-
ret = ne_utils_file_read_lines(nvme_info->str, nvme_sysentry, out_info_list);
108+
ret = ne_utils_file_read_lines(ctx, nvme_info->str, nvme_sysentry, out_info_list);
109109
if (ret == -1) {
110110
return ret;
111111
}

0 commit comments

Comments
 (0)