Skip to content

Commit 8464be0

Browse files
committed
in_node_exporter_metrics: add new option path.rootfs
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent 4ec16dd commit 8464be0

6 files changed

Lines changed: 68 additions & 5 deletions

File tree

plugins/in_node_exporter_metrics/ne.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ static struct flb_config_map config_map[] = {
449449
"Specify file path or directory to collect textfile metrics from the node."
450450
},
451451

452+
{
453+
FLB_CONFIG_MAP_STR, "path.rootfs", "/",
454+
0, FLB_TRUE, offsetof(struct flb_ne, path_rootfs),
455+
"rootfs mount point"
456+
},
457+
452458
{
453459
FLB_CONFIG_MAP_STR, "path.procfs", "/proc",
454460
0, FLB_TRUE, offsetof(struct flb_ne, path_procfs),

plugins/in_node_exporter_metrics/ne.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
struct flb_ne {
5050
/* configuration */
51+
flb_sds_t path_rootfs;
5152
flb_sds_t path_procfs;
5253
flb_sds_t path_sysfs;
5354
flb_sds_t path_textfile;

plugins/in_node_exporter_metrics/ne_config.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct flb_ne *flb_ne_config_create(struct flb_input_instance *ins,
2424
struct flb_config *config)
2525
{
2626
int ret;
27+
int root_len;
28+
flb_sds_t tmp;
2729
struct flb_ne *ctx;
2830

2931
ctx = flb_calloc(1, sizeof(struct flb_ne));
@@ -41,6 +43,59 @@ struct flb_ne *flb_ne_config_create(struct flb_input_instance *ins,
4143
}
4244

4345
/* mount points */
46+
flb_plg_info(ins, "path.rootfs = %s", ctx->path_rootfs);
47+
48+
if (ctx->path_rootfs && strcmp(ctx->path_rootfs, "/") != 0) {
49+
root_len = strlen(ctx->path_rootfs);
50+
if (root_len > 1 && ctx->path_rootfs[root_len - 1] == '/') {
51+
root_len--;
52+
}
53+
54+
/* Compose procfs path */
55+
tmp = flb_sds_create_size(1024);
56+
if (tmp) {
57+
if (ctx->path_procfs[0] == '/') {
58+
tmp = flb_sds_printf(&tmp, "%.*s%s", root_len, ctx->path_rootfs, ctx->path_procfs);
59+
}
60+
else {
61+
tmp = flb_sds_printf(&tmp, "%.*s/%s", root_len, ctx->path_rootfs, ctx->path_procfs);
62+
}
63+
if (tmp) {
64+
ctx->path_procfs = tmp;
65+
}
66+
}
67+
68+
/* Compose sysfs path */
69+
tmp = flb_sds_create_size(1024);
70+
if (tmp) {
71+
if (ctx->path_sysfs[0] == '/') {
72+
tmp = flb_sds_printf(&tmp, "%.*s%s", root_len, ctx->path_rootfs, ctx->path_sysfs);
73+
}
74+
else {
75+
tmp = flb_sds_printf(&tmp, "%.*s/%s", root_len, ctx->path_rootfs, ctx->path_sysfs);
76+
}
77+
if (tmp) {
78+
ctx->path_sysfs = tmp;
79+
}
80+
}
81+
82+
/* Compose textfile path if any */
83+
if (ctx->path_textfile) {
84+
tmp = flb_sds_create_size(1024);
85+
if (tmp) {
86+
if (ctx->path_textfile[0] == '/') {
87+
tmp = flb_sds_printf(&tmp, "%.*s%s", root_len, ctx->path_rootfs, ctx->path_textfile);
88+
}
89+
else {
90+
tmp = flb_sds_printf(&tmp, "%.*s/%s", root_len, ctx->path_rootfs, ctx->path_textfile);
91+
}
92+
if (tmp) {
93+
ctx->path_textfile = tmp;
94+
}
95+
}
96+
}
97+
}
98+
4499
flb_plg_info(ins, "path.procfs = %s", ctx->path_procfs);
45100
flb_plg_info(ins, "path.sysfs = %s", ctx->path_sysfs);
46101

plugins/in_node_exporter_metrics/ne_stat_linux.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static int stat_update(struct flb_ne *ctx)
8585
mk_list_init(&list);
8686
ret = ne_utils_file_read_lines(ctx->path_procfs, "/stat", &list);
8787
if (ret == -1) {
88+
flb_plg_error(ctx->ins, "failed to read %s/stat", ctx->path_procfs);
8889
return -1;
8990
}
9091

plugins/in_node_exporter_metrics/ne_utils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ int ne_utils_file_read_lines(const char *mount, const char *path, struct mk_list
196196
/*
197197
* Read a file and store the first line as a string.
198198
*/
199-
int ne_utils_file_read_sds(const char *mount,
200-
const char *path,
201-
const char *join_a,
199+
int ne_utils_file_read_sds(const char *mount,
200+
const char *path,
201+
const char *join_a,
202202
const char *join_b,
203203
flb_sds_t *str)
204204
{

plugins/in_node_exporter_metrics/ne_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ int ne_utils_file_read_uint64(const char *mount,
3535

3636
int ne_utils_file_read_sds(const char *mount,
3737
const char *path,
38-
const char *join_a,
39-
const char *join_b,
38+
const char *join_a,
39+
const char *join_b,
4040
flb_sds_t *str);
4141

4242
int ne_utils_file_read_lines(const char *mount, const char *path, struct mk_list *list);

0 commit comments

Comments
 (0)