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

feat: add a interface to get perf-counters info of all partitions of all apps #417

Merged
merged 4 commits into from
Nov 19, 2019
Merged
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
64 changes: 64 additions & 0 deletions src/shell/command_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,70 @@ inline bool decode_node_perf_counter_info(const dsn::rpc_address &node_addr,
return true;
}

// rows: key-app name, value-perf counters for each partition
inline bool get_app_partition_stat(shell_context *sc,
std::map<std::string, std::vector<row_data>> &rows)
{
// get apps and nodes
std::vector<::dsn::app_info> apps;
std::vector<node_desc> nodes;
if (!get_apps_and_nodes(sc, apps, nodes)) {
return false;
}

// get app_id --> app_name
std::map<int32_t, std::string> app_id_name;
for (::dsn::app_info &app : apps) {
app_id_name[app.app_id] = app.app_name;
rows[app.app_name].resize(app.partition_count);
}

// get app_id --> partitions
std::map<int32_t, std::vector<dsn::partition_configuration>> app_partitions;
if (!get_app_partitions(sc, apps, app_partitions)) {
return false;
}

// get all of the perf counters with format ".*@.*"
neverchanje marked this conversation as resolved.
Show resolved Hide resolved
::dsn::command command;
command.cmd = "perf-counters";
char tmp[256];
sprintf(tmp, ".*@.*");
command.arguments.emplace_back(tmp);
std::vector<std::pair<bool, std::string>> results;
call_remote_command(sc, nodes, command, results);

for (int i = 0; i < nodes.size(); ++i) {
// decode info of perf-counters on node i
dsn::perf_counter_info info;
if (!decode_node_perf_counter_info(nodes[i].address, results[i], info)) {
return false;
}

for (dsn::perf_counter_metric &m : info.counters) {
// get app_id/partition_id/counter_name from the name of perf-counter
int32_t app_id_x, partition_index_x;
std::string counter_name;
if (!parse_app_pegasus_perf_counter_name(
m.name, app_id_x, partition_index_x, counter_name)) {
continue;
}

// only on primary partition will be counted
auto find = app_partitions.find(app_id_x);
if (find != app_partitions.end() &&
find->second[partition_index_x].primary == nodes[i].address) {
const std::string &app_name = app_id_name[app_id_x];
row_data &row = rows[app_name][partition_index_x];
row.row_name = std::to_string(partition_index_x);
row.app_id = app_id_x;
update_app_pegasus_perf_counter(row, counter_name, m.value);
}
}
}
return true;
}

inline bool
get_app_stat(shell_context *sc, const std::string &app_name, std::vector<row_data> &rows)
{
Expand Down