diff --git a/plugins/in_nginx_exporter_metrics/nginx.c b/plugins/in_nginx_exporter_metrics/nginx.c index 9645fca8e75..bee495e23f8 100644 --- a/plugins/in_nginx_exporter_metrics/nginx.c +++ b/plugins/in_nginx_exporter_metrics/nginx.c @@ -1550,6 +1550,8 @@ struct nginx_ctx *nginx_ctx_init(struct flb_input_instance *ins, if (!upstream) { flb_plg_error(ins, "upstream initialization error"); + cmt_destroy(ctx->cmt); + flb_free(ctx); return NULL; } ctx->upstream = upstream; @@ -1570,6 +1572,7 @@ static int nginx_collect(struct flb_input_instance *ins, FLB_INPUT_RETURN(rc); } +static int nginx_ctx_destroy(struct nginx_ctx *ctx); /** * Callback function to initialize nginx metrics plugin * @@ -1585,6 +1588,7 @@ static int nginx_init(struct flb_input_instance *ins, struct nginx_ctx *ctx = NULL; struct cmt_counter *c; struct cmt_gauge *g; + int ret = -1; /* Allocate space for the configuration */ ctx = nginx_ctx_init(ins, config); @@ -1604,7 +1608,7 @@ static int nginx_init(struct flb_input_instance *ins, "Accepted client connections", 0, NULL); if (ctx->connections_accepted == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(ctx->connections_accepted); @@ -1612,7 +1616,7 @@ static int nginx_init(struct flb_input_instance *ins, "active", "active client connections", 0, NULL); if (ctx->connections_active == NULL) { - return -1; + goto nginx_init_end; } ctx->connections_handled = cmt_counter_create(ctx->cmt, "nginx", "connections", @@ -1620,7 +1624,7 @@ static int nginx_init(struct flb_input_instance *ins, "Handled client connections", 0, NULL); if (ctx->connections_handled == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(ctx->connections_handled); @@ -1629,7 +1633,7 @@ static int nginx_init(struct flb_input_instance *ins, "reading client connections", 0, NULL); if (ctx->connections_reading == NULL) { - return -1; + goto nginx_init_end; } ctx->connections_writing = cmt_gauge_create(ctx->cmt, "nginx", "connections", @@ -1637,7 +1641,7 @@ static int nginx_init(struct flb_input_instance *ins, "writing client connections", 0, NULL); if (ctx->connections_writing == NULL) { - return -1; + goto nginx_init_end; } ctx->connections_waiting = cmt_gauge_create(ctx->cmt, "nginx", "connections", @@ -1645,14 +1649,14 @@ static int nginx_init(struct flb_input_instance *ins, "waiting client connections", 0, NULL); if (ctx->connections_waiting == NULL) { - return -1; + goto nginx_init_end; } ctx->connections_total = cmt_counter_create(ctx->cmt, "nginx", "http", "requests_total", "Total http requests", 0, NULL); if (ctx->connections_total == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(ctx->connections_total); @@ -1678,7 +1682,7 @@ static int nginx_init(struct flb_input_instance *ins, "1 for a successful scrape and 0 for a failed " "one", 0, NULL); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->connection_up = g; @@ -1687,7 +1691,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Plus Total Connections", 0, NULL); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->plus_connections->connections_accepted = c; @@ -1698,7 +1702,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Plus Total Connections", 0, NULL); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->plus_connections->connections_dropped = c; @@ -1708,7 +1712,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Plus Total Connections", 0, NULL); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->plus_connections->connections_active = c; @@ -1718,7 +1722,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Plus Total Connections", 0, NULL); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->plus_connections->connections_idle = c; @@ -1728,7 +1732,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Plus Total Connections", 0, NULL); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->plus_ssl->handshakes = c; @@ -1738,7 +1742,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Plus Total Connections", 0, NULL); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->plus_ssl->handshakes_failed = c; @@ -1748,7 +1752,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Plus Total Connections", 0, NULL); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->plus_ssl->session_reuses = c; @@ -1758,7 +1762,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Plus Total Connections", 0, NULL); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->plus_http_requests->total = c; @@ -1768,7 +1772,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Plus Total Connections", 0, NULL); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->plus_http_requests->current = c; @@ -1780,7 +1784,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Server Zone discarded", 1, (char *[]){"server_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->server_zones->discarded = c; @@ -1792,7 +1796,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Server Zone processing", 1, (char *[]){"server_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->server_zones->processing = c; @@ -1804,7 +1808,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Server Zone received", 1, (char *[]){"server_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->server_zones->received = c; @@ -1816,7 +1820,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Server Zone requests", 1, (char *[]){"server_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->server_zones->requests = c; @@ -1828,7 +1832,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Server Zone responses", 2, (char *[]){"server_zone", "code"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->server_zones->responses = c; @@ -1840,7 +1844,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Server Zone sent", 1, (char *[]){"server_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->server_zones->sent = c; @@ -1852,7 +1856,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Server Zone discarded", 1, (char *[]){"location_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->location_zones->discarded = c; @@ -1864,7 +1868,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Server Zone received", 1, (char *[]){"location_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->location_zones->received = c; @@ -1876,7 +1880,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Server Zone requests", 1, (char *[]){"location_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->location_zones->requests = c; @@ -1888,7 +1892,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Server Zone responses", 2, (char *[]){"location_zone", "code"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->location_zones->responses = c; @@ -1900,7 +1904,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Server Zone sent", 1, (char *[]){"location_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->location_zones->sent = c; @@ -1912,7 +1916,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Keepalives", 1, (char *[]){"upstream"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->upstreams->keepalives = g; @@ -1923,7 +1927,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Zombies", 1, (char *[]){"upstream"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->upstreams->zombies = g; @@ -1934,7 +1938,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Active", 2, (char *[]){"upstream","server"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->upstreams->active = g; @@ -1945,7 +1949,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Fails", 2, (char *[]){"upstream","server"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->upstreams->fails = c; @@ -1957,7 +1961,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Header Time", 2, (char *[]){"upstream","server"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->upstreams->header_time = g; @@ -1968,7 +1972,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Limit", 2, (char *[]){"upstream","server"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->upstreams->limit = g; @@ -1979,7 +1983,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Received", 2, (char *[]){"upstream","server"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->upstreams->received = c; @@ -1991,7 +1995,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Requests", 2, (char *[]){"upstream","server"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->upstreams->requests = c; @@ -2003,7 +2007,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Responses", 3, (char *[]){"code", "upstream","server"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->upstreams->responses = c; @@ -2015,7 +2019,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Response Time", 2, (char *[]){"upstream","server"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->upstreams->response_time = g; @@ -2026,7 +2030,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Sent", 2, (char *[]){"upstream","server"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->upstreams->sent = c; @@ -2038,7 +2042,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream State", 2, (char *[]){"upstream","server"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->upstreams->state = g; @@ -2049,7 +2053,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Unavailable", 2, (char *[]){"upstream","server"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->upstreams->unavail = c; @@ -2061,7 +2065,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Stream Server Zone connections", 1, (char *[]){"server_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->streams->connections = c; @@ -2073,7 +2077,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Stream Server Zone discarded", 1, (char *[]){"server_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->streams->discarded = c; @@ -2086,7 +2090,7 @@ static int nginx_init(struct flb_input_instance *ins, "processing", 1, (char *[]){"server_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->streams->processing = c; @@ -2098,7 +2102,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Stream Server Zone received", 1, (char *[]){"server_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->streams->received = c; @@ -2110,7 +2114,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Stream Server Zone sent", 1, (char *[]){"server_zone"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->streams->sent = c; @@ -2122,7 +2126,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Stream Server Zone Sessions", 2, (char *[]){"server_zone", "code"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->streams->sessions = c; @@ -2134,7 +2138,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Zombies", 1, (char *[]){"upstream"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->stream_upstreams->zombies = g; @@ -2145,7 +2149,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Active", 2, (char *[]){"upstream","server"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->stream_upstreams->active = g; @@ -2156,7 +2160,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Fails", 2, (char *[]){"upstream","server"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->stream_upstreams->fails = c; @@ -2168,7 +2172,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Limit", 2, (char *[]){"upstream","server"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->stream_upstreams->limit = g; @@ -2179,7 +2183,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Received", 2, (char *[]){"upstream","server"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->stream_upstreams->received = c; @@ -2191,7 +2195,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Header Time", 2, (char *[]){"upstream", "server"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->stream_upstreams->connect_time = g; @@ -2202,7 +2206,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Header Time", 2, (char *[]){"upstream", "server"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->stream_upstreams->first_byte_time = g; @@ -2213,7 +2217,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Requests", 2, (char *[]){"upstream","server"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->stream_upstreams->connections = c; @@ -2225,7 +2229,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Response Time", 2, (char *[]){"upstream","server"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->stream_upstreams->response_time = g; @@ -2236,7 +2240,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Sent", 2, (char *[]){"upstream","server"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->stream_upstreams->sent = c; @@ -2248,7 +2252,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream State", 2, (char *[]){"upstream","server"}); if (g == NULL) { - return -1; + goto nginx_init_end; } ctx->stream_upstreams->state = g; @@ -2259,7 +2263,7 @@ static int nginx_init(struct flb_input_instance *ins, "NGINX Upstream Unavailable", 2, (char *[]){"upstream","server"}); if (c == NULL) { - return -1; + goto nginx_init_end; } cmt_counter_allow_reset(c); ctx->stream_upstreams->unavail = c; @@ -2269,7 +2273,13 @@ static int nginx_init(struct flb_input_instance *ins, nginx_collect, 1, 0, config); - return 0; + ret = 0; + nginx_init_end: + if (ret < 0) { + nginx_ctx_destroy(ctx); + } + + return ret; }