userver: userver/storages/sqlite/infra/statistics/statistics.hpp Source File
Loading...
Searching...
No Matches
statistics.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/sqlite/infra/statistics/statistics.hpp
4/// @brief SQLite pool statistics structs and metric dump helpers
5
6#include <cstdint>
7
8#include <userver/utils/statistics/histogram.hpp>
9#include <userver/utils/statistics/histogram_aggregator.hpp>
10#include <userver/utils/statistics/rate_counter.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace storages::sqlite::infra::statistics {
15
16using RateCounter = utils::statistics::RateCounter;
17
18inline constexpr double kDefaultBoundsArray[] = {5, 10, 20, 35, 60, 100, 173, 300, 520};
19
20struct PoolConnectionStatistics final {
21 RateCounter overload{};
22 RateCounter closed{};
23 RateCounter created{};
24 RateCounter acquired{};
25 RateCounter released{};
26};
27
28struct PoolQueriesStatistics final {
29 RateCounter total{};
30 RateCounter error{};
31 RateCounter executed{};
32 utils::statistics::Histogram timings{kDefaultBoundsArray};
33};
34
35struct PoolTransactionsStatistics final {
36 RateCounter total{};
37 RateCounter commit{};
38 RateCounter rollback{};
39 utils::statistics::Histogram timings{kDefaultBoundsArray};
40};
41
42struct PoolTransactionsStatisticsAggregated final {
43 RateCounter total{};
44 RateCounter commit{};
45 RateCounter rollback{};
46 utils::statistics::HistogramAggregator timings{kDefaultBoundsArray};
47
48 void Add(PoolTransactionsStatistics& other);
49};
50
51struct PoolStatistics final {
52 PoolConnectionStatistics connections{};
53 PoolQueriesStatistics queries{};
54 PoolTransactionsStatistics transactions{};
55};
56
57struct AggregatedInstanceStatistics final {
58 const PoolConnectionStatistics* write_connections{nullptr};
59 const PoolConnectionStatistics* read_connections{nullptr};
60 const PoolQueriesStatistics* write_queries{nullptr};
61 const PoolQueriesStatistics* read_queries{nullptr};
62 const PoolTransactionsStatistics* transaction{nullptr};
63 const PoolTransactionsStatisticsAggregated* transaction_aggregated{nullptr};
64};
65
66void DumpMetric(utils::statistics::Writer& writer, const AggregatedInstanceStatistics& stats);
67
68void DumpMetric(utils::statistics::Writer& writer, const PoolQueriesStatistics& stats);
69
70void DumpMetric(utils::statistics::Writer& writer, const PoolConnectionStatistics& stats);
71
72void DumpMetric(utils::statistics::Writer& writer, const PoolTransactionsStatistics& stats);
73
74} // namespace storages::sqlite::infra::statistics
75
76USERVER_NAMESPACE_END