duration and rate counter metric

This commit is contained in:
Iñaqui 2023-05-05 11:40:48 -04:00 committed by Richard Russo
parent e825110d38
commit 7b69eb0e2f
5 changed files with 72 additions and 3 deletions

View File

@ -537,6 +537,50 @@ const char *socket_type_name(SOCKET_TYPE st) {
return "UNKNOWN";
}
const char *duration_name(unsigned long duration) {
if (duration < 1) {
return "1sec";
} else if (duration < 10) {
return "10sec";
} else if (duration < 30) {
return "30sec";
} else if (duration < 60) {
return "1min";
} else if (duration < 600) {
return "10mins";
} else if (duration < 1800) {
return "30mins";
} else if (duration < 3600) {
return "1hr";
} else if (duration < 14400) {
return "4hrs";
} else if (duration < 43200) {
return "12hrs";
} else if (duration < 86400) {
return "24hrs";
} else {
return "days";
}
}
const char *rate_name(unsigned long rate_kbps) {
if (rate_kbps < 1) {
return "1kbps";
} else if (rate_kbps < 10) {
return "10kbps";
} else if (rate_kbps < 50) {
return "50kbps";
} else if (rate_kbps < 100) {
return "100kbps";
} else if (rate_kbps < 500) {
return "500kbps";
} else if (rate_kbps < 1000) {
return "1000kbps";
} else {
return "10000kbps";
}
}
/////////////////// MTU /////////////////////////////////////////
int set_socket_df(evutil_socket_t fd, int family, int value) {

View File

@ -3740,7 +3740,14 @@ void turn_report_allocation_delete(void *a, SOCKET_TYPE socket_type) {
(unsigned long)(ss->t_peer_sent_packets), (unsigned long)(ss->t_peer_sent_bytes),
true);
}
prom_dec_allocation(socket_type);
turn_time_t ct = get_turn_server_time(server) - ss->start_time;
const uint32_t byte_to_kilobit = 125;
uint64_t received_rate_kbps = ss->received_rate / byte_to_kilobit;
uint64_t sent_rate_kbps = ss->sent_rate / byte_to_kilobit;
prom_dec_allocation(socket_type,
(unsigned long)ct,
(unsigned long)received_rate_kbps,
(unsigned long)sent_rate_kbps);
}
}
}

View File

@ -33,6 +33,8 @@ prom_counter_t *turn_total_traffic_peer_rcvb;
prom_counter_t *turn_total_traffic_peer_sentp;
prom_counter_t *turn_total_traffic_peer_sentb;
prom_counter_t *turn_total_sessions;
prom_gauge_t *turn_total_allocations;
#if MHD_VERSION >= 0x00097002
@ -134,6 +136,11 @@ void start_prometheus_server(void) {
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));
// Create total completed session counter metric
const char *total_sessions_labels[] = {"duration", "received_rate", "sent_rate"};
turn_total_sessions = prom_collector_registry_must_register_metric(
prom_counter_new("turn_total_sessions", "Represents total completed sessions", 3, total_sessions_labels));
// Create total allocations number gauge metric
const char *typeLabel[] = {"type"};
turn_total_allocations = prom_collector_registry_must_register_metric(
@ -238,10 +245,16 @@ void prom_inc_allocation(SOCKET_TYPE type) {
}
}
void prom_dec_allocation(SOCKET_TYPE type) {
void prom_dec_allocation(SOCKET_TYPE type,
unsigned long duration,
unsigned long received_rate_kbps,
unsigned long sent_rate_kbps) {
if (turn_params.prometheus == 1) {
const char *label[] = {socket_type_name(type)};
prom_gauge_dec(turn_total_allocations, label);
const char *total_sessions_labels[] =
{ duration_name(duration), rate_name(received_rate_kbps), rate_name(sent_rate_kbps) };
prom_counter_add(turn_total_sessions, 1, total_sessions_labels);
}
}

View File

@ -62,7 +62,10 @@ void prom_set_finished_traffic(const char *realm, const char *user, unsigned lon
unsigned long sentp, unsigned long sentb, bool peer);
void prom_inc_allocation(SOCKET_TYPE type);
void prom_dec_allocation(SOCKET_TYPE type);
void prom_dec_allocation(SOCKET_TYPE type,
unsigned long duration,
unsigned long received_rate_kbps,
unsigned long sent_rate_kbps);
int is_ipv6_enabled(void);

View File

@ -275,6 +275,8 @@ int is_stream_socket(int st);
int is_tcp_socket(int st);
int is_sctp_socket(int st);
const char *socket_type_name(SOCKET_TYPE st);
const char *duration_name(unsigned long duration);
const char *rate_name(unsigned long rate_kbps);
const char *get_ioa_socket_cipher(ioa_socket_handle s);
const char *get_ioa_socket_ssl_method(ioa_socket_handle s);
SOCKET_TYPE get_ioa_socket_type(ioa_socket_handle s);