Skip to content

Commit

Permalink
feat: add more cache info (#2797)
Browse files Browse the repository at this point in the history
list redis cache and block cache of rocksdb on info data
  • Loading branch information
bigdaronlee163 authored Jul 22, 2024
1 parent 7d9af52 commit a428088
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1267,8 +1267,12 @@ void InfoCmd::InfoData(std::string& info) {
uint64_t total_background_errors = 0;
uint64_t total_memtable_usage = 0;
uint64_t total_table_reader_usage = 0;
uint64_t total_redis_cache_usage = 0;
uint64_t total_block_cache_usage = 0;
uint64_t memtable_usage = 0;
uint64_t table_reader_usage = 0;
uint64_t redis_cache_usage = 0;
uint64_t block_cache_usage = 0;
std::shared_lock db_rwl(g_pika_server->dbs_rw_);
for (const auto& db_item : g_pika_server->dbs_) {
if (!db_item.second) {
Expand All @@ -1279,10 +1283,14 @@ void InfoCmd::InfoData(std::string& info) {
db_item.second->DBLockShared();
db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_CUR_SIZE_ALL_MEM_TABLES, &memtable_usage);
db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_ESTIMATE_TABLE_READER_MEM, &table_reader_usage);
db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_BlOCK_CACHE_USAGE, &block_cache_usage);
db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_BACKGROUND_ERRORS, &background_errors);
redis_cache_usage = db_item.second->GetCacheInfo().used_memory;
db_item.second->DBUnlockShared();
total_memtable_usage += memtable_usage;
total_table_reader_usage += table_reader_usage;
total_block_cache_usage += block_cache_usage;
total_redis_cache_usage += redis_cache_usage;
for (const auto& item : background_errors) {
if (item.second != 0) {
db_fatal_msg_stream << (total_background_errors != 0 ? "," : "");
Expand All @@ -1292,10 +1300,12 @@ void InfoCmd::InfoData(std::string& info) {
}
}

tmp_stream << "used_memory:" << (total_memtable_usage + total_table_reader_usage) << "\r\n";
tmp_stream << "used_memory_human:" << ((total_memtable_usage + total_table_reader_usage) >> 20) << "M\r\n";
tmp_stream << "used_memory:" << (total_memtable_usage + total_table_reader_usage + total_redis_cache_usage + total_block_cache_usage) << "\r\n";
tmp_stream << "used_memory_human:" << ((total_memtable_usage + total_table_reader_usage + total_redis_cache_usage + total_block_cache_usage) >> 20) << "M\r\n";
tmp_stream << "db_memtable_usage:" << total_memtable_usage << "\r\n";
tmp_stream << "db_tablereader_usage:" << total_table_reader_usage << "\r\n";
tmp_stream << "db_block_cache_usage:" << total_block_cache_usage << "\r\n";
tmp_stream << "db_redis_cache_usage:" << total_redis_cache_usage << "\r\n";
tmp_stream << "db_fatal:" << (total_background_errors != 0 ? "1" : "0") << "\r\n";
tmp_stream << "db_fatal_msg:" << (total_background_errors != 0 ? db_fatal_msg_stream.str() : "nullptr") << "\r\n";

Expand Down
1 change: 1 addition & 0 deletions src/storage/include/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ inline constexpr double ZSET_SCORE_MIN = std::numeric_limits<double>::lowest();
inline const std::string PROPERTY_TYPE_ROCKSDB_CUR_SIZE_ALL_MEM_TABLES = "rocksdb.cur-size-all-mem-tables";
inline const std::string PROPERTY_TYPE_ROCKSDB_ESTIMATE_TABLE_READER_MEM = "rocksdb.estimate-table-readers-mem";
inline const std::string PROPERTY_TYPE_ROCKSDB_BACKGROUND_ERRORS = "rocksdb.background-errors";
inline const std::string PROPERTY_TYPE_ROCKSDB_BlOCK_CACHE_USAGE = "rocksdb.block-cache-usage";

inline const std::string ALL_DB = "all";
inline const std::string STRINGS_DB = "strings";
Expand Down

0 comments on commit a428088

Please sign in to comment.