fix: Correct routes and URLs to please prometheus

master
Sean McBride 2 years ago
parent 36edac7425
commit 8b2b26ffe0

@ -56,7 +56,7 @@ metrics_server_thread_spawn(int client_socket)
fgets(http_status_code_buf, 256, req_body); fgets(http_status_code_buf, 256, req_body);
fclose(req_body); fclose(req_body);
if (strncmp(http_status_code_buf, "GET / HTTP", 10) != 0) { if (strncmp(http_status_code_buf, "GET /metrics HTTP", 10) != 0) {
write(client_socket, http_header_build(404), http_header_len(404)); write(client_socket, http_header_build(404), http_header_len(404));
close(client_socket); close(client_socket);
return; return;

@ -25,17 +25,20 @@ render_routes(struct route *route, void *arg_one, void *arg_two)
uint64_t total_4XX = atomic_load(&route->metrics.total_4XX); uint64_t total_4XX = atomic_load(&route->metrics.total_4XX);
uint64_t total_5XX = atomic_load(&route->metrics.total_5XX); uint64_t total_5XX = atomic_load(&route->metrics.total_5XX);
fprintf(ostream, "# TYPE %s_%s_total_requests counter\n", tenant->name, route->route); // Strip leading /
fprintf(ostream, "%s_%s_total_requests: %lu\n", tenant->name, route->route, total_requests); const char *route_label = &route->route[1];
fprintf(ostream, "# TYPE %s_%s_total_2XX counter\n", tenant->name, route->route); fprintf(ostream, "# TYPE %s_%s_total_requests counter\n", tenant->name, route_label);
fprintf(ostream, "%s_%s_total_2XX: %lu\n", tenant->name, route->route, total_2XX); fprintf(ostream, "%s_%s_total_requests: %lu\n", tenant->name, route_label, total_requests);
fprintf(ostream, "# TYPE %s_%s_total_4XX counter\n", tenant->name, route->route); fprintf(ostream, "# TYPE %s_%s_total_2XX counter\n", tenant->name, route_label);
fprintf(ostream, "%s_%s_total_4XX: %lu\n", tenant->name, route->route, total_4XX); fprintf(ostream, "%s_%s_total_2XX: %lu\n", tenant->name, route_label, total_2XX);
fprintf(ostream, "# TYPE %s_%s_total_5XX counter\n", tenant->name, route->route); fprintf(ostream, "# TYPE %s_%s_total_4XX counter\n", tenant->name, route_label);
fprintf(ostream, "%s_%s_total_5XX: %lu\n", tenant->name, route->route, total_5XX); fprintf(ostream, "%s_%s_total_4XX: %lu\n", tenant->name, route_label, total_4XX);
fprintf(ostream, "# TYPE %s_%s_total_5XX counter\n", tenant->name, route_label);
fprintf(ostream, "%s_%s_total_5XX: %lu\n", tenant->name, route_label, total_5XX);
#ifdef ADMISSIONS_CONTROL #ifdef ADMISSIONS_CONTROL
fprintf(ostream, "# TYPE %s_%s_latency_p50 gauge\n", tenant->name, route->route); fprintf(ostream, "# TYPE %s_%s_latency_p50 gauge\n", tenant->name, route->route);

Loading…
Cancel
Save