From 8352b89bdde804097e62a5ba7bc4ea14ba9428bb Mon Sep 17 00:00:00 2001 From: astib Date: Wed, 12 Jun 2024 10:51:47 +0200 Subject: [PATCH] add simple neighbor stats CLI command --- src/proxy/nbrhood.hpp | 4 +++- src/service/cmd/diag/diag_cmds.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/proxy/nbrhood.hpp b/src/proxy/nbrhood.hpp index e0e46f8..e1fbf9f 100644 --- a/src/proxy/nbrhood.hpp +++ b/src/proxy/nbrhood.hpp @@ -279,6 +279,8 @@ struct Neighbor { class NbrHood { public: + static size_t inline MAX_CACHE_SZ = 8000; + using nbr_t = std::shared_ptr; using nbr_cache_t = LRUCache; @@ -376,7 +378,7 @@ class NbrHood { } static NbrHood& instance() { - static NbrHood r(8000); + static NbrHood r(NbrHood::MAX_CACHE_SZ); return r; } private: diff --git a/src/service/cmd/diag/diag_cmds.cpp b/src/service/cmd/diag/diag_cmds.cpp index 586f900..e14eca2 100644 --- a/src/service/cmd/diag/diag_cmds.cpp +++ b/src/service/cmd/diag/diag_cmds.cpp @@ -2331,6 +2331,21 @@ int cli_diag_neighbor_list(struct cli_def *cli, const char *command, char *argv[ return CLI_OK; } +int cli_diag_neighbor_stats(struct cli_def *cli, const char *command, char *argv[], int argc) { + std::stringstream ss; + { + auto& nb = NbrHood::instance(); + auto _lc = std::scoped_lock(nb.cache().lock()); + + ss << "Neighbors stats:\n"; + ss << " cache size: " << nb.cache().get_map_ul().size() << "\r\n"; + ss << " cache max entries: " << NbrHood::MAX_CACHE_SZ << "\r\n"; + } + + cli_print(cli, "%s", ss.str().c_str()); + return CLI_OK; +} + int cli_diag_neighbor_clear(struct cli_def *cli, const char *command, char *argv[], int argc) { size_t sz = 0; @@ -2539,6 +2554,7 @@ bool register_diags(cli_def* cli, cli_command* diag) { auto diag_neighbor = cli_register_command(cli,diag,"neighbor",nullptr,PRIVILEGE_PRIVILEGED, MODE_EXEC,"proxy neighbors diag"); cli_register_command(cli,diag_neighbor,"list",cli_diag_neighbor_list,PRIVILEGE_PRIVILEGED, MODE_EXEC,"list active neighbors"); + cli_register_command(cli,diag_neighbor,"stats",cli_diag_neighbor_stats,PRIVILEGE_PRIVILEGED, MODE_EXEC,"neighbors database stats"); cli_register_command(cli,diag_neighbor,"clear",cli_diag_neighbor_clear,PRIVILEGE_PRIVILEGED, MODE_EXEC,"clear neighbors database"); cli_register_command(cli,diag_neighbor,"tag",cli_diag_neighbor_tag,PRIVILEGE_PRIVILEGED, MODE_EXEC,"update a neighbor entry with a tag-string"); cli_register_command(cli,diag_neighbor,"webhook-update",cli_diag_neighbor_webhook_update,PRIVILEGE_PRIVILEGED, MODE_EXEC,"send single neighbor entry webhook update");