Skip to content

Commit 952ecc7

Browse files
PS-10264: Implement Telemetry Collection for Key DB Features (ThreadPool, MyRocks)
https://perconadev.atlassian.net/browse/PS-10264 Implemented new telemetry metrics: 1. Collection of the value of 'thread_handling' configuration variable 2. Collection of the size used by the particular storage engine in use. Implementation of 'se_info' metric make 'databases_size' and 'se_engines_in_use' deprecated, but they are still reported for backward compatibility.
1 parent b2512d9 commit 952ecc7

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

components/percona_telemetry/data_provider.cc

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ const char *stored_program_call_count = "stored_program_call_count";
6060
const char *contexts_count = "contexts_count";
6161
const char *routines_cnt = "routines_cnt";
6262
const char *js_lang_component_info = "js_lang_component_info";
63+
const char *se_info = "se_info";
64+
const char *name = "name";
65+
const char *size = "size";
66+
67+
// server configuration variables
68+
const char *server_config_info = "server_config_info";
69+
const char *thread_handling = "thread_handling";
6370
} // namespace JSONKey
6471
} // namespace
6572

@@ -398,13 +405,19 @@ bool DataProvider::collect_dbs_number_info(rapidjson::Document *document) {
398405
return false;
399406
}
400407

401-
/* Note that this metric is update very X, so it may be inacurate.
408+
/* Note that metrics related to size are updated every 24hrs, so they may be
409+
inaccurate.
402410
We could make it accurate but that would need ANALYZE TABLE for every table
403-
which would be overkill.*/
411+
which would be overkill. */
412+
/* Collect the size of all databases. This information is available also via
413+
metrics collected in collect_se_info(), but we keep collecting it here
414+
as well for backward compatibility. If not needed, we can safely remove this
415+
method in the future. */
404416
bool DataProvider::collect_dbs_size_info(rapidjson::Document *document) {
417+
// total size of databases
405418
QueryResult result;
406419
if (do_query("SELECT IFNULL(ROUND(SUM(data_length + index_length), 1), '0') "
407-
"size_MB FROM information_schema.tables WHERE table_schema NOT "
420+
"bytes FROM information_schema.tables WHERE table_schema NOT "
408421
"IN('mysql', 'information_schema', 'performance_schema', 'sys')",
409422
&result) ||
410423
result.empty()) {
@@ -419,6 +432,10 @@ bool DataProvider::collect_dbs_size_info(rapidjson::Document *document) {
419432
return false;
420433
}
421434

435+
/* Collect the list of SEs in use. This information is available also via
436+
metrics collected in collect_se_info(), but we keep collecting it here
437+
as well for backward compatibility. If not needed, we can safely remove this
438+
method in the future. */
422439
bool DataProvider::collect_se_usage_info(rapidjson::Document *document) {
423440
QueryResult result;
424441
if (do_query("SELECT DISTINCT ENGINE FROM information_schema.tables WHERE "
@@ -441,6 +458,40 @@ bool DataProvider::collect_se_usage_info(rapidjson::Document *document) {
441458
return false;
442459
}
443460

461+
/* Collect the SE info (for now only size) */
462+
bool DataProvider::collect_se_info(rapidjson::Document *document) {
463+
QueryResult result;
464+
if (do_query("SELECT ENGINE, "
465+
"IFNULL(ROUND(SUM(data_length + index_length), 1), '0') bytes "
466+
"FROM information_schema.TABLES "
467+
"WHERE TABLE_SCHEMA NOT IN ('mysql', 'performance_schema', "
468+
"'information_schema', 'sys') "
469+
"GROUP BY ENGINE;",
470+
&result)) {
471+
return true;
472+
}
473+
474+
rapidjson::Document::AllocatorType &allocator = document->GetAllocator();
475+
rapidjson::Value se_info(rapidjson::Type::kArrayType);
476+
477+
for (auto &engine_iter : result) {
478+
rapidjson::Document engine_obj(rapidjson::Type::kObjectType);
479+
rapidjson::Value engine_name;
480+
engine_name.SetString(engine_iter[0].c_str(), allocator);
481+
engine_obj.AddMember(rapidjson::StringRef(JSONKey::name), engine_name,
482+
allocator);
483+
rapidjson::Value engine_size;
484+
engine_size.SetString(engine_iter[1].c_str(), allocator);
485+
engine_obj.AddMember(rapidjson::StringRef(JSONKey::size), engine_size,
486+
allocator);
487+
488+
se_info.PushBack(engine_obj, allocator);
489+
}
490+
document->AddMember(rapidjson::StringRef(JSONKey::se_info), se_info,
491+
allocator);
492+
return false;
493+
}
494+
444495
bool DataProvider::collect_group_replication_info(
445496
rapidjson::Document *document) {
446497
// Do fast check if there is anything to learn about GR
@@ -595,6 +646,25 @@ bool DataProvider::collect_db_replication_id(rapidjson::Document *document) {
595646
return false;
596647
}
597648

649+
bool DataProvider::collect_server_config(rapidjson::Document *document) {
650+
rapidjson::Document::AllocatorType &allocator = document->GetAllocator();
651+
rapidjson::Document server_config_json(rapidjson::Type::kObjectType);
652+
653+
/* Collect as much as possible. In case of error, skip and continue. */
654+
QueryResult result;
655+
if (!do_query("SELECT @@thread_handling", &result) && !result.empty()) {
656+
rapidjson::Value thread_handling;
657+
thread_handling.SetString(result[0][0].c_str(), allocator);
658+
server_config_json.AddMember(rapidjson::StringRef(JSONKey::thread_handling),
659+
thread_handling, allocator);
660+
}
661+
662+
document->AddMember(rapidjson::StringRef(JSONKey::server_config_info),
663+
server_config_json, allocator);
664+
665+
return false;
666+
}
667+
598668
bool DataProvider::collect_metrics(rapidjson::Document *document) {
599669
/* The configuration of this instance might have changed, so we need to colect
600670
it every time. */
@@ -618,8 +688,10 @@ bool DataProvider::collect_metrics(rapidjson::Document *document) {
618688
res |= collect_dbs_number_info(document);
619689
res |= collect_dbs_size_info(document);
620690
res |= collect_se_usage_info(document);
691+
res |= collect_se_info(document);
621692
res |= collect_group_replication_info(document);
622693
res |= collect_async_replication_info(document);
694+
res |= collect_server_config(document);
623695

624696
/* The requirement is to have db_replication_id key at the top of JSON
625697
structure. But it may originate from the different places. The above

components/percona_telemetry/data_provider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ class DataProvider {
8585
bool collect_dbs_number_info(rapidjson::Document *document);
8686
bool collect_dbs_size_info(rapidjson::Document *document);
8787
bool collect_se_usage_info(rapidjson::Document *document);
88+
bool collect_se_info(rapidjson::Document *document);
8889
bool collect_group_replication_info(rapidjson::Document *document);
8990
bool collect_async_replication_info(rapidjson::Document *document);
91+
bool collect_server_config(rapidjson::Document *document);
9092
bool collect_db_replication_id(rapidjson::Document *document);
9193
bool collect_metrics(rapidjson::Document *document);
9294

0 commit comments

Comments
 (0)