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

Hash table charts #15323

Merged
merged 70 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
853df34
ebpf_functions: Add function that reports error when a wrong function…
thiagoftsm Jun 15, 2023
4ea6138
ebpf_functions: Add function to show help for enable function.
thiagoftsm Jun 15, 2023
26b0858
ebpf_functions: Rename missing define and title
thiagoftsm Jun 16, 2023
554daba
ebpf_functions: Inform eBPF function to netdata
thiagoftsm Jun 16, 2023
06e0b9e
ebpf_functions: Append prefix ebpf_ to internal function and update d…
thiagoftsm Jun 16, 2023
299a293
ebpf_functions: Add column description for response
thiagoftsm Jun 18, 2023
7c5fbf8
ebpf_functions: Add charts and remove charts not direct associated wi…
thiagoftsm Jun 18, 2023
4ecbf42
ebpf_functions: Add group by for functions output
thiagoftsm Jun 18, 2023
e90cc69
ebpf_functions: Add option to enable specific thread
thiagoftsm Jun 19, 2023
e0c98ff
ebpf_functions: Add initial option to disable thread.
thiagoftsm Jun 19, 2023
1a1fbde
ebpf_functions: Add new way to stop threads (1st step)
thiagoftsm Jun 19, 2023
5a433e4
ebpf_functions: Remove macro and use new function
thiagoftsm Jun 20, 2023
a0254d9
ebpf_functions: Modify thread chart setting chartt status instead total.
thiagoftsm Jun 20, 2023
5cae425
ebpf_functions: Fix wrong thread name during chart plot and wrong pro…
thiagoftsm Jun 21, 2023
5bccf6e
ebpf_functions: Move content from process thread to main thread reduc…
thiagoftsm Jun 21, 2023
a26ca46
ebpf_functions: Last commit doing all threads independent of process …
thiagoftsm Jun 21, 2023
72cc391
ebpf_functions: Add missing information and fix small texts
thiagoftsm Jun 21, 2023
e0fb15e
ebpf_functions: Add lock/unlock for mutex avoiding changes during cha…
thiagoftsm Jun 21, 2023
e965f94
ebpf_functions: Add a new
thiagoftsm Jun 22, 2023
deb47b6
ebpf_functions: Add a new field action
thiagoftsm Jun 22, 2023
e74a016
ebpf_functions: Add new field and remove mutex from places where we a…
thiagoftsm Jun 22, 2023
4052d9a
ebpf_functions: Reorganize algorithm avoiding different comparisons a…
thiagoftsm Jun 22, 2023
2e87887
ebpf_functions: Create new enum element to indicate origin of thread …
thiagoftsm Jun 22, 2023
b310b3a
ebpf_functions: Modify the way we set apps is enabled; Modify functio…
thiagoftsm Jun 22, 2023
e0398f3
ebpf_functions: Fix service obsolation position. Rename thread functi…
thiagoftsm Jun 22, 2023
269127c
ebpf_functions: Add final obsolete code for dc chart
thiagoftsm Jun 23, 2023
b50bd2a
ebpf_functions: Add final obsolete code for disk chart and fix issue …
thiagoftsm Jun 23, 2023
ec48077
ebpf_functions: Add final obsolete code for mount
thiagoftsm Jun 25, 2023
8ba9a02
ebpf_functions: Add final obsolete code for oomkill
thiagoftsm Jun 25, 2023
acad264
ebpf_functions: Add final obsolete code for process
thiagoftsm Jun 25, 2023
b689fe9
ebpf_functions: Add disable thread now that we have conditions to obs…
thiagoftsm Jun 27, 2023
72c8cb7
ebpf_functions: Add specific thread option and remove old debug message
thiagoftsm Jun 27, 2023
e147edb
ebpf_functions: Add script and configuratin file to help reviewers
thiagoftsm Jun 28, 2023
5d61f1b
ebpf_functions: add message to clarify users about current plugin beh…
thiagoftsm Jun 28, 2023
12c1878
ebpf_functions: OK, I changed my mind. This commit is allowing users …
thiagoftsm Jun 28, 2023
4e8102e
ebpf_functions: Address issues: Fix typo; Add function description; A…
thiagoftsm Jun 29, 2023
6f7b9be
ebpf_functions: Add function documentation
thiagoftsm Jun 29, 2023
46c3de7
ebpf_functions: rename variable to match option
thiagoftsm Jun 29, 2023
1f62db6
ebpf_functions: Update memory usage chart when thread goes out
thiagoftsm Jul 5, 2023
175cff0
ebpf_functions: Move function update for a position where it can work…
thiagoftsm Jul 5, 2023
407ab18
ebpf_functions: Add new eBPF option to control period of time thread …
thiagoftsm Jun 19, 2023
6042a91
ebpf_functions: Add new eBPF option to configuration file and also ad…
thiagoftsm Jun 19, 2023
0da88e8
ebpf_functions: Add final obsolete code for mdflush
thiagoftsm Jun 24, 2023
5526ba8
ebpf_functions: rename variable to match option
thiagoftsm Jun 29, 2023
068e490
hash_table_charts: Update kernel collector version
thiagoftsm Jul 4, 2023
489ab92
hash_table_charts: Update ebpf-co-re version
thiagoftsm Jul 4, 2023
d49f334
hash_table_charts: Add for enum new values inserted in global hash ta…
thiagoftsm Jul 4, 2023
ed597f2
hash_table_charts: Add statistic variables that will be used with new…
thiagoftsm Jul 4, 2023
222020c
hash_table_charts: Set a less generic initial value for aral charts a…
thiagoftsm Jul 5, 2023
866e654
hash_table_charts: Add new values for enum that will order future charts
thiagoftsm Jul 5, 2023
f41cb0d
hash_table_charts: Add new chart to count elements inside global tables
thiagoftsm Jul 5, 2023
ac2a78f
hash_table_charts: Add charts to monitor PID elements inside hash tables
thiagoftsm Jul 6, 2023
89c8cc2
hash_table_charts: Reorganize algorithm
thiagoftsm Jul 6, 2023
026a32e
hash_table_charts: Add helper to read global tables; Move definition …
thiagoftsm Jul 6, 2023
70bc84a
hash_table_charts: Modify read_global_table to use new helper and app…
thiagoftsm Jul 6, 2023
d110250
hash_table_charts: Modify read_global_table to use new helper and app…
thiagoftsm Jul 6, 2023
42b5300
hash_table_charts: Modify read_global_table to use new helper and app…
thiagoftsm Jul 6, 2023
70c4cc4
hash_table_charts: Fix wrong rebase; Modify read global table (process)
thiagoftsm Jul 6, 2023
c131be4
hash_table_charts: Modify read unique table (oomkill)
thiagoftsm Jul 6, 2023
373e83b
hash_table_charts: Modify read unique table (shm)
thiagoftsm Jul 6, 2023
48bc4b6
hash_table_charts: Reset variable before to use it.
thiagoftsm Jul 6, 2023
73e2b30
hash_table_charts: Modify read unique table (socket)
thiagoftsm Jul 6, 2023
519850f
hash_table_charts: Modify read unique table (swap)
thiagoftsm Jul 6, 2023
a387573
hash_table_charts: Modify read unique table (vfs)
thiagoftsm Jul 7, 2023
aad0311
Fix rebase
thiagoftsm Jul 14, 2023
806ee70
Fix rebase again
thiagoftsm Jul 14, 2023
0ad8e67
Drop line added during rebase
thiagoftsm Jul 14, 2023
0f77c90
Drop line added during rebase (README)
thiagoftsm Jul 14, 2023
7490844
hash_table_charts: Modify index.
thiagoftsm Jul 15, 2023
a06e022
hash_table_charts: Remove unnecessary call
thiagoftsm Jul 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
167 changes: 165 additions & 2 deletions collectors/ebpf.plugin/ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ebpf_module_t ebpf_modules[] = {
NETDATA_V5_14,
.load = EBPF_LOAD_LEGACY, .targets = NULL, .probe_links = NULL, .objects = NULL,
.thread = NULL, .maps_per_core = CONFIG_BOOLEAN_YES, .lifetime = EBPF_DEFAULT_LIFETIME, .running_time = 0 },
{ .thread_name = "socket", .config_name = "socket", .thread_description = NETDATA_EBPF_SOCKET_MODULE_DESC,
{ .thread_name = "socket", .config_name = "socket", .thread_description = NETDATA_EBPF_SOCKET_MODULE_DESC,
.enabled = 0, .start_routine = ebpf_socket_thread,
.update_every = EBPF_DEFAULT_UPDATE_EVERY, .global_charts = 1, .apps_charts = NETDATA_EBPF_APPS_FLAG_NO,
.apps_level = NETDATA_APPS_LEVEL_REAL_PARENT, .cgroup_charts = CONFIG_BOOLEAN_NO, .mode = MODE_ENTRY, .optional = 0,
Expand Down Expand Up @@ -1229,7 +1229,7 @@ void write_histogram_chart(char *family, char *name, const netdata_idx_t *hist,
*/
int ebpf_statistic_create_aral_chart(char *name, ebpf_module_t *em)
{
static int priority = 140100;
static int priority = NETATA_EBPF_ORDER_STAT_ARAL_BEGIN;
char *mem = { NETDATA_EBPF_STAT_DIMENSION_MEMORY };
char *aral = { NETDATA_EBPF_STAT_DIMENSION_ARAL };

Expand Down Expand Up @@ -1325,6 +1325,49 @@ void ebpf_send_data_aral_chart(ARAL *memory, ebpf_module_t *em)
write_end_chart();
}

/*****************************************************************
*
* FUNCTIONS TO READ GLOBAL HASH TABLES
*
*****************************************************************/

/**
* Read Global Table Stats
*
* Read data from specified table (map_fd) using array allocated inside thread(values) and storing
* them in stats vector starting from the first position.
*
* For PID tables is recommended to use a function to parse the specific data.
*
* @param stats vector used to store data
* @param values helper to read data from hash tables.
* @param map_fd table that has data
* @param maps_per_core Is necessary to read data from all cores?
* @param begin initial value to query hash table
* @param end last value that will not be used.
*/
void ebpf_read_global_table_stats(netdata_idx_t *stats,
netdata_idx_t *values,
int map_fd,
int maps_per_core,
uint32_t begin,
uint32_t end)
{
uint32_t idx, order;

for (idx = begin, order = 0; idx < end; idx++, order++) {
if (!bpf_map_lookup_elem(map_fd, &idx, values)) {
int i;
int before = (maps_per_core) ? ebpf_nprocs: 1;
netdata_idx_t total = 0;
for (i = 0; i < before; i++)
total += values[i];

stats[order] = total;
}
}
}

/*****************************************************************
*
* FUNCTIONS TO DEFINE OPTIONS
Expand Down Expand Up @@ -2453,6 +2496,47 @@ static char *memlock_stat = {"memory_locked"};
static char *hash_table_stat = {"hash_table"};
static char *hash_table_core[NETDATA_EBPF_LOAD_STAT_END] = {"per_core", "unique"};

/**
* Send Hash Table PID data
*
* Send all information associated with a specific pid table.
*
* @param chart chart id
* @param idx index position in hash_table_stats
*/
static inline void ebpf_send_hash_table_pid_data(char *chart, uint32_t idx)
{
int i;
write_begin_chart(NETDATA_MONITORING_FAMILY, chart);
for (i = 0; i < EBPF_MODULE_FUNCTION_IDX; i++) {
ebpf_module_t *wem = &ebpf_modules[i];
if (wem->apps_routine)
write_chart_dimension((char *)wem->thread_name,
(wem->enabled < NETDATA_THREAD_EBPF_STOPPING) ?
wem->hash_table_stats[idx]:
0);
}
write_end_chart();
}

/**
* Send Global Hash Table data
*
* Send all information associated with a specific pid table.
*
*/
static inline void ebpf_send_global_hash_table_data()
{
int i;
write_begin_chart(NETDATA_MONITORING_FAMILY, NETDATA_EBPF_HASH_TABLES_GLOBAL_ELEMENTS);
for (i = 0; i < EBPF_MODULE_FUNCTION_IDX; i++) {
ebpf_module_t *wem = &ebpf_modules[i];
write_chart_dimension((char *)wem->thread_name,
(wem->enabled < NETDATA_THREAD_EBPF_STOPPING) ? NETDATA_CONTROLLER_END: 0);
}
write_end_chart();
}

/**
* Send Statistic Data
*
Expand Down Expand Up @@ -2500,6 +2584,11 @@ void ebpf_send_statistic_data()
write_chart_dimension(hash_table_core[NETDATA_EBPF_THREAD_PER_CORE], (long long)plugin_statistics.hash_percpu);
write_chart_dimension(hash_table_core[NETDATA_EBPF_THREAD_UNIQUE], (long long)plugin_statistics.hash_unique);
write_end_chart();

ebpf_send_global_hash_table_data();

ebpf_send_hash_table_pid_data(NETDATA_EBPF_HASH_TABLES_INSERT_PID_ELEMENTS, NETDATA_EBPF_GLOBAL_TABLE_PID_TABLE_ADD);
ebpf_send_hash_table_pid_data(NETDATA_EBPF_HASH_TABLES_REMOVE_PID_ELEMENTS, NETDATA_EBPF_GLOBAL_TABLE_PID_TABLE_DEL);
}

/**
Expand Down Expand Up @@ -2681,6 +2770,66 @@ static inline void ebpf_create_statistic_hash_per_core(int update_every)
ebpf_algorithms[NETDATA_EBPF_ABSOLUTE_IDX]);
}

/**
* Hash table global elements
*
* Write to standard output current values inside global tables.
*
* @param update_every time used to update charts
*/
static void ebpf_create_statistic_hash_global_elements(int update_every)
{
ebpf_write_chart_cmd(NETDATA_MONITORING_FAMILY,
NETDATA_EBPF_HASH_TABLES_GLOBAL_ELEMENTS,
"Controllers inside global table",
"rows",
NETDATA_EBPF_FAMILY,
NETDATA_EBPF_CHART_TYPE_LINE,
NULL,
NETDATA_EBPF_ORDER_STAT_HASH_GLOBAL_TABLE_TOTAL,
update_every,
NETDATA_EBPF_MODULE_NAME_PROCESS);

int i;
for (i = 0; i < EBPF_MODULE_FUNCTION_IDX; i++) {
ebpf_write_global_dimension((char *)ebpf_modules[i].thread_name,
(char *)ebpf_modules[i].thread_name,
ebpf_algorithms[NETDATA_EBPF_ABSOLUTE_IDX]);
}
}

/**
* Hash table global elements
*
* Write to standard output current values inside global tables.
*
* @param update_every time used to update charts
* @param id chart id
* @param title chart title
* @param order ordder chart will be shown on dashboard.
*/
static void ebpf_create_statistic_hash_pid_table(int update_every, char *id, char *title, int order)
{
ebpf_write_chart_cmd(NETDATA_MONITORING_FAMILY,
id,
title,
"rows",
NETDATA_EBPF_FAMILY,
NETDATA_EBPF_CHART_TYPE_LINE,
NULL,
order,
update_every,
NETDATA_EBPF_MODULE_NAME_PROCESS);

int i;
for (i = 0; i < EBPF_MODULE_FUNCTION_IDX; i++) {
ebpf_module_t *wem = &ebpf_modules[i];
if (wem->apps_routine)
ebpf_write_global_dimension((char *)wem->thread_name,
(char *)wem->thread_name,
ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX]);
}
}

/**
* Create Statistics Charts
Expand Down Expand Up @@ -2718,6 +2867,20 @@ static void ebpf_create_statistic_charts(int update_every)
ebpf_create_statistic_hash_tables(update_every);

ebpf_create_statistic_hash_per_core(update_every);

ebpf_create_statistic_hash_global_elements(update_every);

ebpf_create_statistic_hash_pid_table(update_every,
NETDATA_EBPF_HASH_TABLES_INSERT_PID_ELEMENTS,
"Elements inserted into PID table",
NETDATA_EBPF_ORDER_STAT_HASH_PID_TABLE_ADDED);

ebpf_create_statistic_hash_pid_table(update_every,
NETDATA_EBPF_HASH_TABLES_REMOVE_PID_ELEMENTS,
"Elements removed from PID table",
NETDATA_EBPF_ORDER_STAT_HASH_PID_TABLE_REMOVED);

fflush(stdout);
}

/*****************************************************************
Expand Down
8 changes: 6 additions & 2 deletions collectors/ebpf.plugin/ebpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ typedef struct netdata_syscall_stat {
struct netdata_syscall_stat *next; // Link list
} netdata_syscall_stat_t;

typedef uint64_t netdata_idx_t;

typedef struct netdata_publish_syscall {
char *dimension;
char *name;
Expand Down Expand Up @@ -169,6 +167,9 @@ typedef struct ebpf_tracepoint {
#define NETDATA_EBPF_KERNEL_MEMORY "ebpf_kernel_memory"
#define NETDATA_EBPF_HASH_TABLES_LOADED "ebpf_hash_tables_count"
#define NETDATA_EBPF_HASH_TABLES_PER_CORE "ebpf_hash_tables_per_core"
#define NETDATA_EBPF_HASH_TABLES_GLOBAL_ELEMENTS "ebpf_hash_tables_global_elements"
#define NETDATA_EBPF_HASH_TABLES_INSERT_PID_ELEMENTS "ebpf_hash_tables_insert_pid_elements"
#define NETDATA_EBPF_HASH_TABLES_REMOVE_PID_ELEMENTS "ebpf_hash_tables_remove_pid_elements"

// Log file
#define NETDATA_DEVELOPER_LOG_FILE "developer.log"
Expand Down Expand Up @@ -319,6 +320,9 @@ void ebpf_update_disabled_plugin_stats(ebpf_module_t *em);
ARAL *ebpf_allocate_pid_aral(char *name, size_t size);
void ebpf_unload_legacy_code(struct bpf_object *objects, struct bpf_link **probe_links);

void ebpf_read_global_table_stats(netdata_idx_t *stats, netdata_idx_t *values, int map_fd,
int maps_per_core, uint32_t begin, uint32_t end);

extern ebpf_filesystem_partitions_t localfs[];
extern ebpf_sync_syscalls_t local_syscalls[];
extern int ebpf_exit_plugin;
Expand Down
36 changes: 18 additions & 18 deletions collectors/ebpf.plugin/ebpf_cachestat.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,26 +854,24 @@ void ebpf_cachestat_create_apps_charts(struct ebpf_module *em, void *ptr)
*
* Read the table with number of calls for all functions
*
* @param stats vector used to read data from control table.
* @param maps_per_core do I need to read all cores?
*/
static void ebpf_cachestat_read_global_table(int maps_per_core)
static void ebpf_cachestat_read_global_tables(netdata_idx_t *stats, int maps_per_core)
{
uint32_t idx;
netdata_idx_t *val = cachestat_hash_values;
netdata_idx_t *stored = cachestat_values;
int fd = cachestat_maps[NETDATA_CACHESTAT_GLOBAL_STATS].map_fd;

for (idx = NETDATA_KEY_CALLS_ADD_TO_PAGE_CACHE_LRU; idx < NETDATA_CACHESTAT_END; idx++) {
if (!bpf_map_lookup_elem(fd, &idx, stored)) {
int i;
int end = (maps_per_core) ? ebpf_nprocs: 1;
netdata_idx_t total = 0;
for (i = 0; i < end; i++)
total += stored[i];

val[idx] = total;
}
}
ebpf_read_global_table_stats(cachestat_hash_values,
cachestat_values,
cachestat_maps[NETDATA_CACHESTAT_GLOBAL_STATS].map_fd,
maps_per_core,
NETDATA_KEY_CALLS_ADD_TO_PAGE_CACHE_LRU,
NETDATA_CACHESTAT_END);

ebpf_read_global_table_stats(stats,
cachestat_values,
cachestat_maps[NETDATA_CACHESTAT_CTRL].map_fd,
maps_per_core,
NETDATA_CONTROLLER_PID_TABLE_ADD,
NETDATA_CONTROLLER_END);
}

/**
Expand Down Expand Up @@ -1288,6 +1286,8 @@ static void cachestat_collector(ebpf_module_t *em)
//This will be cancelled by its parent
uint32_t running_time = 0;
uint32_t lifetime = em->lifetime;
netdata_idx_t *stats = em->hash_table_stats;
memset(stats, 0, sizeof(em->hash_table_stats));
while (!ebpf_exit_plugin && running_time < lifetime) {
(void)heartbeat_next(&hb, USEC_PER_SEC);

Expand All @@ -1296,7 +1296,7 @@ static void cachestat_collector(ebpf_module_t *em)

counter = 0;
netdata_apps_integration_flags_t apps = em->apps_charts;
ebpf_cachestat_read_global_table(maps_per_core);
ebpf_cachestat_read_global_tables(stats, maps_per_core);
pthread_mutex_lock(&collect_data_mutex);
if (apps)
ebpf_read_cachestat_apps_table(maps_per_core);
Expand Down
36 changes: 18 additions & 18 deletions collectors/ebpf.plugin/ebpf_dcstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,26 +690,24 @@ static void ebpf_update_dc_cgroup(int maps_per_core)
*
* Read the table with number of calls for all functions
*
* @param stats vector used to read data from control table.
* @param maps_per_core do I need to read all cores?
*/
static void ebpf_dc_read_global_table(int maps_per_core)
static void ebpf_dc_read_global_tables(netdata_idx_t *stats, int maps_per_core)
{
uint32_t idx;
netdata_idx_t *val = dcstat_hash_values;
netdata_idx_t *stored = dcstat_values;
int fd = dcstat_maps[NETDATA_DCSTAT_GLOBAL_STATS].map_fd;

for (idx = NETDATA_KEY_DC_REFERENCE; idx < NETDATA_DIRECTORY_CACHE_END; idx++) {
if (!bpf_map_lookup_elem(fd, &idx, stored)) {
int i;
int end = (maps_per_core) ? ebpf_nprocs: 1;
netdata_idx_t total = 0;
for (i = 0; i < end; i++)
total += stored[i];

val[idx] = total;
}
}
ebpf_read_global_table_stats(dcstat_hash_values,
dcstat_values,
dcstat_maps[NETDATA_DCSTAT_GLOBAL_STATS].map_fd,
maps_per_core,
NETDATA_KEY_DC_REFERENCE,
NETDATA_DIRECTORY_CACHE_END);

ebpf_read_global_table_stats(stats,
dcstat_values,
dcstat_maps[NETDATA_DCSTAT_CTRL].map_fd,
maps_per_core,
NETDATA_CONTROLLER_PID_TABLE_ADD,
NETDATA_CONTROLLER_END);
}

/**
Expand Down Expand Up @@ -1169,6 +1167,8 @@ static void dcstat_collector(ebpf_module_t *em)
int maps_per_core = em->maps_per_core;
uint32_t running_time = 0;
uint32_t lifetime = em->lifetime;
netdata_idx_t *stats = em->hash_table_stats;
memset(stats, 0, sizeof(em->hash_table_stats));
while (!ebpf_exit_plugin && running_time < lifetime) {
(void)heartbeat_next(&hb, USEC_PER_SEC);

Expand All @@ -1177,7 +1177,7 @@ static void dcstat_collector(ebpf_module_t *em)

counter = 0;
netdata_apps_integration_flags_t apps = em->apps_charts;
ebpf_dc_read_global_table(maps_per_core);
ebpf_dc_read_global_tables(stats, maps_per_core);
pthread_mutex_lock(&collect_data_mutex);
if (apps)
read_dc_apps_table(maps_per_core);
Expand Down