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