Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/apps/relay/ns_ioalib_engine_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3721,6 +3721,12 @@ void turn_report_allocation_set(void *a, turn_time_t lifetime, int refresh)
send_message_to_redis(e->rch, "set", key, "%s lifetime=%lu", status, (unsigned long)lifetime);
send_message_to_redis(e->rch, "publish", key, "%s lifetime=%lu", status, (unsigned long)lifetime);
}
#endif
#if !defined(TURN_NO_PROMETHEUS)
{
if(!refresh)
prom_report_allocation_start();
}
#endif
}
}
Expand Down Expand Up @@ -3777,6 +3783,8 @@ 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_report_allocation_finish();
}
#endif
}
Expand Down
18 changes: 17 additions & 1 deletion src/apps/relay/prom_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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_gauge_t *turn_active_allocations;

int start_prometheus_server(void){
if (turn_params.prometheus == PROM_DISABLED){
Expand Down Expand Up @@ -59,6 +60,9 @@ int start_prometheus_server(void){
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_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 active allocations gauge
turn_active_allocations = prom_collector_registry_must_register_metric(prom_gauge_new("turn_active_allocations", "Number of currently active allocations", 0, NULL));

promhttp_set_active_collector_registry(NULL);

struct MHD_Daemon *daemon;
Expand Down Expand Up @@ -89,7 +93,7 @@ int 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){
if (turn_params.prometheus == 1){
if (turn_params.prometheus > PROM_DISABLED){

const char *label[] = {realm, user};

Expand Down Expand Up @@ -117,4 +121,16 @@ void prom_set_finished_traffic(const char* realm, const char* user, unsigned lon
}
}

void prom_report_allocation_start(){
if (turn_params.prometheus > PROM_DISABLED){
prom_gauge_inc(turn_active_allocations, NULL);
}
}

void prom_report_allocation_finish(){
if (turn_params.prometheus > PROM_DISABLED){
prom_gauge_dec(turn_active_allocations, NULL);
}
}

#endif /* TURN_NO_PROMETHEUS */
5 changes: 5 additions & 0 deletions src/apps/relay/prom_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ extern prom_counter_t *turn_total_traffic_peer_rcvb;
extern prom_counter_t *turn_total_traffic_peer_sentp;
extern prom_counter_t *turn_total_traffic_peer_sentb;

extern prom_gauge_t *turn_active_allocations;

#define TURN_ALLOC_STR_MAX_SIZE (20)

#ifdef __cplusplus
Expand All @@ -63,6 +65,9 @@ int 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_report_allocation_start(void);
void prom_report_allocation_finish(void);

#endif /* TURN_NO_PROMETHEUS */

#ifdef __cplusplus
Expand Down