Added no-promethsu CLI option
This commit is contained in:
parent
fb3bd0d353
commit
2789a27fb9
@ -155,6 +155,7 @@ TURN_CREDENTIALS_NONE, /* ct */
|
||||
0, /* bps_capacity_allocated */
|
||||
0, /* total_quota */
|
||||
0, /* user_quota */
|
||||
1, /* prometheus enabled by default */
|
||||
///////////// Users DB //////////////
|
||||
{ (TURN_USERDB_TYPE)0, {"\0"}, {0,NULL, {NULL,0}} },
|
||||
///////////// CPUs //////////////////
|
||||
@ -528,6 +529,10 @@ static char Usage[] = "Usage: turnserver [options]\n"
|
||||
" and delivering traffic and allocation event notifications.\n"
|
||||
" The connection string has the same parameters as redis-userdb connection string.\n"
|
||||
#endif
|
||||
#if !defined(TURN_NO_PROMETHEUS)
|
||||
" --no-prometheus Disable prometheus metrics. By default it is enabled and listening on port 9121 unther the path /metrics\n"
|
||||
" also the path / on this port can be used as a health check\n"
|
||||
#endif
|
||||
" --use-auth-secret TURN REST API flag.\n"
|
||||
" Flag that sets a special authorization option that is based upon authentication secret\n"
|
||||
" (TURN Server REST API, see TURNServerRESTAPI.pdf). This option is used with timestamp.\n"
|
||||
@ -734,6 +739,7 @@ enum EXTRA_OPTS {
|
||||
MAX_ALLOCATE_LIFETIME_OPT,
|
||||
CHANNEL_LIFETIME_OPT,
|
||||
PERMISSION_LIFETIME_OPT,
|
||||
NO_PROMETHEUS_OPT,
|
||||
AUTH_SECRET_OPT,
|
||||
DEL_ALL_AUTH_SECRETS_OPT,
|
||||
STATIC_AUTH_SECRET_VAL_OPT,
|
||||
@ -835,6 +841,9 @@ static const struct myoption long_options[] = {
|
||||
#if !defined(TURN_NO_HIREDIS)
|
||||
{ "redis-userdb", required_argument, NULL, 'N' },
|
||||
{ "redis-statsdb", required_argument, NULL, 'O' },
|
||||
#endif
|
||||
#if !defined(TURN_NO_PROMETHEUS)
|
||||
{ "no-prometheus", optional_argument, NULL, NO_PROMETHEUS_OPT },
|
||||
#endif
|
||||
{ "use-auth-secret", optional_argument, NULL, AUTH_SECRET_OPT },
|
||||
{ "static-auth-secret", required_argument, NULL, STATIC_AUTH_SECRET_VAL_OPT },
|
||||
@ -1427,6 +1436,11 @@ static void set_option(int c, char *value)
|
||||
STRCPY(turn_params.redis_statsdb, value);
|
||||
turn_params.use_redis_statsdb = 1;
|
||||
break;
|
||||
#endif
|
||||
#if !defined(TURN_NO_PROMETHEUS)
|
||||
case NO_PROMETHEUS_OPT:
|
||||
turn_params.prometheus = 0;
|
||||
break;
|
||||
#endif
|
||||
case AUTH_SECRET_OPT:
|
||||
turn_params.use_auth_secret_with_timestamp = 1;
|
||||
|
||||
@ -309,6 +309,10 @@ typedef struct _turn_params_ {
|
||||
band_limit_t bps_capacity_allocated;
|
||||
vint total_quota;
|
||||
vint user_quota;
|
||||
#if !defined(TURN_NO_PROMETHEUS)
|
||||
int prometheus;
|
||||
#endif
|
||||
|
||||
|
||||
/////// Users DB ///////////
|
||||
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
#if !defined(TURN_NO_PROMETHEUS)
|
||||
|
||||
#include "mainrelay.h"
|
||||
#include "prom_server.h"
|
||||
|
||||
int start_prometheus_server(void){
|
||||
if (turn_params.prometheus == 0){
|
||||
return 0;
|
||||
}
|
||||
prom_collector_registry_default_init();
|
||||
// Create status gauge metric
|
||||
turn_status = prom_collector_registry_must_register_metric(prom_gauge_new("turn_status", "Represents status", 5, (const char *[]) {"realm", "user", "allocation", "status", "lifetime" }));
|
||||
@ -42,54 +46,61 @@ int start_prometheus_server(void){
|
||||
}
|
||||
|
||||
void prom_set_status(const char* realm, const char* user, unsigned long long allocation, const char* status, unsigned long lifetime){
|
||||
char allocation_chars[1024];
|
||||
char lifetime_chars[1024];
|
||||
|
||||
snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
||||
snprintf(lifetime_chars, sizeof(lifetime_chars), "%lu", lifetime);
|
||||
if (turn_params.prometheus == 1){
|
||||
char allocation_chars[1024];
|
||||
char lifetime_chars[1024];
|
||||
|
||||
snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
||||
snprintf(lifetime_chars, sizeof(lifetime_chars), "%lu", lifetime);
|
||||
|
||||
prom_gauge_add(turn_status, 1, (const char *[]) { realm , user, allocation_chars, status, lifetime_chars });
|
||||
prom_gauge_add(turn_status, 1, (const char *[]) { realm , user, allocation_chars, status, lifetime_chars });
|
||||
}
|
||||
}
|
||||
|
||||
void prom_del_status(const char* realm, const char* user, unsigned long long allocation, const char* status){
|
||||
char allocation_chars[1024];
|
||||
snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
||||
|
||||
prom_gauge_sub(turn_status, 1, (const char *[]) { realm , user, allocation_chars, (char *)"new", (char *)"600" });
|
||||
prom_gauge_add(turn_status, 1, (const char *[]) { realm , user, allocation_chars, status, NULL });
|
||||
if (turn_params.prometheus == 0){
|
||||
char allocation_chars[1024];
|
||||
snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
||||
|
||||
prom_gauge_sub(turn_status, 1, (const char *[]) { realm , user, allocation_chars, (char *)"new", (char *)"600" });
|
||||
prom_gauge_add(turn_status, 1, (const char *[]) { realm , user, allocation_chars, status, NULL });
|
||||
}
|
||||
}
|
||||
void prom_set_traffic(const char* realm, const char* user, unsigned long long allocation, unsigned long rsvp, unsigned long rsvb, unsigned long sentp, unsigned long sentb, bool peer){
|
||||
char allocation_chars[1024];
|
||||
snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
||||
if (turn_params.prometheus == 1){
|
||||
char allocation_chars[1024];
|
||||
snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
||||
|
||||
if (peer){
|
||||
prom_gauge_set(turn_traffic_peer_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_peer_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_peer_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_peer_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
||||
} else {
|
||||
prom_gauge_set(turn_traffic_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
||||
if (peer){
|
||||
prom_gauge_set(turn_traffic_peer_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_peer_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_peer_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_peer_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
||||
} else {
|
||||
prom_gauge_set(turn_traffic_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_traffic_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void prom_set_total_traffic(const char* realm, const char* user, unsigned long long allocation, unsigned long rsvp, unsigned long rsvb, unsigned long sentp, unsigned long sentb, bool peer){
|
||||
char allocation_chars[1024];
|
||||
snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
||||
if (turn_params.prometheus == 1){
|
||||
char allocation_chars[1024];
|
||||
snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
||||
|
||||
if (peer){
|
||||
prom_gauge_set(turn_total_traffic_peer_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_peer_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_peer_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_peer_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
||||
} else {
|
||||
prom_gauge_set(turn_total_traffic_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
||||
if (peer){
|
||||
prom_gauge_set(turn_total_traffic_peer_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_peer_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_peer_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_peer_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
||||
} else {
|
||||
prom_gauge_set(turn_total_traffic_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
||||
prom_gauge_set(turn_total_traffic_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user