begin metric counting call switch events;

pull/128/head
Bryan Biedenkapp 3 months ago
parent 9ef9ba34f4
commit c9bb239771

@ -44,10 +44,12 @@ static const uint64_t NS_PER_DAY = 86400ULL * NS_PER_SECOND;
std::atomic<int32_t> TrafficNetwork::MetricsLogging::s_totalActiveCalls {0};
std::atomic<uint64_t> TrafficNetwork::MetricsLogging::s_totalCallsProcessed {0U};
std::atomic<uint64_t> TrafficNetwork::MetricsLogging::s_totalCallCollisions {0U};
std::atomic<uint64_t> TrafficNetwork::MetricsLogging::s_totalCallSwitches {0U};
namespace {
static const char* SQLITE_COUNTER_CALLS_PROCESSED = "total_calls_processed";
static const char* SQLITE_COUNTER_CALL_COLLISIONS = "total_call_collisions";
static const char* SQLITE_COUNTER_CALL_SWITCHES = "total_call_switches";
/**
* @brief Get the current time in nanoseconds since the epoch.
@ -969,6 +971,15 @@ void TrafficNetwork::MetricsLogging::incrementCallCollisions(TrafficNetwork* net
persistSQLiteCounter(network, SQLITE_COUNTER_CALL_COLLISIONS, value);
}
/* Increments the total call switches counter. */
void TrafficNetwork::MetricsLogging::incrementCallSwitches(TrafficNetwork* network)
{
uint64_t value = s_totalCallSwitches.fetch_add(1U, std::memory_order_relaxed) + 1U;
persistSQLiteCounter(network, SQLITE_COUNTER_CALL_SWITCHES, value);
}
/* Resets the total processed calls counter to zero. */
void TrafficNetwork::MetricsLogging::resetCallsProcessed(TrafficNetwork* network)
@ -987,6 +998,15 @@ void TrafficNetwork::MetricsLogging::resetCallCollisions(TrafficNetwork* network
persistSQLiteCounter(network, SQLITE_COUNTER_CALL_COLLISIONS, 0U);
}
/* Resets the total call switches counter to zero. */
void TrafficNetwork::MetricsLogging::resetCallSwitches(TrafficNetwork* network)
{
s_totalCallSwitches.store(0U, std::memory_order_relaxed);
persistSQLiteCounter(network, SQLITE_COUNTER_CALL_SWITCHES, 0U);
}
/* Gets the active call counter. */
int32_t TrafficNetwork::MetricsLogging::getTotalActiveCalls()
@ -1008,6 +1028,13 @@ uint64_t TrafficNetwork::MetricsLogging::getTotalCallCollisions()
return s_totalCallCollisions.load(std::memory_order_relaxed);
}
/* Gets the total call switches counter. */
uint64_t TrafficNetwork::MetricsLogging::getTotalCallSwitches()
{
return s_totalCallSwitches.load(std::memory_order_relaxed);
}
/* Logs a activity transfer event. */
void TrafficNetwork::MetricsLogging::logActivity(TrafficNetwork* network, uint32_t peerId, const std::string& identity, const std::string& msg)
@ -1566,7 +1593,7 @@ void TrafficNetwork::MetricsLogging::loadSQLiteCounters(TrafficNetwork* network)
}
sqlite3_stmt* stmt = nullptr;
std::string sql = "SELECT key, value FROM metrics_counters WHERE key IN (?, ?);";
std::string sql = "SELECT key, value FROM metrics_counters WHERE key IN (?, ?, ?);";
if (sqlite3_prepare_v2(network->m_sqliteDB, sql.c_str(), -1, &stmt, nullptr) != SQLITE_OK) {
LogWarning(LOG_MASTER, "Unable to prepare SQLite counter load statement: %s", sqlite3_errmsg(network->m_sqliteDB));
return;
@ -1574,11 +1601,14 @@ void TrafficNetwork::MetricsLogging::loadSQLiteCounters(TrafficNetwork* network)
sqlite3_bind_text(stmt, 1, SQLITE_COUNTER_CALLS_PROCESSED, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 2, SQLITE_COUNTER_CALL_COLLISIONS, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 3, SQLITE_COUNTER_CALL_SWITCHES, -1, SQLITE_STATIC);
uint64_t loadedProcessed = 0U;
uint64_t loadedCollisions = 0U;
uint64_t loadedSwitches = 0U;
bool hasProcessed = false;
bool hasCollisions = false;
bool hasSwitches = false;
while (sqlite3_step(stmt) == SQLITE_ROW) {
const char* key = (const char*)sqlite3_column_text(stmt, 0);
@ -1593,6 +1623,9 @@ void TrafficNetwork::MetricsLogging::loadSQLiteCounters(TrafficNetwork* network)
} else if (::strcmp(key, SQLITE_COUNTER_CALL_COLLISIONS) == 0) {
loadedCollisions = value;
hasCollisions = true;
} else if (::strcmp(key, SQLITE_COUNTER_CALL_SWITCHES) == 0) {
loadedSwitches = value;
hasSwitches = true;
}
}
@ -1604,6 +1637,9 @@ void TrafficNetwork::MetricsLogging::loadSQLiteCounters(TrafficNetwork* network)
if (hasCollisions) {
s_totalCallCollisions.store(loadedCollisions, std::memory_order_relaxed);
}
if (hasSwitches) {
s_totalCallSwitches.store(loadedSwitches, std::memory_order_relaxed);
}
}
/* Persists a single metrics counter to SQLite. */

@ -1044,6 +1044,11 @@ namespace network
* @param network Pointer to the TrafficNetwork instance.
*/
static void incrementCallCollisions(TrafficNetwork* network);
/**
* @brief Increments the total call switches counter.
* @param network Pointer to the TrafficNetwork instance.
*/
static void incrementCallSwitches(TrafficNetwork* network);
/**
* @brief Resets the total processed calls counter to zero.
* @param network Pointer to the TrafficNetwork instance.
@ -1054,6 +1059,11 @@ namespace network
* @param network Pointer to the TrafficNetwork instance.
*/
static void resetCallCollisions(TrafficNetwork* network);
/**
* @brief Resets the total call switches counter to zero.
* @param network Pointer to the TrafficNetwork instance.
*/
static void resetCallSwitches(TrafficNetwork* network);
/**
* @brief Gets the active call counter.
* @return Active call counter value.
@ -1069,6 +1079,11 @@ namespace network
* @return Total call collisions counter value.
*/
static uint64_t getTotalCallCollisions();
/**
* @brief Gets the total call switches counter.
* @return Total call switches counter value.
*/
static uint64_t getTotalCallSwitches();
/**
* @brief Logs a activity transfer event.
@ -1170,6 +1185,7 @@ namespace network
static std::atomic<int32_t> s_totalActiveCalls;
static std::atomic<uint64_t> s_totalCallsProcessed;
static std::atomic<uint64_t> s_totalCallCollisions;
static std::atomic<uint64_t> s_totalCallSwitches;
/**
* @brief Checks if the SQLite database for the specified TrafficNetwork instance is blank.

@ -219,6 +219,8 @@ bool TagAnalogData::processFrame(const uint8_t* data, uint32_t len, uint32_t pee
m_status[dstId].callTakeover = false; // reset takeover flag
m_status.unlock();
TrafficNetwork::MetricsLogging::incrementCallSwitches(m_network);
status = m_status[dstId];
}
@ -292,6 +294,8 @@ bool TagAnalogData::processFrame(const uint8_t* data, uint32_t len, uint32_t pee
m_status[dstId].srcId = srcId;
m_status[dstId].ssrc = ssrc;
m_status.unlock();
TrafficNetwork::MetricsLogging::incrementCallSwitches(m_network);
}
}
}

@ -332,6 +332,8 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
m_status[dstId].callTakeover = false; // reset takeover flag
m_status.unlock();
TrafficNetwork::MetricsLogging::incrementCallSwitches(m_network);
status = m_status[dstId];
}
@ -349,6 +351,7 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
peerId, ssrc, srcId, dstId, slotNo, streamId, status.peerId, status.srcId, status.dstId, status.slotNo, status.streamId, fromUpstream);
m_status[dstId].srcId = srcId;
}
TrafficNetwork::MetricsLogging::incrementCallSwitches(m_network);
m_status.unlock();
}
else {
@ -420,6 +423,8 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
m_status[dstId].srcId = srcId;
m_status[dstId].ssrc = ssrc;
m_status.unlock();
TrafficNetwork::MetricsLogging::incrementCallSwitches(m_network);
}
}
}

@ -359,6 +359,8 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
m_status[dstId].callTakeover = false; // reset takeover flag
m_status.unlock();
TrafficNetwork::MetricsLogging::incrementCallSwitches(m_network);
status = m_status[dstId];
}
@ -377,6 +379,7 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
m_status[dstId].srcId = srcId;
}
m_status.unlock();
TrafficNetwork::MetricsLogging::incrementCallSwitches(m_network);
}
else {
if (status.srcId != 0U && status.srcId != srcId) {
@ -447,6 +450,8 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
m_status[dstId].srcId = srcId;
m_status[dstId].ssrc = ssrc;
m_status.unlock();
TrafficNetwork::MetricsLogging::incrementCallSwitches(m_network);
}
}
}

@ -439,6 +439,8 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
m_status[dstId].callTakeover = false; // reset takeover flag
m_status.unlock();
TrafficNetwork::MetricsLogging::incrementCallSwitches(m_network);
status = m_status[dstId];
}
@ -457,6 +459,7 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
m_status[dstId].srcId = srcId;
}
m_status.unlock();
TrafficNetwork::MetricsLogging::incrementCallSwitches(m_network);
} else {
if (status.srcId != 0U && status.srcId != srcId) {
bool hasCallPriority = false;
@ -527,6 +530,8 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
m_status[dstId].srcId = srcId;
m_status[dstId].ssrc = ssrc;
m_status.unlock();
TrafficNetwork::MetricsLogging::incrementCallSwitches(m_network);
}
}
}

@ -684,6 +684,7 @@ void RESTAPI::initializeEndpoints()
m_dispatcher.match(FNE_GET_RESET_TOTAL_CALLS).get(REST_API_BIND(RESTAPI::restAPI_GetResetTotalCalls, this));
m_dispatcher.match(FNE_GET_RESET_ACTIVE_CALLS).get(REST_API_BIND(RESTAPI::restAPI_GetResetActiveCalls, this));
m_dispatcher.match(FNE_GET_RESET_CALL_COLLISIONS).get(REST_API_BIND(RESTAPI::restAPI_GetResetCallCollisions, this));
m_dispatcher.match(FNE_GET_RESET_CALL_SWITCHES).get(REST_API_BIND(RESTAPI::restAPI_GetResetCallSwitches, this));
m_dispatcher.match(FNE_GET_UNIT_REG_LIST).get(REST_API_BIND(RESTAPI::restAPI_GetUnitRegList, this));
m_dispatcher.match(FNE_GET_AFF_LIST).get(REST_API_BIND(RESTAPI::restAPI_GetAffList, this));
m_dispatcher.match(FNE_GET_GRANT_LIST).get(REST_API_BIND(RESTAPI::restAPI_GetGrantList, this));
@ -2124,6 +2125,25 @@ void RESTAPI::restAPI_GetResetCallCollisions(const HTTPPayload& request, HTTPPay
reply.payload(response);
}
/* REST API endpoint; implements get reset call switches request. */
void RESTAPI::restAPI_GetResetCallSwitches(const HTTPPayload& request, HTTPPayload& reply, const RequestMatch& match)
{
if (!validateAuth(request, reply)) {
return;
}
json::object response = json::object();
setResponseDefaultStatus(response);
LogInfoEx(LOG_REST, "request to reset total call switches");
if (m_network != nullptr) {
TrafficNetwork::MetricsLogging::resetCallSwitches(m_network);
}
reply.payload(response);
}
/* REST API endpoint; implements get unit registration list request. */
void RESTAPI::restAPI_GetUnitRegList(const HTTPPayload& request, HTTPPayload& reply, const RequestMatch& match)

@ -420,6 +420,14 @@ private:
*/
void restAPI_GetResetCallCollisions(const HTTPPayload& request, HTTPPayload& reply, const restapi::RequestMatch& match);
/**
* @brief REST API endpoint; implements put reset call switches request.
* @param request HTTP request.
* @param reply HTTP reply.
* @param match HTTP request matcher.
*/
void restAPI_GetResetCallSwitches(const HTTPPayload& request, HTTPPayload& reply, const restapi::RequestMatch& match);
/**
* @brief REST API endpoint; implements get unit registration list request.
* @param request HTTP request.

@ -63,6 +63,7 @@
#define FNE_GET_RESET_TOTAL_CALLS "/stat-reset-total-calls"
#define FNE_GET_RESET_ACTIVE_CALLS "/stat-reset-active-calls"
#define FNE_GET_RESET_CALL_COLLISIONS "/stat-reset-call-collisions"
#define FNE_GET_RESET_CALL_SWITCHES "/stat-reset-call-switches"
#define FNE_GET_UNIT_REG_LIST "/report-unit-regs"
#define FNE_GET_AFF_LIST "/report-affiliations"
#define FNE_GET_GRANT_LIST "/report-grants"

Loading…
Cancel
Save

Powered by TurnKey Linux.