forked from mariadb-corporation/MaxScale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_stats.hh
92 lines (73 loc) · 1.9 KB
/
session_stats.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Copyright (c) 2018 MariaDB Corporation Ab
* Copyright (c) 2023 MariaDB plc, Finnish Branch
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
*
* Change Date: 2025-09-12
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#pragma once
#include <maxscale/ccdefs.hh>
#include <unordered_map>
#include <maxscale/server.hh>
#include <maxbase/average.hh>
#include <maxbase/stopwatch.hh>
namespace maxscale
{
/** SessionStats is a class holding statistics associated with a session */
class SessionStats
{
public:
struct CurrentStats
{
maxbase::Duration ave_session_dur;
double ave_session_active_pct;
int64_t ave_session_selects;
int64_t total_queries;
int64_t total_read_queries;
int64_t total_write_queries;
};
void update(maxbase::Duration sess_duration,
maxbase::Duration active_duration,
int64_t num_selects);
void inc_total()
{
++m_total;
}
void inc_read()
{
++m_read;
}
void inc_write()
{
++m_write;
}
int64_t total() const
{
return m_total;
}
int64_t read() const
{
return m_read;
}
int64_t write() const
{
return m_write;
}
CurrentStats current_stats() const;
SessionStats& operator+=(const SessionStats& rhs);
private:
int64_t m_total = 0;
int64_t m_read = 0;
int64_t m_write = 0;
maxbase::CumulativeAverage m_ave_session_dur;
maxbase::CumulativeAverage m_ave_active_dur;
maxbase::CumulativeAverage m_num_ave_session_selects;
};
using TargetSessionStats = std::unordered_map<mxs::Target*, SessionStats>;
}