Skip to content

Commit

Permalink
ebpf_apps: Chart creation
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoftsm committed May 31, 2020
1 parent 4c606f8 commit 43f9957
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 37 deletions.
94 changes: 79 additions & 15 deletions collectors/ebpf.plugin/ebpf.c
Expand Up @@ -5,6 +5,13 @@

#include "ebpf.h"

/*****************************************************************
*
* FUNCTIONS USED BY NETDATA
*
*****************************************************************/


// callback required by eval()
int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result) {
(void)variable;
Expand Down Expand Up @@ -35,6 +42,12 @@ void netdata_cleanup_and_exit(int ret) {
}

// ----------------------------------------------------------------------
/*****************************************************************
*
* GLOBAL VARIABLES
*
*****************************************************************/

char *ebpf_plugin_dir = PLUGINS_DIR;
char *ebpf_user_config_dir = CONFIG_DIR;
char *ebpf_stock_config_dir = LIBCONFIG_DIR;
Expand All @@ -51,7 +64,6 @@ int running_on_kernel = 0;
char kernel_string[64];
int ebpf_nprocs;
static int isrh;
netdata_idx_t *hash_values;

pthread_mutex_t lock;

Expand Down Expand Up @@ -90,6 +102,17 @@ ebpf_module_t ebpf_modules[] = {
.global_charts = 0, .apps_charts = 1, .mode = MODE_ENTRY, .probes = NULL },
};

//Link with apps.plugin
struct target
*apps_groups_default_target = NULL, // the default target
*apps_groups_root_target = NULL; // apps_groups.conf defined

/*****************************************************************
*
* FUNCTIONS USED TO CLEAN MEMORY AND OPERATE SYSTEM FILES
*
*****************************************************************/

/**
* Close the collector gracefully
*
Expand Down Expand Up @@ -313,6 +336,26 @@ void ebpf_create_chart(char *family
ncd(move, end);
}

/**
* Create charts on apps submenu
*
* @param name the chart name
* @param axis the value displayed on vertical axis.
* @param web Submenu that the chart will be attached on dashboard.
* @param order the chart order
* @param root structure used to create the dimensions.
*/
void ebpf_create_charts_on_apps(char *name, char *axis, char *web, int order, struct target *root)
{
struct target *w;
ebpf_write_chart_cmd(NETDATA_APPS_FAMILY, name, axis, web, order);

for (w = root; w ; w = w->next) {
if(unlikely(w->exposed))
fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
}
}

/*****************************************************************
*
* FUNCTIONS TO DEFINE OPTIONS
Expand Down Expand Up @@ -514,8 +557,10 @@ static inline int parse_disable_apps(char *ptr)

/**
* Read collector values
*
* @param disable_apps variable to store information related to apps.
*/
static void read_collector_values() {
static void read_collector_values(int *disable_apps) {
// Read global section
char *value;
if (appconfig_exists(&collector_config, EBPF_GLOBAL_SECTION, "load")) //Backward compatibility
Expand All @@ -526,45 +571,46 @@ static void read_collector_values() {
how_to_load(value);

value = appconfig_get(&collector_config, EBPF_GLOBAL_SECTION, "disable apps", "no");
int disable_apps = parse_disable_apps(value);
*disable_apps = parse_disable_apps(value);

// Read ebpf programs section
uint32_t enabled = appconfig_get_boolean(&collector_config, EBPF_PROGRAMS_SECTION,
ebpf_modules[0].config_name, 1);
int started = 0;
if (enabled) {
ebpf_enable_chart(0, disable_apps);
ebpf_enable_chart(0, *disable_apps);
started++;
}

enabled = appconfig_get_boolean(&collector_config, EBPF_PROGRAMS_SECTION,
ebpf_modules[1].config_name, 1);
if (enabled) {
ebpf_enable_chart(1, disable_apps);
ebpf_enable_chart(1, *disable_apps);
started++;
}

if (!started)
ebpf_enable_all_charts(disable_apps);
ebpf_enable_all_charts(*disable_apps);

}

/**
* Load collector config
*
* @param path the path where the file ebpf.conf is stored.
* @param path the path where the file ebpf.conf is stored.
* @param disable_apps variable to store the information about apps plugin status.
*
* @return 0 on success and -1 otherwise.
*/
static int load_collector_config(char *path) {
static int load_collector_config(char *path, int *disable_apps) {
char lpath[4096];

snprintf(lpath, 4095, "%s/%s", path, "ebpf.conf" );

if (!appconfig_load(&collector_config, lpath, 0, NULL))
return -1;

read_collector_values();
read_collector_values(disable_apps);

return 0;
}
Expand Down Expand Up @@ -691,10 +737,10 @@ static void parse_args(int argc, char **argv)
update_every = freq;
}

if (load_collector_config(ebpf_user_config_dir)) {
if (load_collector_config(ebpf_user_config_dir, &disable_apps)) {
error("Does not have a configuration file inside `%s/ebpf.conf. It will try to load stock file.",
ebpf_user_config_dir);
if (load_collector_config(ebpf_stock_config_dir)) {
if (load_collector_config(ebpf_stock_config_dir, &disable_apps)) {
error("Does not have a stock file. It is starting with default options.");
} else {
enabled = 1;
Expand All @@ -709,6 +755,24 @@ static void parse_args(int argc, char **argv)
info("EBPF running with all charts, because neither \"-n\" or \"-p\" was given.");
#endif
}

if (disable_apps)
return;

//Load apps_groups.conf
if (ebpf_read_apps_groups_conf(&apps_groups_default_target, &apps_groups_root_target,
ebpf_user_config_dir, "groups") ) {
info("Cannot read process groups configuration file '%s/apps_groups.conf'. Will try '%s/apps_groups.conf'",
ebpf_user_config_dir, ebpf_stock_config_dir);
if (ebpf_read_apps_groups_conf(&apps_groups_default_target, &apps_groups_root_target,
ebpf_stock_config_dir, "groups") ) {
error("Cannot read process groups '%s/apps_groups.conf'. There are no internal defaults. Failing.",
ebpf_stock_config_dir);
thread_finished++;
ebpf_exit(1);
}
} else
info("Loaded config file '%s/apps_groups.conf'", ebpf_user_config_dir);
}


Expand All @@ -734,14 +798,14 @@ int main(int argc, char **argv)
running_on_kernel = get_kernel_version(kernel_string, 63);
if(!has_condition_to_run(running_on_kernel)) {
error("The current collector cannot run on this kernel.");
return 1;
return 2;
}

if(!am_i_running_as_root()) {
error("ebpf.plugin should either run as root (now running with uid %u, euid %u) or have special capabilities..",
(unsigned int)getuid(), (unsigned int)geteuid()
);
return 1;
return 3;
}

//set name
Expand All @@ -757,7 +821,7 @@ int main(int argc, char **argv)
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
if (setrlimit(RLIMIT_MEMLOCK, &r)) {
error("Setrlimit(RLIMIT_MEMLOCK)");
return 2;
return 4;
}

signal(SIGINT, ebpf_exit);
Expand All @@ -766,7 +830,7 @@ int main(int argc, char **argv)
if (pthread_mutex_init(&lock, NULL)) {
thread_finished++;
error("Cannot start the mutex.");
ebpf_exit(3);
ebpf_exit(5);
}

struct netdata_static_thread ebpf_threads[] = {
Expand Down
8 changes: 8 additions & 0 deletions collectors/ebpf.plugin/ebpf.h
Expand Up @@ -157,11 +157,19 @@ void write_io_chart(char *chart, char *family, char *dwrite, char *dread, netdat

extern void fill_ebpf_functions(ebpf_functions_t *ef);

void ebpf_create_charts_on_apps(char *name, char *axis, char *web, int order, struct target *root);

# define EBPF_GLOBAL_SECTION "global"
# define EBPF_PROGRAMS_SECTION "ebpf programs"

# define EBPF_COMMON_DIMENSION_CALL "Calls"
# define EBPF_COMMON_DIMENSION_BYTESS "bytes/s"
# define EBPF_COMMON_DIMENSION_DIFFERENCE "Difference"

//Common variables
extern char *ebpf_user_config_dir;
extern char *ebpf_stock_config_dir;
extern struct target *apps_groups_default_target;
extern struct target *apps_groups_root_target;

#endif
4 changes: 2 additions & 2 deletions collectors/ebpf.plugin/ebpf_apps.c
Expand Up @@ -310,8 +310,8 @@ struct target *get_apps_groups_target(struct target **apps_groups_root_target, c
/**
* Read the apps_groups.conf file
*
* @param path
* @param file
* @param path the directory to search apps_%s.conf
* @param file the word to complement the file name.
*
* @return It returns 0 on succcess and -1 otherwise
*/
Expand Down
4 changes: 2 additions & 2 deletions collectors/ebpf.plugin/ebpf_apps.h
Expand Up @@ -9,8 +9,8 @@
# include "../../libnetdata/ebpf/ebpf.h"

# define NETDATA_APPS_FAMILY "apps"
# define NETDATA_APPS_SYSCALL_GROUP "syscall"
# define NETDATA_APPS_NET_GROUP "net"
# define NETDATA_APPS_SYSCALL_GROUP "ebpf syscall"
# define NETDATA_APPS_NET_GROUP "ebpf net"

# define MAX_COMPARE_NAME 100
# define MAX_NAME 100
Expand Down

0 comments on commit 43f9957

Please sign in to comment.