Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conf/fluent-bit-metrics.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
name node_exporter_metrics
tag node_metrics
scrape_interval 2
# use host root path when running in containers
# path.rootfs /host

[OUTPUT]
name prometheus_exporter
Expand Down
5 changes: 2 additions & 3 deletions docker_compose/node-exporter-dashboard/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ services:
fluentbit:
image: fluent/fluent-bit:latest
container_name: fluentbit
command: /fluent-bit/bin/fluent-bit -i node_exporter_metrics -p path.procfs=/host/proc -p path.sysfs=/host/sys -o prometheus_exporter -p "add_label=host fluentbit" -f 1
command: /fluent-bit/bin/fluent-bit -i node_exporter_metrics -p path.rootfs=/host -o prometheus_exporter -p "add_label=host fluentbit" -f 1
ports:
- 2021:2021
networks:
- exporter-network
volumes:
- /proc:/host/proc
- /sys:/host/sys
- /:/host:ro

grafana:
image: grafana/grafana:latest
Expand Down
6 changes: 6 additions & 0 deletions plugins/in_node_exporter_metrics/ne.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ static struct flb_config_map config_map[] = {
"Specify file path or directory to collect textfile metrics from the node."
},

{
FLB_CONFIG_MAP_STR, "path.rootfs", "/",
0, FLB_TRUE, offsetof(struct flb_ne, path_rootfs),
"rootfs mount point"
},

{
FLB_CONFIG_MAP_STR, "path.procfs", "/proc",
0, FLB_TRUE, offsetof(struct flb_ne, path_procfs),
Expand Down
1 change: 1 addition & 0 deletions plugins/in_node_exporter_metrics/ne.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

struct flb_ne {
/* configuration */
flb_sds_t path_rootfs;
flb_sds_t path_procfs;
flb_sds_t path_sysfs;
flb_sds_t path_textfile;
Expand Down
55 changes: 55 additions & 0 deletions plugins/in_node_exporter_metrics/ne_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct flb_ne *flb_ne_config_create(struct flb_input_instance *ins,
struct flb_config *config)
{
int ret;
int root_len;
flb_sds_t tmp;
struct flb_ne *ctx;

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

/* mount points */
flb_plg_info(ins, "path.rootfs = %s", ctx->path_rootfs);

if (ctx->path_rootfs && strcmp(ctx->path_rootfs, "/") != 0) {
root_len = strlen(ctx->path_rootfs);
if (root_len > 1 && ctx->path_rootfs[root_len - 1] == '/') {
root_len--;
}

/* Compose procfs path */
tmp = flb_sds_create_size(1024);
if (tmp) {
if (ctx->path_procfs[0] == '/') {
tmp = flb_sds_printf(&tmp, "%.*s%s", root_len, ctx->path_rootfs, ctx->path_procfs);
}
else {
tmp = flb_sds_printf(&tmp, "%.*s/%s", root_len, ctx->path_rootfs, ctx->path_procfs);
}
if (tmp) {
ctx->path_procfs = tmp;
}
}

/* Compose sysfs path */
tmp = flb_sds_create_size(1024);
if (tmp) {
if (ctx->path_sysfs[0] == '/') {
tmp = flb_sds_printf(&tmp, "%.*s%s", root_len, ctx->path_rootfs, ctx->path_sysfs);
}
else {
tmp = flb_sds_printf(&tmp, "%.*s/%s", root_len, ctx->path_rootfs, ctx->path_sysfs);
}
if (tmp) {
ctx->path_sysfs = tmp;
}
}

/* Compose textfile path if any */
if (ctx->path_textfile) {
tmp = flb_sds_create_size(1024);
if (tmp) {
if (ctx->path_textfile[0] == '/') {
tmp = flb_sds_printf(&tmp, "%.*s%s", root_len, ctx->path_rootfs, ctx->path_textfile);
}
else {
tmp = flb_sds_printf(&tmp, "%.*s/%s", root_len, ctx->path_rootfs, ctx->path_textfile);
}
if (tmp) {
ctx->path_textfile = tmp;
}
}
}
}

flb_plg_info(ins, "path.procfs = %s", ctx->path_procfs);
flb_plg_info(ins, "path.sysfs = %s", ctx->path_sysfs);

Expand Down
1 change: 1 addition & 0 deletions plugins/in_node_exporter_metrics/ne_stat_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static int stat_update(struct flb_ne *ctx)
mk_list_init(&list);
ret = ne_utils_file_read_lines(ctx->path_procfs, "/stat", &list);
if (ret == -1) {
flb_plg_error(ctx->ins, "failed to read %s/stat", ctx->path_procfs);
return -1;
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/in_node_exporter_metrics/ne_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ int ne_utils_file_read_lines(const char *mount, const char *path, struct mk_list
/*
* Read a file and store the first line as a string.
*/
int ne_utils_file_read_sds(const char *mount,
const char *path,
const char *join_a,
int ne_utils_file_read_sds(const char *mount,
const char *path,
const char *join_a,
const char *join_b,
flb_sds_t *str)
{
Expand Down
4 changes: 2 additions & 2 deletions plugins/in_node_exporter_metrics/ne_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ int ne_utils_file_read_uint64(const char *mount,

int ne_utils_file_read_sds(const char *mount,
const char *path,
const char *join_a,
const char *join_b,
const char *join_a,
const char *join_b,
flb_sds_t *str);

int ne_utils_file_read_lines(const char *mount, const char *path, struct mk_list *list);
Expand Down
Loading