Add protocolgroup prometheus metrics

This commit is contained in:
adel-signal 2024-04-03 10:35:28 -07:00 committed by Richard Russo
parent f5bc420a2e
commit 2fc7c99b16
6 changed files with 189 additions and 131 deletions

View File

@ -3663,7 +3663,8 @@ void turn_report_allocation_set(void *a, turn_time_t lifetime, int refresh) {
#endif
{
if (!refresh) {
prom_inc_allocation(get_ioa_socket_type(ss->client_socket), get_ioa_socket_address_family(ss->client_socket));
prom_inc_allocation(get_ioa_socket_type(ss->client_socket),
get_ioa_socket_address_family(ss->client_socket), ss->protocolgroup);
}
}
}
@ -3727,26 +3728,26 @@ void turn_report_allocation_delete(void *a, SOCKET_TYPE socket_type, int family)
prom_set_finished_traffic(ss->realm_options.name, (const char *)ss->username,
(unsigned long)(ss->t_received_packets), (unsigned long)(ss->t_received_bytes),
(unsigned long)(ss->t_sent_packets), (unsigned long)(ss->t_sent_bytes),
(unsigned long)ss->t_before_ping_packets, false);
(unsigned long)ss->t_before_ping_packets, false, ss->protocolgroup);
prom_set_finished_traffic(
ss->realm_options.name, (const char *)ss->username, (unsigned long)(ss->t_peer_received_packets),
(unsigned long)(ss->t_peer_received_bytes), (unsigned long)(ss->t_peer_sent_packets),
(unsigned long)(ss->t_peer_sent_bytes), 0, true);
(unsigned long)(ss->t_peer_sent_bytes), 0, true, ss->protocolgroup);
} else {
// Set prometheus traffic metrics
prom_set_finished_traffic(NULL, (const char *)ss->username, (unsigned long)(ss->t_received_packets),
(unsigned long)(ss->t_received_bytes), (unsigned long)(ss->t_sent_packets),
(unsigned long)(ss->t_sent_bytes), (unsigned long)ss->t_before_ping_packets,
false);
false, ss->protocolgroup);
prom_set_finished_traffic(NULL, (const char *)ss->username, (unsigned long)(ss->t_peer_received_packets),
(unsigned long)(ss->t_peer_received_bytes),
(unsigned long)(ss->t_peer_sent_packets), (unsigned long)(ss->t_peer_sent_bytes),
0, true);
0, true, ss->protocolgroup);
}
turn_time_t ct = get_turn_server_time(server) - ss->start_time;
const uint32_t byte_to_kilobit = 125;
uint64_t sent_rate_kbps = ss->sent_rate / byte_to_kilobit;
prom_dec_allocation(socket_type, family, (unsigned long)ct, (unsigned long)sent_rate_kbps);
prom_dec_allocation(socket_type, family, (unsigned long)ct, (unsigned long)sent_rate_kbps, ss->protocolgroup);
}
}
}

View File

@ -9,6 +9,8 @@
#if !defined(TURN_NO_PROMETHEUS)
#define PROTOCOL_GROUP_LABEL "protocol-group"
prom_counter_t *stun_binding_request;
prom_counter_t *stun_binding_response;
prom_counter_t *stun_binding_error;
@ -86,8 +88,9 @@ void start_prometheus_server(void) {
}
prom_collector_registry_default_init();
const char *label[] = {"realm", NULL};
size_t nlabels = 1;
// Signal change to add protocol-group label to metrics
const char *label[] = {"realm", PROTOCOL_GROUP_LABEL, PROTOCOL_GROUP_LABEL};
size_t nlabels = 2;
if (turn_params.prometheus_username_labels) {
label[1] = "user";
@ -122,90 +125,107 @@ void start_prometheus_server(void) {
turn_traffic_peer_sentb = prom_collector_registry_must_register_metric(
prom_counter_new("turn_traffic_peer_sentb", "Represents finished sessions peer sent bytes", nlabels, label));
const char *traffic_label[] = {PROTOCOL_GROUP_LABEL};
const size_t ntraffic_labels = 1;
// Create total finished traffic counter metrics
turn_total_traffic_rcvp = prom_collector_registry_must_register_metric(
prom_counter_new("turn_total_traffic_rcvp", "Represents total finished sessions received packets", 0, NULL));
turn_total_traffic_rcvb = prom_collector_registry_must_register_metric(
prom_counter_new("turn_total_traffic_rcvb", "Represents total finished sessions received bytes", 0, NULL));
turn_total_traffic_sentp = prom_collector_registry_must_register_metric(
prom_counter_new("turn_total_traffic_sentp", "Represents total finished sessions sent packets", 0, NULL));
turn_total_traffic_sentb = prom_collector_registry_must_register_metric(
prom_counter_new("turn_total_traffic_sentb", "Represents total finished sessions sent bytes", 0, NULL));
prom_counter_new("turn_total_traffic_rcvp", "Represents total finished sessions received packets",
ntraffic_labels, traffic_label));
turn_total_traffic_rcvb = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_total_traffic_rcvb", "Represents total finished sessions received bytes", ntraffic_labels, traffic_label));
turn_total_traffic_sentp = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_total_traffic_sentp", "Represents total finished sessions sent packets", ntraffic_labels, traffic_label));
turn_total_traffic_sentb = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_total_traffic_sentb", "Represents total finished sessions sent bytes", ntraffic_labels, traffic_label));
// Create total finished sessions traffic for peers counter metrics
turn_total_traffic_peer_rcvp = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_total_traffic_peer_rcvp", "Represents total finished sessions peer received packets", 0, NULL));
turn_total_traffic_peer_rcvb = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_total_traffic_peer_rcvb", "Represents total finished sessions peer received bytes", 0, NULL));
turn_total_traffic_peer_sentp = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_total_traffic_peer_sentp", "Represents total finished sessions peer sent packets", 0, NULL));
turn_total_traffic_peer_rcvp = prom_collector_registry_must_register_metric(
prom_counter_new("turn_total_traffic_peer_rcvp", "Represents total finished sessions peer received packets",
ntraffic_labels, traffic_label));
turn_total_traffic_peer_rcvb = prom_collector_registry_must_register_metric(
prom_counter_new("turn_total_traffic_peer_rcvb", "Represents total finished sessions peer received bytes",
ntraffic_labels, traffic_label));
turn_total_traffic_peer_sentp = prom_collector_registry_must_register_metric(
prom_counter_new("turn_total_traffic_peer_sentp", "Represents total finished sessions peer sent packets",
ntraffic_labels, traffic_label));
turn_total_traffic_peer_sentb = prom_collector_registry_must_register_metric(
prom_counter_new("turn_total_traffic_peer_sentb", "Represents total finished sessions peer sent bytes", 0, NULL));
prom_counter_new("turn_total_traffic_peer_sentb", "Represents total finished sessions peer sent bytes",
ntraffic_labels, traffic_label));
// Signal change to add protocol-group metric label
// Create total completed session counter metric
const char *total_sessions_labels[] = {"duration", "sent_rate"};
const char *total_sessions_labels[] = {"duration", "sent_rate", PROTOCOL_GROUP_LABEL};
turn_total_sessions = prom_collector_registry_must_register_metric(
prom_counter_new("turn_total_sessions", "Represents total completed sessions", 2, total_sessions_labels));
prom_counter_new("turn_total_sessions", "Represents total completed sessions", 3, total_sessions_labels));
// Create total allocations number gauge metric
const char *total_allocations_labels[] = {"type", "client_addr_family"};
const char *total_allocations_labels[] = {"type", "client_addr_family", PROTOCOL_GROUP_LABEL};
turn_total_allocations = prom_collector_registry_must_register_metric(
prom_gauge_new("turn_total_allocations", "Represents current allocations number", 2, total_allocations_labels));
prom_gauge_new("turn_total_allocations", "Represents current allocations number", 3, total_allocations_labels));
// Signal change to add metrics
// Create round trip time pseudo-histogram metrics
// values must be kept in sync with observation function below
turn_rtt_client[0] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_client_le_25ms", "Represents measured round trip time of client with channel", 0, NULL));
turn_rtt_client[1] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_client_le_50ms", "Represents measured round trip time of client with channel", 0, NULL));
turn_rtt_client[2] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_client_le_100ms", "Represents measured round trip time of client with channel", 0, NULL));
turn_rtt_client[3] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_client_le_200ms", "Represents measured round trip time of client with channel", 0, NULL));
turn_rtt_client[4] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_client_le_400ms", "Represents measured round trip time of client with channel", 0, NULL));
turn_rtt_client[5] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_client_le_800ms", "Represents measured round trip time of client with channel", 0, NULL));
turn_rtt_client[6] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_client_le_1500ms", "Represents measured round trip time of client with channel", 0, NULL));
turn_rtt_client[7] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_client_more", "Represents measured round trip time of client with channel", 0, NULL));
const char *rtt_labels[] = {PROTOCOL_GROUP_LABEL};
const size_t nrtt_labels = 1;
turn_rtt_client[0] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_client_le_25ms", "Represents measured round trip time of client with channel",
nrtt_labels, rtt_labels));
turn_rtt_client[1] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_client_le_50ms", "Represents measured round trip time of client with channel",
nrtt_labels, rtt_labels));
turn_rtt_client[2] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_client_le_100ms", "Represents measured round trip time of client with channel",
nrtt_labels, rtt_labels));
turn_rtt_client[3] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_client_le_200ms", "Represents measured round trip time of client with channel",
nrtt_labels, rtt_labels));
turn_rtt_client[4] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_client_le_400ms", "Represents measured round trip time of client with channel",
nrtt_labels, rtt_labels));
turn_rtt_client[5] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_client_le_800ms", "Represents measured round trip time of client with channel",
nrtt_labels, rtt_labels));
turn_rtt_client[6] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_client_le_1500ms", "Represents measured round trip time of client with channel",
nrtt_labels, rtt_labels));
turn_rtt_client[7] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_client_more", "Represents measured round trip time of client with channel", nrtt_labels, rtt_labels));
turn_rtt_peer[0] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_peer_le_25ms", "Represents measured round trip time of peer with channel", 0, NULL));
turn_rtt_peer[1] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_peer_le_50ms", "Represents measured round trip time of peer with channel", 0, NULL));
turn_rtt_peer[2] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_peer_le_100ms", "Represents measured round trip time of peer with channel", 0, NULL));
turn_rtt_peer[3] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_peer_le_200ms", "Represents measured round trip time of peer with channel", 0, NULL));
turn_rtt_peer[4] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_peer_le_400ms", "Represents measured round trip time of peer with channel", 0, NULL));
turn_rtt_peer[5] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_peer_le_800ms", "Represents measured round trip time of peer with channel", 0, NULL));
turn_rtt_peer[6] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_peer_le_1500ms", "Represents measured round trip time of peer with channel", 0, NULL));
turn_rtt_peer[7] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_peer_more", "Represents measured round trip time of peer with channel", 0, NULL));
turn_rtt_peer[0] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_peer_le_25ms", "Represents measured round trip time of peer with channel", nrtt_labels, rtt_labels));
turn_rtt_peer[1] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_peer_le_50ms", "Represents measured round trip time of peer with channel", nrtt_labels, rtt_labels));
turn_rtt_peer[2] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_peer_le_100ms", "Represents measured round trip time of peer with channel", nrtt_labels, rtt_labels));
turn_rtt_peer[3] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_peer_le_200ms", "Represents measured round trip time of peer with channel", nrtt_labels, rtt_labels));
turn_rtt_peer[4] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_peer_le_400ms", "Represents measured round trip time of peer with channel", nrtt_labels, rtt_labels));
turn_rtt_peer[5] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_peer_le_800ms", "Represents measured round trip time of peer with channel", nrtt_labels, rtt_labels));
turn_rtt_peer[6] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_peer_le_1500ms", "Represents measured round trip time of peer with channel", nrtt_labels, rtt_labels));
turn_rtt_peer[7] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_peer_more", "Represents measured round trip time of peer with channel", nrtt_labels, rtt_labels));
turn_rtt_combined[0] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_combined_le_25ms", "Represents combined round trip time of channel", 0, NULL));
turn_rtt_combined[1] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_combined_le_50ms", "Represents combined round trip time of channel", 0, NULL));
turn_rtt_combined[2] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_combined_le_100ms", "Represents combined round trip time of channel", 0, NULL));
turn_rtt_combined[3] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_combined_le_200ms", "Represents combined round trip time of channel", 0, NULL));
turn_rtt_combined[4] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_combined_le_400ms", "Represents combined round trip time of channel", 0, NULL));
turn_rtt_combined[5] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_combined_le_800ms", "Represents combined round trip time of channel", 0, NULL));
turn_rtt_combined[6] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_combined_le_1500ms", "Represents combined round trip time of channel", 0, NULL));
turn_rtt_combined[7] = prom_collector_registry_must_register_metric(
prom_counter_new("turn_rtt_combined_more", "Represents combined round trip time of channel", 0, NULL));
turn_rtt_combined[0] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_combined_le_25ms", "Represents combined round trip time of channel", nrtt_labels, rtt_labels));
turn_rtt_combined[1] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_combined_le_50ms", "Represents combined round trip time of channel", nrtt_labels, rtt_labels));
turn_rtt_combined[2] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_combined_le_100ms", "Represents combined round trip time of channel", nrtt_labels, rtt_labels));
turn_rtt_combined[3] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_combined_le_200ms", "Represents combined round trip time of channel", nrtt_labels, rtt_labels));
turn_rtt_combined[4] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_combined_le_400ms", "Represents combined round trip time of channel", nrtt_labels, rtt_labels));
turn_rtt_combined[5] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_combined_le_800ms", "Represents combined round trip time of channel", nrtt_labels, rtt_labels));
turn_rtt_combined[6] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_combined_le_1500ms", "Represents combined round trip time of channel", nrtt_labels, rtt_labels));
turn_rtt_combined[7] = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_rtt_combined_more", "Represents combined round trip time of channel", nrtt_labels, rtt_labels));
turn_with_no_ping_rcvp = prom_collector_registry_must_register_metric(prom_counter_new(
"turn_with_no_ping_rcvp", "Count of packets received for TURN where no ICE ping has been observed", 0, NULL));
@ -271,34 +291,38 @@ void start_prometheus_server(void) {
// Signal change to add metrics
void prom_set_finished_traffic(const char *realm, const char *user, unsigned long rsvp, unsigned long rsvb,
unsigned long sentp, unsigned long sentb, unsigned long without_pingp, bool peer) {
unsigned long sentp, unsigned long sentb, unsigned long without_pingp, bool peer,
const char *protocolgroup) {
if (turn_params.prometheus == 1) {
const char *label[] = {realm, NULL};
// Signal change to add protocol-group label to metrics
const char *user_label[] = {realm, protocolgroup, protocolgroup};
if (turn_params.prometheus_username_labels) {
label[1] = user;
user_label[1] = user;
}
const char *traffic_label[] = {protocolgroup};
// end signal change
if (peer) {
prom_counter_add(turn_traffic_peer_rcvp, rsvp, label);
prom_counter_add(turn_traffic_peer_rcvb, rsvb, label);
prom_counter_add(turn_traffic_peer_sentp, sentp, label);
prom_counter_add(turn_traffic_peer_sentb, sentb, label);
prom_counter_add(turn_traffic_peer_rcvp, rsvp, user_label);
prom_counter_add(turn_traffic_peer_rcvb, rsvb, user_label);
prom_counter_add(turn_traffic_peer_sentp, sentp, user_label);
prom_counter_add(turn_traffic_peer_sentb, sentb, user_label);
prom_counter_add(turn_total_traffic_peer_rcvp, rsvp, NULL);
prom_counter_add(turn_total_traffic_peer_rcvb, rsvb, NULL);
prom_counter_add(turn_total_traffic_peer_sentp, sentp, NULL);
prom_counter_add(turn_total_traffic_peer_sentb, sentb, NULL);
prom_counter_add(turn_total_traffic_peer_rcvp, rsvp, traffic_label);
prom_counter_add(turn_total_traffic_peer_rcvb, rsvb, traffic_label);
prom_counter_add(turn_total_traffic_peer_sentp, sentp, traffic_label);
prom_counter_add(turn_total_traffic_peer_sentb, sentb, traffic_label);
} else {
prom_counter_add(turn_traffic_rcvp, rsvp, label);
prom_counter_add(turn_traffic_rcvb, rsvb, label);
prom_counter_add(turn_traffic_sentp, sentp, label);
prom_counter_add(turn_traffic_sentb, sentb, label);
prom_counter_add(turn_traffic_rcvp, rsvp, user_label);
prom_counter_add(turn_traffic_rcvb, rsvb, user_label);
prom_counter_add(turn_traffic_sentp, sentp, user_label);
prom_counter_add(turn_traffic_sentb, sentb, user_label);
prom_counter_add(turn_total_traffic_rcvp, rsvp, NULL);
prom_counter_add(turn_total_traffic_rcvb, rsvb, NULL);
prom_counter_add(turn_total_traffic_sentp, sentp, NULL);
prom_counter_add(turn_total_traffic_sentb, sentb, NULL);
prom_counter_add(turn_total_traffic_rcvp, rsvp, traffic_label);
prom_counter_add(turn_total_traffic_rcvb, rsvb, traffic_label);
prom_counter_add(turn_total_traffic_sentp, sentp, traffic_label);
prom_counter_add(turn_total_traffic_sentb, sentb, traffic_label);
}
// Signal change to add metrics
if (without_pingp) {
@ -307,18 +331,19 @@ void prom_set_finished_traffic(const char *realm, const char *user, unsigned lon
}
}
void prom_inc_allocation(SOCKET_TYPE type, int addr_family) {
void prom_inc_allocation(SOCKET_TYPE type, int addr_family, const char *protocolgroup) {
if (turn_params.prometheus == 1) {
const char *labels[] = {socket_type_name(type), addr_family_name(addr_family)};
const char *labels[] = {socket_type_name(type), addr_family_name(addr_family), protocolgroup};
prom_gauge_inc(turn_total_allocations, labels);
}
}
void prom_dec_allocation(SOCKET_TYPE type, int addr_family, unsigned long duration, unsigned long sent_rate_kbps) {
void prom_dec_allocation(SOCKET_TYPE type, int addr_family, unsigned long duration, unsigned long sent_rate_kbps,
const char *protocolgroup) {
if (turn_params.prometheus == 1) {
const char *labels[] = {socket_type_name(type), addr_family_name(addr_family)};
const char *labels[] = {socket_type_name(type), addr_family_name(addr_family), protocolgroup};
prom_gauge_dec(turn_total_allocations, labels);
const char *total_sessions_labels[] = {duration_name(duration), rate_name(sent_rate_kbps)};
const char *total_sessions_labels[] = {duration_name(duration), rate_name(sent_rate_kbps), protocolgroup};
prom_counter_add(turn_total_sessions, 1, total_sessions_labels);
}
}
@ -357,47 +382,48 @@ int is_ipv6_enabled(void) {
return ret;
}
// Signal change to add metrics
void prom_observe_rtt(prom_counter_t *counter[8], int microseconds) {
// Signal change to add rtt metrics
void prom_observe_rtt(prom_counter_t *counter[8], int microseconds, const char *protocolgroup) {
const char *label[] = {protocolgroup};
if (microseconds <= 25000) {
prom_counter_add(counter[0], 1, NULL);
prom_counter_add(counter[0], 1, label);
}
if (microseconds <= 50000) {
prom_counter_add(counter[1], 1, NULL);
prom_counter_add(counter[1], 1, label);
}
if (microseconds <= 100000) {
prom_counter_add(counter[2], 1, NULL);
prom_counter_add(counter[2], 1, label);
}
if (microseconds <= 200000) {
prom_counter_add(counter[3], 1, NULL);
prom_counter_add(counter[3], 1, label);
}
if (microseconds <= 400000) {
prom_counter_add(counter[4], 1, NULL);
prom_counter_add(counter[4], 1, label);
}
if (microseconds <= 800000) {
prom_counter_add(counter[5], 1, NULL);
prom_counter_add(counter[5], 1, label);
}
if (microseconds <= 1500000) {
prom_counter_add(counter[6], 1, NULL);
prom_counter_add(counter[6], 1, label);
}
prom_counter_add(counter[7], 1, NULL);
prom_counter_add(counter[7], 1, label);
}
void prom_observe_rtt_client(int microseconds) {
void prom_observe_rtt_client(int microseconds, const char *protocolgroup) {
if (turn_params.prometheus == 1) {
prom_observe_rtt(turn_rtt_client, microseconds);
prom_observe_rtt(turn_rtt_client, microseconds, protocolgroup);
}
}
void prom_observe_rtt_peer(int microseconds) {
void prom_observe_rtt_peer(int microseconds, const char *protocolgroup) {
if (turn_params.prometheus == 1) {
prom_observe_rtt(turn_rtt_peer, microseconds);
prom_observe_rtt(turn_rtt_peer, microseconds, protocolgroup);
}
}
void prom_observe_rtt_combined(int microseconds) {
void prom_observe_rtt_combined(int microseconds, const char *protocolgroup) {
if (turn_params.prometheus == 1) {
prom_observe_rtt(turn_rtt_combined, microseconds);
prom_observe_rtt(turn_rtt_combined, microseconds, protocolgroup);
}
}
@ -409,7 +435,8 @@ void start_prometheus_server(void) {
}
void prom_set_finished_traffic(const char *realm, const char *user, unsigned long rsvp, unsigned long rsvb,
unsigned long sentp, unsigned long sentb, unsigned long without_pingp, bool peer) {
unsigned long sentp, unsigned long sentb, unsigned long without_pingp, bool peer,
const char *protocolgroup) {
UNUSED_ARG(realm);
UNUSED_ARG(user);
UNUSED_ARG(rsvp);
@ -418,6 +445,7 @@ void prom_set_finished_traffic(const char *realm, const char *user, unsigned lon
UNUSED_ARG(sentb);
UNUSED_ARG(without_pingp);
UNUSED_ARG(peer);
UNUSED_ARG(protocolgroup);
}
void prom_inc_allocation(SOCKET_TYPE type) { UNUSED_ARG(type); }

View File

@ -68,10 +68,13 @@ void start_prometheus_server(void);
// Signal change to add metrics
void prom_set_finished_traffic(const char *realm, const char *user, unsigned long rsvp, unsigned long rsvb,
unsigned long sentp, unsigned long sentb, unsigned long without_pingp, bool peer);
unsigned long sentp, unsigned long sentb, unsigned long without_pingp, bool peer,
const char *protocolgroup);
void prom_inc_allocation(SOCKET_TYPE type, int addr_family);
void prom_dec_allocation(SOCKET_TYPE type, int addr_family, unsigned long duration, unsigned long sent_rate_kbps);
void prom_inc_allocation(SOCKET_TYPE type, int addr_family, const char *protocolgroup);
// Signal change to add protocol-group label
void prom_dec_allocation(SOCKET_TYPE type, int addr_family, unsigned long duration, unsigned long sent_rate_kbps,
const char *protocolgroup);
int is_ipv6_enabled(void);
@ -80,10 +83,10 @@ void prom_inc_stun_binding_response(void);
void prom_inc_stun_binding_error(void);
// Signal change to add metrics
void prom_observe_rtt(prom_counter_t *counter[8], int microseconds);
void prom_observe_rtt_client(int microseconds);
void prom_observe_rtt_peer(int microseconds);
void prom_observe_rtt_combined(int microseconds);
void prom_observe_rtt(prom_counter_t *counter[8], int microseconds, const char *protocolgroup);
void prom_observe_rtt_client(int microseconds, const char *protocolgroup);
void prom_observe_rtt_peer(int microseconds, const char *protocolgroup);
void prom_observe_rtt_combined(int microseconds, const char *protocolgroup);
#else
@ -91,7 +94,8 @@ void start_prometheus_server(void);
// Signal change to add metrics
void prom_set_finished_traffic(const char *realm, const char *user, unsigned long rsvp, unsigned long rsvb,
unsigned long sentp, unsigned long sentb, unsigned long without_pingp, bool peer);
unsigned long sentp, unsigned long sentb, unsigned long without_pingp, bool peer,
const char *protocolgroup);
void prom_inc_allocation(SOCKET_TYPE type);
void prom_dec_allocation(SOCKET_TYPE type);

View File

@ -48,6 +48,9 @@
#define STUN_MAX_SERVER_NAME_SIZE (1025)
#define STUN_MAX_PWD_SIZE (256)
#define AUTH_SECRET_SIZE STUN_MAX_PWD_SIZE
// Signal change to add group metric label
#define MAX_PROTOCOL_GROUP_SIZE (16)
#define DEFAULT_PROTOCOL_GROUP "00"
#define STUN_MAGIC_COOKIE (0x2112A442)

View File

@ -197,6 +197,8 @@ static int inc_quota(ts_ur_super_session *ss, uint8_t *username) {
} else {
STRCPY(ss->username, username);
// Signal change to add protocol-group label to metrics
set_protocolgroup(ss);
ss->quota_used = 1;
}
@ -376,6 +378,15 @@ static int good_peer_addr(turn_turnserver *server, const char *realm, ioa_addr *
allocation *get_allocation_ss(ts_ur_super_session *ss) { return &(ss->alloc); }
void set_protocolgroup(ts_ur_super_session *ss) {
char *group = strrchr((char *)ss->username, '#');
if (group != NULL) {
strncpy(ss->protocolgroup, group, MAX_PROTOCOL_GROUP_SIZE);
} else {
strncpy(ss->protocolgroup, DEFAULT_PROTOCOL_GROUP, MAX_PROTOCOL_GROUP_SIZE);
}
}
static inline relay_endpoint_session *get_relay_session_ss(ts_ur_super_session *ss, int family) {
return get_relay_session(&(ss->alloc), family);
}
@ -1494,6 +1505,8 @@ static void copy_auth_parameters(ts_ur_super_session *orig_ss, ts_ur_super_sessi
ss->nonce_expiration_time = orig_ss->nonce_expiration_time;
memcpy(&(ss->realm_options), &(orig_ss->realm_options), sizeof(ss->realm_options));
memcpy(ss->username, orig_ss->username, sizeof(ss->username));
// Signal change to add protocol-group label to metrics
memcpy(ss->protocolgroup, orig_ss->protocolgroup, sizeof(ss->protocolgroup));
ss->hmackey_set = orig_ss->hmackey_set;
memcpy(ss->hmackey, orig_ss->hmackey, sizeof(ss->hmackey));
ss->oauth = orig_ss->oauth;
@ -2941,8 +2954,8 @@ static int handle_turn_binding(turn_turnserver *server, ts_ur_super_session *ss,
// Signal change to add metrics
/////////////// inspect relayed packets, they might be ICE binds ///////////////
static int inspect_binds(turn_turnserver *server, ioa_net_data *in_buffer, turn_permission_info *tinfo, int from_peer,
int is_channel) {
static int inspect_binds(ts_ur_super_session *ss, turn_turnserver *server, ioa_net_data *in_buffer,
turn_permission_info *tinfo, int from_peer, int is_channel) {
if (!in_buffer || !tinfo || !(from_peer == 0 || from_peer == 1)) {
return 0;
}
@ -2989,12 +3002,12 @@ static int inspect_binds(turn_turnserver *server, ioa_net_data *in_buffer, turn_
#if !defined(TURN_NO_PROMETHEUS)
if (is_channel) {
if (from_client) {
prom_observe_rtt_client(diffus);
prom_observe_rtt_client(diffus, ss->protocolgroup);
} else {
prom_observe_rtt_peer(diffus);
prom_observe_rtt_peer(diffus, ss->protocolgroup);
}
if (tinfo->pings[from_peer].lastrttus > 0) {
prom_observe_rtt_combined(diffus + tinfo->pings[from_peer].lastrttus);
prom_observe_rtt_combined(diffus + tinfo->pings[from_peer].lastrttus, ss->protocolgroup);
}
}
#endif
@ -3124,7 +3137,7 @@ static int handle_turn_send(turn_turnserver *server, ts_ur_super_session *ss, in
ioa_network_buffer_set_size(nbh, len);
}
// Signal change to add rtt metrics
if (inspect_binds(server, in_buffer, tinfo, 0, 0)) {
if (inspect_binds(ss, server, in_buffer, tinfo, 0, 0)) {
++(ss->t_before_ping_packets);
}
@ -3517,6 +3530,8 @@ static int check_stun_auth(turn_turnserver *server, ts_ur_super_session *ss, stu
if (ss->oauth) {
ss->hmackey_set = 0;
STRCPY(ss->username, usname);
// Signal change to add protocol-group label to metrics
set_protocolgroup(ss);
} else {
if (method == STUN_METHOD_ALLOCATE) {
*err_code = 437;
@ -3529,6 +3544,8 @@ static int check_stun_auth(turn_turnserver *server, ts_ur_super_session *ss, stu
}
} else {
STRCPY(ss->username, usname);
// Signal change to add protocol-group label to metrics
set_protocolgroup(ss);
}
{
@ -4192,7 +4209,7 @@ static int write_to_peerchannel(ts_ur_super_session *ss, uint16_t chnum, ioa_net
// Signal change to add rtt metrics
turn_turnserver *server = (turn_turnserver *)ss->server;
turn_permission_info *tinfo = (turn_permission_info *)(chn->owner);
if (inspect_binds(server, in_buffer, tinfo, 0, 1)) {
if (inspect_binds(ss, server, in_buffer, tinfo, 0, 1)) {
++(ss->t_before_ping_packets);
}
@ -4916,7 +4933,7 @@ static void peer_input_handler(ioa_socket_handle s, int event_type, ioa_net_data
if (tinfo) {
chnum = get_turn_channel_number(tinfo, &(in_buffer->src_addr));
// Signal change to add rtt metrics
if (inspect_binds(server, in_buffer, tinfo, 1, chnum != 0)) {
if (inspect_binds(ss, server, in_buffer, tinfo, 1, chnum != 0)) {
++(ss->t_before_ping_packets);
}
} else if (!(server->server_relay)) {

View File

@ -121,6 +121,8 @@ struct _ts_ur_super_session {
band_limit_t bps;
// Signal change to add metrics
uint64_t t_before_ping_packets;
// Signal change to add protocol-group label to metrics
char protocolgroup[MAX_PROTOCOL_GROUP_SIZE + 1];
};
////// Session info for statistics //////
@ -186,6 +188,9 @@ int turn_session_info_copy_from(struct turn_session_info *tsi, ts_ur_super_sessi
allocation *get_allocation_ss(ts_ur_super_session *ss);
// Signal change to add protocol-group label to metrics
void set_protocolgroup(ts_ur_super_session *ss);
///////////////////////////////////////////////////////
#ifdef __cplusplus