mirror of
https://github.com/coturn/coturn.git
synced 2025-05-15 01:52:22 +08:00
Add parameter for specifying prometheus path (#1602)
Add a `--prometheus-path` parameter which allows users to specify at what path the metrics should be exposed. This simplifies serving metrics on a specific path behind some restrictive reverse proxies that expect the upstream server to serve URLs with paths matching the requested path. Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
This commit is contained in:
parent
3370eaf12d
commit
790cc6f79e
@ -64,3 +64,10 @@ turnserver_pid="$!"
|
|||||||
sleep 2
|
sleep 2
|
||||||
assert_prom_response "http://127.0.0.1:8080/metrics"
|
assert_prom_response "http://127.0.0.1:8080/metrics"
|
||||||
kill "$turnserver_pid"
|
kill "$turnserver_pid"
|
||||||
|
|
||||||
|
echo "Running turnserver with prometheus, using custom path"
|
||||||
|
$BINDIR/turnserver --prometheus --prometheus-path="/coturn/metrics" > /dev/null &
|
||||||
|
turnserver_pid="$!"
|
||||||
|
sleep 2
|
||||||
|
assert_prom_response "http://localhost:9641/coturn/metrics"
|
||||||
|
kill "$turnserver_pid"
|
||||||
|
@ -209,6 +209,7 @@ turn_params_t turn_params = {
|
|||||||
0, /* prometheus disabled by default */
|
0, /* prometheus disabled by default */
|
||||||
DEFAULT_PROM_SERVER_PORT, /* prometheus port */
|
DEFAULT_PROM_SERVER_PORT, /* prometheus port */
|
||||||
"", /* prometheus address */
|
"", /* prometheus address */
|
||||||
|
"/metrics", /* prometheus path */
|
||||||
0, /* prometheus username labelling disabled by default when prometheus is enabled */
|
0, /* prometheus username labelling disabled by default when prometheus is enabled */
|
||||||
|
|
||||||
///////////// Users DB //////////////
|
///////////// Users DB //////////////
|
||||||
@ -1137,6 +1138,7 @@ static char Usage[] =
|
|||||||
" also the path / on this port can be used as a health check\n"
|
" also the path / on this port can be used as a health check\n"
|
||||||
" --prometheus-port <port> Prometheus metrics port (Default: 9641).\n"
|
" --prometheus-port <port> Prometheus metrics port (Default: 9641).\n"
|
||||||
" --prometheus-address <address> Prometheus listening address (Default: any).\n"
|
" --prometheus-address <address> Prometheus listening address (Default: any).\n"
|
||||||
|
" --prometheus-path <path> Prometheus serve path (Default: /metrics).\n"
|
||||||
" --prometheus-username-labels When metrics are enabled, add labels with client usernames.\n"
|
" --prometheus-username-labels When metrics are enabled, add labels with client usernames.\n"
|
||||||
#endif
|
#endif
|
||||||
" --use-auth-secret TURN REST API flag.\n"
|
" --use-auth-secret TURN REST API flag.\n"
|
||||||
@ -1436,6 +1438,7 @@ enum EXTRA_OPTS {
|
|||||||
PROMETHEUS_OPT,
|
PROMETHEUS_OPT,
|
||||||
PROMETHEUS_PORT_OPT,
|
PROMETHEUS_PORT_OPT,
|
||||||
PROMETHEUS_ADDRESS_OPT,
|
PROMETHEUS_ADDRESS_OPT,
|
||||||
|
PROMETHEUS_PATH_OPT,
|
||||||
PROMETHEUS_ENABLE_USERNAMES_OPT,
|
PROMETHEUS_ENABLE_USERNAMES_OPT,
|
||||||
AUTH_SECRET_OPT,
|
AUTH_SECRET_OPT,
|
||||||
NO_AUTH_PINGS_OPT,
|
NO_AUTH_PINGS_OPT,
|
||||||
@ -1555,6 +1558,7 @@ static const struct myoption long_options[] = {
|
|||||||
{"prometheus", optional_argument, NULL, PROMETHEUS_OPT},
|
{"prometheus", optional_argument, NULL, PROMETHEUS_OPT},
|
||||||
{"prometheus-port", optional_argument, NULL, PROMETHEUS_PORT_OPT},
|
{"prometheus-port", optional_argument, NULL, PROMETHEUS_PORT_OPT},
|
||||||
{"prometheus-address", optional_argument, NULL, PROMETHEUS_ADDRESS_OPT},
|
{"prometheus-address", optional_argument, NULL, PROMETHEUS_ADDRESS_OPT},
|
||||||
|
{"prometheus-path", optional_argument, NULL, PROMETHEUS_PATH_OPT},
|
||||||
{"prometheus-username-labels", optional_argument, NULL, PROMETHEUS_ENABLE_USERNAMES_OPT},
|
{"prometheus-username-labels", optional_argument, NULL, PROMETHEUS_ENABLE_USERNAMES_OPT},
|
||||||
#endif
|
#endif
|
||||||
{"use-auth-secret", optional_argument, NULL, AUTH_SECRET_OPT},
|
{"use-auth-secret", optional_argument, NULL, AUTH_SECRET_OPT},
|
||||||
@ -2207,6 +2211,9 @@ static void set_option(int c, char *value) {
|
|||||||
case PROMETHEUS_ADDRESS_OPT:
|
case PROMETHEUS_ADDRESS_OPT:
|
||||||
STRCPY(turn_params.prometheus_address, value);
|
STRCPY(turn_params.prometheus_address, value);
|
||||||
break;
|
break;
|
||||||
|
case PROMETHEUS_PATH_OPT:
|
||||||
|
STRCPY(turn_params.prometheus_path, value);
|
||||||
|
break;
|
||||||
case PROMETHEUS_ENABLE_USERNAMES_OPT:
|
case PROMETHEUS_ENABLE_USERNAMES_OPT:
|
||||||
turn_params.prometheus_username_labels = 1;
|
turn_params.prometheus_username_labels = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -311,6 +311,7 @@ typedef struct _turn_params_ {
|
|||||||
int prometheus;
|
int prometheus;
|
||||||
int prometheus_port;
|
int prometheus_port;
|
||||||
char prometheus_address[INET6_ADDRSTRLEN];
|
char prometheus_address[INET6_ADDRSTRLEN];
|
||||||
|
char prometheus_path[1025];
|
||||||
int prometheus_username_labels;
|
int prometheus_username_labels;
|
||||||
|
|
||||||
/////// Users DB ///////////
|
/////// Users DB ///////////
|
||||||
|
@ -52,7 +52,7 @@ MHD_RESULT promhttp_handler(void *cls, struct MHD_Connection *connection, const
|
|||||||
if (strcmp(method, "GET") != 0) {
|
if (strcmp(method, "GET") != 0) {
|
||||||
status = MHD_HTTP_METHOD_NOT_ALLOWED;
|
status = MHD_HTTP_METHOD_NOT_ALLOWED;
|
||||||
body = "method not allowed";
|
body = "method not allowed";
|
||||||
} else if (strcmp(url, "/metrics") == 0) {
|
} else if (strcmp(url, turn_params.prometheus_path) == 0) {
|
||||||
body = prom_collector_registry_bridge(PROM_COLLECTOR_REGISTRY_DEFAULT);
|
body = prom_collector_registry_bridge(PROM_COLLECTOR_REGISTRY_DEFAULT);
|
||||||
mode = MHD_RESPMEM_MUST_FREE;
|
mode = MHD_RESPMEM_MUST_FREE;
|
||||||
status = MHD_HTTP_OK;
|
status = MHD_HTTP_OK;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user