Merge pull request #787 from dsmeytis/prom_allocations_metric

Add current allocations number gauge metric
This commit is contained in:
Gustavo Garcia 2022-08-02 09:51:47 +02:00 committed by GitHub
commit 1987cacb52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -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_inc_allocation();
}
#endif
}
}
@ -3777,6 +3783,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();
}
#endif
}

View File

@ -24,6 +24,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_gauge_t *turn_total_allocations;
int start_prometheus_server(void){
if (turn_params.prometheus == 0){
@ -63,6 +65,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 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));
promhttp_set_active_collector_registry(NULL);
@ -105,4 +110,16 @@ void prom_set_finished_traffic(const char* realm, const char* user, unsigned lon
}
}
void prom_inc_allocation(void) {
if (turn_params.prometheus == 1){
prom_gauge_inc(turn_total_allocations, NULL);
}
}
void prom_dec_allocation(void) {
if (turn_params.prometheus == 1){
prom_gauge_dec(turn_total_allocations, NULL);
}
}
#endif /* TURN_NO_PROMETHEUS */

View File

@ -46,6 +46,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_total_allocations_number;
#define TURN_ALLOC_STR_MAX_SIZE (20)
#ifdef __cplusplus
@ -57,6 +59,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_inc_allocation(void);
void prom_dec_allocation(void);
#endif /* TURN_NO_PROMETHEUS */
#ifdef __cplusplus