MXS-2078 Add support for holding router specific server data.

New class to hold the statistics, part of which is currently in
RWSplitSession. Simple API in Backend to create session
specific data.
This commit is contained in:
Niclas Antti
2018-11-05 13:59:14 +02:00
parent 13a0390de6
commit 5175d2b2d7
4 changed files with 155 additions and 0 deletions

View File

@ -259,3 +259,29 @@ bool Backend::write_stored_command()
return rval;
}
const maxbase::StopWatch& Backend::session_timer() const
{
return m_session_timer;
}
const maxbase::IntervalTimer& Backend::select_timer() const
{
return m_select_timer;
}
void Backend::select_started()
{
m_select_timer.start_interval();
}
void Backend::select_ended()
{
m_select_timer.end_interval();
++m_num_selects;
}
int64_t Backend::num_selects() const
{
return m_num_selects;
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2016 MariaDB Corporation Ab
*
* 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: 2022-01-01
*
* 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.
*/
#include <maxscale/session_stats.hh>
#include <iostream>
void maxscale::ServerStats::start_session()
{
// nop for now
}
void maxscale::ServerStats::end_session(maxbase::Duration sess_duration,
maxbase::Duration active_duration,
int64_t num_selects)
{
m_ave_session_dur.add(sess_duration.secs());
m_ave_active_dur.add(active_duration.secs());
m_num_ave_session_selects.add(num_selects);
}
maxscale::ServerStats& maxscale::ServerStats::operator+=(const maxscale::ServerStats& rhs)
{
total += rhs.total;
read += rhs.read;
write += rhs.write;
m_ave_session_dur += rhs.m_ave_session_dur;
m_ave_active_dur += rhs.m_ave_active_dur;
m_num_ave_session_selects += rhs.m_num_ave_session_selects;
return *this;
}
maxscale::ServerStats::CurrentStats maxscale::ServerStats::current_stats() const
{
double sess_secs = m_ave_session_dur.average();
double active_secs = m_ave_active_dur.average();
double active = 100 * active_secs / sess_secs;
return {maxbase::Duration(sess_secs),
active,
static_cast<int64_t>(m_num_ave_session_selects.average()),
total,
read,
write};
}