6#include <unordered_map>
9#include <userver/storages/postgres/detail/time_types.hpp>
11#include <userver/congestion_control/controllers/linear.hpp>
12#include <userver/utils/statistics/min_max_avg.hpp>
13#include <userver/utils/statistics/percentile.hpp>
14#include <userver/utils/statistics/recentperiod.hpp>
15#include <userver/utils/statistics/relaxed_counter.hpp>
16#include <userver/utils/statistics/writer.hpp>
18USERVER_NAMESPACE_BEGIN
23template <
typename Counter,
typename PercentileAccumulator>
69template <
typename Counter,
typename MmaAccumulator>
95template <
typename MmaAccumulator>
104template <
typename Counter,
typename PercentileAccumulator,
105 typename MmaAccumulator>
140 InstanceStatisticsNonatomic() =
default;
142 template <
typename Statistics>
143 InstanceStatisticsNonatomic(
const Statistics& stats) {
151 const InstanceStatistics& stats,
152 const decltype(InstanceStatistics::topology)& topology_stats) {
153 connection.open_total = stats.connection.open_total;
154 connection.drop_total = stats.connection.drop_total;
155 connection.active = stats.connection.active;
156 connection.used = stats.connection.used;
157 connection.maximum = stats.connection.maximum;
158 connection.waiting = stats.connection.waiting;
159 connection.error_total = stats.connection.error_total;
160 connection.error_timeout = stats.connection.error_timeout;
161 connection.prepared_statements =
162 stats.connection.prepared_statements.GetStatsForPeriod();
163 connection.max_queue_size = stats.connection.max_queue_size;
165 transaction.total = stats.transaction.total;
166 transaction.commit_total = stats.transaction.commit_total;
167 transaction.rollback_total = stats.transaction.rollback_total;
168 transaction.out_of_trx_total = stats.transaction.out_of_trx_total;
169 transaction.parse_total = stats.transaction.parse_total;
170 transaction.execute_total = stats.transaction.execute_total;
171 transaction.reply_total = stats.transaction.reply_total;
172 transaction.portal_bind_total = stats.transaction.portal_bind_total;
173 transaction.error_execute_total = stats.transaction.error_execute_total;
174 transaction.execute_timeout = stats.transaction.execute_timeout;
175 transaction.duplicate_prepared_statements =
176 stats.transaction.duplicate_prepared_statements;
177 transaction.total_percentile =
178 stats.transaction.total_percentile.GetStatsForPeriod();
179 transaction.busy_percentile =
180 stats.transaction.busy_percentile.GetStatsForPeriod();
181 transaction.wait_start_percentile =
182 stats.transaction.wait_start_percentile.GetStatsForPeriod();
183 transaction.wait_end_percentile =
184 stats.transaction.wait_end_percentile.GetStatsForPeriod();
185 transaction.return_to_pool_percentile =
186 stats.transaction.return_to_pool_percentile.GetStatsForPeriod();
188 topology.roundtrip_time = topology_stats.roundtrip_time.GetStatsForPeriod();
189 topology.replication_lag =
190 topology_stats.replication_lag.GetStatsForPeriod();
192 pool_exhaust_errors = stats.pool_exhaust_errors;
193 queue_size_errors = stats.queue_size_errors;
194 connection_percentile = stats.connection_percentile.GetStatsForPeriod();
195 acquire_percentile = stats.acquire_percentile.GetStatsForPeriod();
201 const std::unordered_map<std::string, Percentile>& timings) {
202 for (
const auto& [name, percentile] : timings) {
203 const auto [it, inserted] =
204 statement_timings.try_emplace(name, percentile);
205 if (!inserted) it->second.Add(percentile);
211 std::unordered_map<std::string, Percentile> statement_timings;
235void DumpMetric(USERVER_NAMESPACE::
utils::statistics::Writer& writer,