MCPcopy Create free account
hub / github.com/ByConity/ByConity / writePartMetrics

Method writePartMetrics

src/Server/ServerPrometheusMetricsWriter.cpp:419–571  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

417}
418
419void ServerPrometheusMetricsWriter::writePartMetrics(WriteBuffer & wb)
420{
421 if (context->getServerType() == ServerType::cnch_server && send_part_metrics)
422 {
423 auto curr_ts = context->getTimestamp();
424 auto cnch_catalog = context->getCnchCatalog();
425
426 if (!cnch_catalog)
427 {
428 LOG_WARNING(&Poco::Logger::get("ServerPrometheusMetricsWriter"), "Cannot get catalog for part metrics");
429 }
430 else
431 {
432 auto db_models = cnch_catalog->getAllDataBases();
433
434 std::string parts_num_key(PART_METRICS_PREFIX);
435 parts_num_key.append(PARTS_NUMBER_LABEL);
436 std::string parts_size_key(PART_METRICS_PREFIX);
437 parts_size_key.append(PARTS_SIZE_LABEL);
438 std::string rows_count_key(PART_METRICS_PREFIX);
439 rows_count_key.append(ROWS_COUNT_LABEL);
440
441 for (auto & db_model : db_models)
442 {
443 auto & db_name = db_model.name();
444
445 auto tables = cnch_catalog->getTablesInDB(db_name);
446 for (auto & table_name : tables)
447 {
448 DB::StoragePtr storage = cnch_catalog->tryGetTable(*context, db_name, table_name, TxnTimestamp{context->getTimestamp()});
449 auto * cnch_table = dynamic_cast<StorageCnchMergeTree *>(storage.get());
450 if (!cnch_table)
451 continue;
452
453 Catalog::PartitionMap partitions;
454 cnch_catalog->getPartitionsFromMetastore(*cnch_table, partitions, nullptr);
455
456 for (auto & partition : partitions)
457 {
458 WriteBufferFromOwnString out;
459 partition.second->partition_ptr->serializeText(*cnch_table, out, format_settings);
460 auto partition_name = out.str();
461 auto partition_id = partition.first;
462
463 auto all_parts = cnch_catalog->getServerDataPartsInPartitions(storage, {partition_id}, curr_ts, nullptr);
464 auto visible_parts = CnchPartsHelper::calcVisibleParts(all_parts, false);
465 auto current_visible = visible_parts.cbegin();
466
467 /// Total parts
468 UInt64 total_parts_num = all_parts.size();
469 UInt64 total_parts_size = 0;
470 UInt64 total_rows_count = 0;
471 /// Visible parts
472 UInt64 visible_parts_num = visible_parts.size();
473 UInt64 visible_parts_size = 0;
474 UInt64 visible_rows_count = 0;
475 /// Invisible parts
476 UInt64 invisible_parts_num = total_parts_num - visible_parts_num;

Callers

nothing calls this directly

Calls 15

calcVisiblePartsFunction · 0.85
getPartMetricKeyLabelFunction · 0.85
getServerTypeMethod · 0.80
getAllDataBasesMethod · 0.80
getTablesInDBMethod · 0.80
infoMethod · 0.80
writeOutLineFunction · 0.70
getFunction · 0.50
getTimestampMethod · 0.45
getCnchCatalogMethod · 0.45

Tested by

no test coverage detected