|
@@ -35,6 +35,42 @@ prom_counter_t *turn_total_traffic_peer_sentb;
|
|
|
|
|
|
prom_gauge_t *turn_total_allocations;
|
|
prom_gauge_t *turn_total_allocations;
|
|
|
|
|
|
|
|
+#if MHD_VERSION >= 0x00097002
|
|
|
|
+#define MHD_RESULT enum MHD_Result
|
|
|
|
+#else
|
|
|
|
+#define MHD_RESULT int
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+MHD_RESULT promhttp_handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method,
|
|
|
|
+ const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) {
|
|
|
|
+ MHD_RESULT ret;
|
|
|
|
+
|
|
|
|
+ char *body = "not found";
|
|
|
|
+ enum MHD_ResponseMemoryMode mode = MHD_RESPMEM_PERSISTENT;
|
|
|
|
+ unsigned int status = MHD_HTTP_NOT_FOUND;
|
|
|
|
+
|
|
|
|
+ if (strcmp(method, "GET") != 0) {
|
|
|
|
+ status = MHD_HTTP_METHOD_NOT_ALLOWED;
|
|
|
|
+ body = "method not allowed";
|
|
|
|
+ } else if (strcmp(url, "/metrics") == 0) {
|
|
|
|
+ body = prom_collector_registry_bridge(PROM_COLLECTOR_REGISTRY_DEFAULT);
|
|
|
|
+ mode = MHD_RESPMEM_MUST_FREE;
|
|
|
|
+ status = MHD_HTTP_OK;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ struct MHD_Response *response = MHD_create_response_from_buffer(strlen(body), body, mode);
|
|
|
|
+ if (response == NULL) {
|
|
|
|
+ if (mode == MHD_RESPMEM_MUST_FREE) {
|
|
|
|
+ free(body);
|
|
|
|
+ }
|
|
|
|
+ ret = MHD_NO;
|
|
|
|
+ } else {
|
|
|
|
+ ret = MHD_queue_response(connection, status, response);
|
|
|
|
+ MHD_destroy_response(response);
|
|
|
|
+ }
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
void start_prometheus_server(void) {
|
|
void start_prometheus_server(void) {
|
|
if (turn_params.prometheus == 0) {
|
|
if (turn_params.prometheus == 0) {
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "prometheus collector disabled, not started\n");
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "prometheus collector disabled, not started\n");
|
|
@@ -103,13 +139,8 @@ void start_prometheus_server(void) {
|
|
turn_total_allocations = prom_collector_registry_must_register_metric(
|
|
turn_total_allocations = prom_collector_registry_must_register_metric(
|
|
prom_gauge_new("turn_total_allocations", "Represents current allocations number", 1, typeLabel));
|
|
prom_gauge_new("turn_total_allocations", "Represents current allocations number", 1, typeLabel));
|
|
|
|
|
|
- promhttp_set_active_collector_registry(NULL);
|
|
|
|
-
|
|
|
|
// some flags appeared first in microhttpd v0.9.53
|
|
// some flags appeared first in microhttpd v0.9.53
|
|
unsigned int flags = 0;
|
|
unsigned int flags = 0;
|
|
- if (MHD_is_feature_supported(MHD_FEATURE_IPv6) && is_ipv6_enabled()) {
|
|
|
|
- flags |= MHD_USE_DUAL_STACK;
|
|
|
|
- }
|
|
|
|
#if MHD_VERSION >= 0x00095300
|
|
#if MHD_VERSION >= 0x00095300
|
|
flags |= MHD_USE_ERROR_LOG;
|
|
flags |= MHD_USE_ERROR_LOG;
|
|
#endif
|
|
#endif
|
|
@@ -127,7 +158,36 @@ void start_prometheus_server(void) {
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "prometheus exporter server will start using SELECT. "
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "prometheus exporter server will start using SELECT. "
|
|
"The exporter might be unreachable on highly used servers\n");
|
|
"The exporter might be unreachable on highly used servers\n");
|
|
}
|
|
}
|
|
- struct MHD_Daemon *daemon = promhttp_start_daemon(flags, turn_params.prometheus_port, NULL, NULL);
|
|
|
|
|
|
+
|
|
|
|
+ ioa_addr server_addr;
|
|
|
|
+ addr_set_any(&server_addr);
|
|
|
|
+ if (turn_params.prometheus_address[0]) {
|
|
|
|
+ if (make_ioa_addr((const uint8_t *)turn_params.prometheus_address, turn_params.prometheus_port, &server_addr) < 0) {
|
|
|
|
+ TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "could not parse prometheus collector's server address\n");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (is_ipv6_enabled() && server_addr.ss.sa_family == AF_INET6) {
|
|
|
|
+ flags |= MHD_USE_IPv6;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (MHD_is_feature_supported(MHD_FEATURE_IPv6) && is_ipv6_enabled()) {
|
|
|
|
+ flags |= MHD_USE_DUAL_STACK;
|
|
|
|
+ server_addr.ss.sa_family = AF_INET6;
|
|
|
|
+ server_addr.s6.sin6_port = htons((uint16_t)turn_params.prometheus_port);
|
|
|
|
+ } else {
|
|
|
|
+ server_addr.ss.sa_family = AF_INET;
|
|
|
|
+ server_addr.s4.sin_port = htons((uint16_t)turn_params.prometheus_port);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ uint8_t addr[MAX_IOA_ADDR_STRING];
|
|
|
|
+ addr_to_string(&server_addr, addr);
|
|
|
|
+ TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "prometheus exporter server will listen on %s\n", addr);
|
|
|
|
+
|
|
|
|
+ struct MHD_Daemon *daemon =
|
|
|
|
+ MHD_start_daemon(flags, 0, NULL, NULL, &promhttp_handler, NULL, MHD_OPTION_LISTENING_ADDRESS_REUSE, 1,
|
|
|
|
+ MHD_OPTION_SOCK_ADDR, &server_addr, MHD_OPTION_END);
|
|
if (daemon == NULL) {
|
|
if (daemon == NULL) {
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "could not start prometheus collector\n");
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "could not start prometheus collector\n");
|
|
return;
|
|
return;
|