feature(1026): add sessioncount to prometheus metrics (#1075)
Co-authored-by: Paul Kramer <paul.kramer@logmein.com>
This commit is contained in:
parent
730996b09a
commit
5a28394200
@ -3707,7 +3707,7 @@ void turn_report_allocation_set(void *a, turn_time_t lifetime, int refresh)
|
||||
#if !defined(TURN_NO_PROMETHEUS)
|
||||
{
|
||||
if (!refresh)
|
||||
prom_inc_allocation();
|
||||
prom_inc_allocation(get_ioa_socket_type(ss->client_socket));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -3715,7 +3715,7 @@ void turn_report_allocation_set(void *a, turn_time_t lifetime, int refresh)
|
||||
}
|
||||
}
|
||||
|
||||
void turn_report_allocation_delete(void *a)
|
||||
void turn_report_allocation_delete(void *a, SOCKET_TYPE socket_type)
|
||||
{
|
||||
if(a) {
|
||||
ts_ur_super_session *ss = (ts_ur_super_session*)(((allocation*)a)->owner);
|
||||
@ -3765,7 +3765,7 @@ void turn_report_allocation_delete(void *a)
|
||||
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), false);
|
||||
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), true);
|
||||
}
|
||||
prom_dec_allocation();
|
||||
prom_dec_allocation(socket_type);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ 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 allocations number gauge metric
|
||||
turn_total_allocations = prom_collector_registry_must_register_metric(prom_gauge_new("turn_total_allocations", "Represents current allocations number", 0, NULL));
|
||||
turn_total_allocations = prom_collector_registry_must_register_metric(prom_gauge_new("turn_total_allocations", "Represents current allocations number", 1, (const char*[]) {"type"}));
|
||||
|
||||
promhttp_set_active_collector_registry(NULL);
|
||||
|
||||
@ -129,15 +129,17 @@ void prom_set_finished_traffic(const char* realm, const char* user, unsigned lon
|
||||
}
|
||||
}
|
||||
|
||||
void prom_inc_allocation(void) {
|
||||
void prom_inc_allocation(SOCKET_TYPE type) {
|
||||
if (turn_params.prometheus == 1){
|
||||
prom_gauge_inc(turn_total_allocations, NULL);
|
||||
prom_gauge_inc(turn_total_allocations, (const char*[]) {"all"});
|
||||
prom_gauge_inc(turn_total_allocations, (const char*[]) {socket_type_name(type)});
|
||||
}
|
||||
}
|
||||
|
||||
void prom_dec_allocation(void) {
|
||||
void prom_dec_allocation(SOCKET_TYPE type) {
|
||||
if (turn_params.prometheus == 1){
|
||||
prom_gauge_dec(turn_total_allocations, NULL);
|
||||
prom_gauge_dec(turn_total_allocations, (const char*[]) {"all"});
|
||||
prom_gauge_dec(turn_total_allocations, (const char*[]) {socket_type_name(type)});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -59,8 +59,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, bool peer);
|
||||
|
||||
void prom_inc_allocation(void);
|
||||
void prom_dec_allocation(void);
|
||||
void prom_inc_allocation(SOCKET_TYPE type);
|
||||
void prom_dec_allocation(SOCKET_TYPE type);
|
||||
#else
|
||||
|
||||
void start_prometheus_server(void);
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
*/
|
||||
|
||||
#include "ns_turn_allocation.h"
|
||||
#include "ns_turn_ioalib.h"
|
||||
|
||||
/////////////// Permission forward declarations /////////////////
|
||||
|
||||
@ -47,12 +48,12 @@ void init_allocation(void *owner, allocation* a, ur_map *tcp_connections) {
|
||||
}
|
||||
}
|
||||
|
||||
void clear_allocation(allocation *a)
|
||||
void clear_allocation(allocation *a, SOCKET_TYPE socket_type)
|
||||
{
|
||||
if (a) {
|
||||
|
||||
if(a->is_valid)
|
||||
turn_report_allocation_delete(a);
|
||||
turn_report_allocation_delete(a, socket_type);
|
||||
|
||||
if(a->tcs.elems) {
|
||||
size_t i;
|
||||
|
||||
@ -195,7 +195,7 @@ void turn_channel_delete(ch_info* chn);
|
||||
/////////// ALLOCATION ////////////
|
||||
|
||||
void init_allocation(void *owner, allocation* a, ur_map *tcp_connections);
|
||||
void clear_allocation(allocation *a);
|
||||
void clear_allocation(allocation *a, SOCKET_TYPE socket_type);
|
||||
|
||||
void turn_permission_clean(turn_permission_info* tinfo);
|
||||
|
||||
|
||||
@ -206,7 +206,7 @@ void ioa_network_buffer_delete(ioa_engine_handle e, ioa_network_buffer_handle nb
|
||||
* Status reporting functions
|
||||
*/
|
||||
void turn_report_allocation_set(void *a, turn_time_t lifetime, int refresh);
|
||||
void turn_report_allocation_delete(void *a);
|
||||
void turn_report_allocation_delete(void *a, SOCKET_TYPE socket_type);
|
||||
void turn_report_session_usage(void *session, int force_invalid);
|
||||
|
||||
/*
|
||||
|
||||
@ -201,7 +201,7 @@ int ur_map_foreach(ur_map* map, foreachcb_type func) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ur_map_foreach_arg(ur_map* map, foreachcb_arg_type func, void* arg) {
|
||||
int ur_map_foreach_arg(const ur_map* map, foreachcb_arg_type func, void* arg) {
|
||||
if(map && func && ur_map_valid(map)) {
|
||||
khiter_t k;
|
||||
for (k = kh_begin((*map)->h); k != kh_end(map->h); ++k) {
|
||||
|
||||
@ -94,7 +94,7 @@ size_t ur_map_size(const ur_map* map);
|
||||
|
||||
int ur_map_foreach(ur_map* map, foreachcb_type func);
|
||||
|
||||
int ur_map_foreach_arg(ur_map* map, foreachcb_arg_type func, void* arg);
|
||||
int ur_map_foreach_arg(const ur_map* map, foreachcb_arg_type func, void* arg);
|
||||
|
||||
int ur_map_lock(const ur_map* map);
|
||||
int ur_map_unlock(const ur_map* map);
|
||||
|
||||
@ -802,12 +802,12 @@ static ts_ur_super_session* create_new_ss(turn_turnserver* server) {
|
||||
return ss;
|
||||
}
|
||||
|
||||
static void delete_ur_map_ss(void *p) {
|
||||
static void delete_ur_map_ss(void *p, SOCKET_TYPE socket_type) {
|
||||
if (p) {
|
||||
ts_ur_super_session* ss = (ts_ur_super_session*) p;
|
||||
delete_session_from_map(ss);
|
||||
IOA_CLOSE_SOCKET(ss->client_socket);
|
||||
clear_allocation(get_allocation_ss(ss));
|
||||
clear_allocation(get_allocation_ss(ss), socket_type);
|
||||
IOA_EVENT_DEL(ss->to_be_allocated_timeout_ev);
|
||||
free(p);
|
||||
}
|
||||
@ -815,7 +815,7 @@ static void delete_ur_map_ss(void *p) {
|
||||
|
||||
/////////// clean all /////////////////////
|
||||
|
||||
static int turn_server_remove_all_from_ur_map_ss(ts_ur_super_session* ss) {
|
||||
static int turn_server_remove_all_from_ur_map_ss(ts_ur_super_session* ss, SOCKET_TYPE socket_type) {
|
||||
if (!ss)
|
||||
return 0;
|
||||
else {
|
||||
@ -829,7 +829,7 @@ static int turn_server_remove_all_from_ur_map_ss(ts_ur_super_session* ss) {
|
||||
if (get_relay_socket_ss(ss,AF_INET6)) {
|
||||
clear_ioa_socket_session_if(get_relay_socket_ss(ss,AF_INET6), ss);
|
||||
}
|
||||
delete_ur_map_ss(ss);
|
||||
delete_ur_map_ss(ss, socket_type);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@ -4169,6 +4169,8 @@ int shutdown_client_connection(turn_turnserver *server, ts_ur_super_session *ss,
|
||||
if (!ss)
|
||||
return -1;
|
||||
|
||||
SOCKET_TYPE socket_type = get_ioa_socket_type(ss->client_socket);
|
||||
|
||||
turn_report_session_usage(ss, 1);
|
||||
dec_quota(ss);
|
||||
dec_bps(ss);
|
||||
@ -4227,7 +4229,7 @@ int shutdown_client_connection(turn_turnserver *server, ts_ur_super_session *ss,
|
||||
}
|
||||
}
|
||||
|
||||
turn_server_remove_all_from_ur_map_ss(ss);
|
||||
turn_server_remove_all_from_ur_map_ss(ss, socket_type);
|
||||
|
||||
FUNCEND;
|
||||
|
||||
@ -4334,7 +4336,7 @@ static void client_ss_allocation_timeout_handler(ioa_engine_handle e, void *arg)
|
||||
turn_turnserver* server = (turn_turnserver*) (ss->server);
|
||||
|
||||
if (!server) {
|
||||
clear_allocation(a);
|
||||
clear_allocation(a, get_ioa_socket_type(ss->client_socket));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user