Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_node_exporter_metrics: implement processes metrics #7880

Merged
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
1 change: 1 addition & 0 deletions plugins/in_node_exporter_metrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(src
ne_loadavg.c
ne_filefd_linux.c
ne_textfile.c
ne_processes.c
ne_utils.c
ne_config.c
ne.c
Expand Down
57 changes: 57 additions & 0 deletions plugins/in_node_exporter_metrics/ne.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "ne_netdev.h"
#include "ne_textfile.h"
#include "ne_systemd.h"
#include "ne_processes.h"

static int ne_timer_cpu_metrics_cb(struct flb_input_instance *ins,
struct flb_config *config, void *in_context)
Expand Down Expand Up @@ -182,6 +183,15 @@ static int ne_timer_systemd_metrics_cb(struct flb_input_instance *ins,
return 0;
}

static int ne_timer_processes_metrics_cb(struct flb_input_instance *ins,
struct flb_config *config, void *in_context)
{
struct flb_ne *ctx = in_context;

ne_processes_update(ctx);

return 0;
}
struct flb_ne_callback {
char *name;
void (*func)(char *, void *, void *);
Expand Down Expand Up @@ -329,6 +339,13 @@ static void ne_systemd_update_cb(char *name, void *p1, void *p2)
ne_systemd_update(ctx);
}

static void ne_processes_update_cb(char *name, void *p1, void *p2)
{
struct flb_ne *ctx = p1;

ne_processes_update(ctx);
}

static int ne_update_cb(struct flb_ne *ctx, char *name)
{
int ret;
Expand Down Expand Up @@ -356,6 +373,7 @@ struct flb_ne_callback ne_callbacks[] = {
{ "filefd", ne_filefd_update_cb },
{ "textfile", ne_textfile_update_cb },
{ "systemd", ne_systemd_update_cb },
{ "processes", ne_processes_update_cb },
{ 0 }
};

Expand Down Expand Up @@ -392,6 +410,7 @@ static int in_ne_init(struct flb_input_instance *in,
ctx->coll_filefd_fd = -1;
ctx->coll_textfile_fd = -1;
ctx->coll_systemd_fd = -1;
ctx->coll_processes_fd = -1;

ctx->callback = flb_callback_create(in->name);
if (!ctx->callback) {
Expand Down Expand Up @@ -701,6 +720,26 @@ static int in_ne_init(struct flb_input_instance *in,
}
ne_systemd_init(ctx);
}
else if (strncmp(entry->str, "processes", 9) == 0) {
if (ctx->processes_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems process collector is disabled but the message says enabled

Copy link
Contributor Author

@cosmo0920 cosmo0920 Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is used when enabling processes metrics. Other messages for enabling metrics are also displayed in enabled circumstances. I mean, when "processes" string is included in metrics parameter, this message will be displayed.

metric_idx = 14;
}
else if (ctx->processes_scrape_interval > 0) {
/* Create the filefd collector */
ret = flb_input_set_collector_time(in,
ne_timer_processes_metrics_cb,
ctx->processes_scrape_interval, 0,
config);
if (ret == -1) {
flb_plg_error(ctx->ins,
"could not set systemd collector for Node Exporter Metrics plugin");
return -1;
}
ctx->coll_processes_fd = ret;
}
ne_processes_init(ctx);
}
else {
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
metric_idx = -1;
Expand Down Expand Up @@ -786,6 +825,9 @@ static int in_ne_exit(void *data, struct flb_config *config)
else if (strncmp(entry->str, "systemd", 7) == 0) {
ne_systemd_exit(ctx);
}
else if (strncmp(entry->str, "processes", 9) == 0) {
ne_processes_exit(ctx);
}
else {
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
}
Expand Down Expand Up @@ -817,6 +859,9 @@ static int in_ne_exit(void *data, struct flb_config *config)
if (ctx->coll_systemd_fd != -1) {
ne_systemd_exit(ctx);
}
if (ctx->coll_processes_fd != -1) {
ne_processes_exit(ctx);
}

flb_ne_config_destroy(ctx);

Expand Down Expand Up @@ -870,6 +915,9 @@ static void in_ne_pause(void *data, struct flb_config *config)
if (ctx->coll_systemd_fd != -1) {
flb_input_collector_pause(ctx->coll_systemd_fd, ctx->ins);
}
if (ctx->coll_processes_fd != -1) {
flb_input_collector_pause(ctx->coll_processes_fd, ctx->ins);
}
}

static void in_ne_resume(void *data, struct flb_config *config)
Expand Down Expand Up @@ -919,6 +967,9 @@ static void in_ne_resume(void *data, struct flb_config *config)
if (ctx->coll_systemd_fd != -1) {
flb_input_collector_resume(ctx->coll_systemd_fd, ctx->ins);
}
if (ctx->coll_processes_fd != -1) {
flb_input_collector_resume(ctx->coll_processes_fd, ctx->ins);
}
}

/* Configuration properties map */
Expand Down Expand Up @@ -1013,6 +1064,12 @@ static struct flb_config_map config_map[] = {
"scrape interval to collect systemd metrics from the node."
},

{
FLB_CONFIG_MAP_TIME, "collector.processes.scrape_interval", "0",
0, FLB_TRUE, offsetof(struct flb_ne, processes_scrape_interval),
"scrape interval to collect processes metrics from the node."
},

{
FLB_CONFIG_MAP_CLIST, "metrics",
"cpu,cpufreq,meminfo,diskstats,filesystem,uname,stat,time,loadavg,vmstat,netdev,filefd,systemd",
Expand Down
10 changes: 10 additions & 0 deletions plugins/in_node_exporter_metrics/ne.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct flb_ne {
int filefd_scrape_interval;
int textfile_scrape_interval;
int systemd_scrape_interval;
int processes_scrape_interval;

int coll_cpu_fd; /* collector fd (cpu) */
int coll_cpufreq_fd; /* collector fd (cpufreq) */
Expand All @@ -81,6 +82,7 @@ struct flb_ne {
int coll_filefd_fd; /* collector fd (filefd) */
int coll_textfile_fd; /* collector fd (textfile) */
int coll_systemd_fd ; /* collector fd (systemd) */
int coll_processes_fd ; /* collector fd (processes) */

/*
* Metrics Contexts
Expand Down Expand Up @@ -186,6 +188,14 @@ struct flb_ne {
struct flb_regex *systemd_regex_exclude_list;
double libsystemd_version;
char *libsystemd_version_text;

/* processes */
struct cmt_gauge *processes_thread_alloc;
struct cmt_gauge *processes_threads_limit;
struct cmt_gauge *processes_threads_state;
struct cmt_gauge *processes_procs_state;
struct cmt_gauge *processes_pid_used;
struct cmt_gauge *processes_pid_max;
};

#endif
22 changes: 22 additions & 0 deletions plugins/in_node_exporter_metrics/ne_processes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2023 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifdef __linux__
#include "ne_processes_linux.c"
#endif
29 changes: 29 additions & 0 deletions plugins/in_node_exporter_metrics/ne_processes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2023 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FLB_IN_NE_PROCESSES_H
#define FLB_IN_NE_PROCESSES_H

#include "ne.h"

int ne_processes_init(struct flb_ne *ctx);
int ne_processes_update(struct flb_ne *ctx);
int ne_processes_exit(struct flb_ne *ctx);

#endif
Loading
Loading