/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
cloud/blockstore/libs/endpoints_vhost/external_endpoint_stats.cpp
108 строк
3 KB
Kirill Pleshivtsev
Vhost server write encrypted zero blocks (#1728)
09 авг 2024, 14:51
Не верифицирован
09 авг 2024, 14:51
a97c4f2
Код
Авторство
О чём код?
#include "external_endpoint_stats.h" #include <cloud/blockstore/libs/diagnostics/server_stats.h> #include <cloud/storage/core/libs/diagnostics/critical_events.h> #include <cloud/storage/core/libs/diagnostics/max_calculator.h> #include <type_traits> namespace NCloud::NBlockStore::NServer { namespace { //////////////////////////////////////////////////////////////////////////////// template <typename F> auto GetHist(const NJson::TJsonValue& value, F&& func) { TVector<std::pair<std::invoke_result_t<F, ui64>, ui64>> hist; if (!value.IsArray()) { return hist; } const auto& array = value.GetArray(); hist.reserve(array.size()); for (const auto& v: array) { if (!v.IsArray()) { continue; } const auto& bucket = v.GetArray(); hist.emplace_back( func(bucket[0].GetUInteger()), bucket[1].GetUInteger()); } return hist; } void BatchCompleted( IServerStats& serverStats, EBlockStoreRequest kind, const NJson::TJsonValue& requestStats, const TString& clientId, const TString& diskId) { TMetricRequest request {kind}; serverStats.PrepareMetricRequest( request, clientId, diskId, 0, // startIndex 0, // requestBytes false); // unaligned auto times = GetHist(requestStats["times"], [] (ui64 us) { return TDuration::MicroSeconds(us); }); auto sizes = GetHist(requestStats["sizes"], [] (ui64 size) { return size; }); serverStats.BatchCompleted( request, requestStats["count"].GetUInteger(), requestStats["bytes"].GetUInteger(), requestStats["errors"].GetUInteger() + requestStats["encryptor_errors"].GetUInteger(), times, sizes); } } // namespace //////////////////////////////////////////////////////////////////////////////// void TEndpointStats::Update(const NJson::TJsonValue& stats) { BatchCompleted( *ServerStats, EBlockStoreRequest::ReadBlocks, stats["read"], ClientId, DiskId); BatchCompleted( *ServerStats, EBlockStoreRequest::WriteBlocks, stats["write"], ClientId, DiskId); // Report critical events if (stats.Has("crit_events")) { for (const auto& event: stats["crit_events"].GetArray()) { ReportCriticalEvent( GetCriticalEventFullName(event["name"].GetString()), event["message"].GetString(), false // verifyDebug ); } } } } // namespace NCloud::NBlockStore::NServer