Skip to content

Commit

Permalink
Merge branch 'disk_command' of github.com:Shuo-Jia/pegasus into disk_…
Browse files Browse the repository at this point in the history
…command
  • Loading branch information
foreverneverer committed Mar 23, 2020
2 parents b44e631 + b1719ac commit c7ecfcc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/server/info_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ info_collector::app_stat_counters *info_collector::get_app_counters(const std::s
INIT_COUNTER(rdb_estimate_num_keys);
INIT_COUNTER(read_qps);
INIT_COUNTER(write_qps);
INIT_COUNTER(backup_request_qps);
_app_stat_counters[app_name] = counters;
return counters;
}
Expand Down
2 changes: 2 additions & 0 deletions src/server/info_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class info_collector
rdb_estimate_num_keys->set(row_stats.total_rdb_estimate_num_keys);
read_qps->set(row_stats.get_total_read_qps());
write_qps->set(row_stats.get_total_write_qps());
backup_request_qps->set(row_stats.total_backup_request_qps);
}

::dsn::perf_counter_wrapper get_qps;
Expand Down Expand Up @@ -93,6 +94,7 @@ class info_collector
::dsn::perf_counter_wrapper rdb_estimate_num_keys;
::dsn::perf_counter_wrapper read_qps;
::dsn::perf_counter_wrapper write_qps;
::dsn::perf_counter_wrapper backup_request_qps;
};

info_collector();
Expand Down
3 changes: 3 additions & 0 deletions src/server/table_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct table_stats
total_rdb_index_and_filter_blocks_mem_usage += row.rdb_index_and_filter_blocks_mem_usage;
total_rdb_memtable_mem_usage += row.rdb_memtable_mem_usage;
total_rdb_estimate_num_keys += row.rdb_estimate_num_keys;
total_backup_request_qps += row.backup_request_qps;
}

void merge(const table_stats &row_stats)
Expand Down Expand Up @@ -76,6 +77,7 @@ struct table_stats
row_stats.total_rdb_index_and_filter_blocks_mem_usage;
total_rdb_memtable_mem_usage += row_stats.total_rdb_memtable_mem_usage;
total_rdb_estimate_num_keys += row_stats.total_rdb_estimate_num_keys;
total_backup_request_qps += row_stats.total_backup_request_qps;
}

std::string app_name;
Expand Down Expand Up @@ -103,6 +105,7 @@ struct table_stats
double total_rdb_index_and_filter_blocks_mem_usage = 0;
double total_rdb_memtable_mem_usage = 0;
double total_rdb_estimate_num_keys = 0;
double total_backup_request_qps = 0;
double max_total_qps = 0;
double min_total_qps = INT_MAX;
double max_total_cu = 0;
Expand Down
64 changes: 50 additions & 14 deletions src/shell/command_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,33 @@ inline bool parse_app_pegasus_perf_counter_name(const std::string &name,
return true;
}

inline bool parse_app_perf_counter_name(const std::string &name,
std::string &app_name,
std::string &counter_name)
{
/**
* name format:
* 1.{node}*{section}*{counter_name}@{app_name}.{percent_line}
* 2.{node}*{section}*{counter_name}@{app_name}
*/
std::string::size_type find = name.find_last_of('@');
if (find == std::string::npos)
return false;

std::string::size_type find2 = name.find_last_of('.');
if (find2 == std::string::npos) {
app_name = name.substr(find + 1);
} else {
app_name = name.substr(find + 1, find2 - find - 1);
}

std::string::size_type find3 = name.find_last_of('*');
if (find3 == std::string::npos)
return false;
counter_name = name.substr(find3 + 1, find - find3 - 1);
return true;
}

struct row_data
{
double get_total_qps() const
Expand Down Expand Up @@ -547,6 +574,7 @@ struct row_data
double rdb_index_and_filter_blocks_mem_usage = 0;
double rdb_memtable_mem_usage = 0;
double rdb_estimate_num_keys = 0;
double backup_request_qps = 0;
};

inline bool
Expand Down Expand Up @@ -600,6 +628,8 @@ update_app_pegasus_perf_counter(row_data &row, const std::string &counter_name,
row.rdb_memtable_mem_usage += value;
else if (counter_name == "rdb.estimate_num_keys")
row.rdb_estimate_num_keys += value;
else if (counter_name == "backup_request_qps")
row.backup_request_qps += value;
else
return false;
return true;
Expand Down Expand Up @@ -679,10 +709,12 @@ inline bool get_app_partition_stat(shell_context *sc,
return false;
}

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

Expand All @@ -709,22 +741,26 @@ inline bool get_app_partition_stat(shell_context *sc,
}

for (dsn::perf_counter_metric &m : info.counters) {
// get app_id/partition_id/counter_name from the name of perf-counter
// get app_id/partition_id/counter_name/app_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;
}
std::string app_name;

// 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;
if (parse_app_pegasus_perf_counter_name(
m.name, app_id_x, partition_index_x, counter_name)) {
// only 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) {
row_data &row = rows[app_id_name[app_id_x]][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);
}
} else if (parse_app_perf_counter_name(m.name, app_name, counter_name)) {
// perf-counter value will be set into partition index 0.
row_data &row = rows[app_name][0];
row.app_id = app_name_id[app_name];
update_app_pegasus_perf_counter(row, counter_name, m.value);
}
}
Expand Down

0 comments on commit c7ecfcc

Please sign in to comment.