feat: Additional counters and gauges

master
Sean McBride 3 years ago
parent 71c99e91bb
commit ccbee1a41e

@ -125,7 +125,8 @@
"pool.h": "c",
"local_cleanup_queue.h": "c",
"sandbox_state_transition.h": "c",
"http_session_perf_log.h": "c"
"http_session_perf_log.h": "c",
"perf_window.h": "c"
},
"files.exclude": {
"**/.git": true,

@ -5,6 +5,9 @@
#define ADMISSIONS_CONTROL_GRANULARITY 1000000
extern _Atomic uint64_t admissions_control_admitted;
extern uint64_t admissions_control_capacity;
void admissions_control_initialize(void);
void admissions_control_add(uint64_t admissions_estimate);
void admissions_control_subtract(uint64_t admissions_estimate);

@ -14,6 +14,7 @@
#include "http_request.h"
#include "http_parser.h"
#include "http_parser_settings.h"
#include "http_total.h"
#include "tenant.h"
#include "vec.h"
#include "http_session_perf_log.h"
@ -173,6 +174,7 @@ http_session_set_response_header(struct http_session *session, int status_code,
{
assert(session != NULL);
assert(status_code >= 200 && status_code <= 599);
http_total_increment(status_code);
if (status_code == 200) {
session->response_header_length = snprintf(session->response_header,

@ -55,3 +55,19 @@ http_total_increment_5XX()
{
atomic_fetch_add(&http_total_5XX, 1);
}
static inline void
http_total_increment(int status_code)
{
#ifdef LOG_TOTAL_REQS_RESPS
if (status_code >= 200 && status_code <= 299) {
http_total_increment_2XX();
} else if (status_code >= 400 && status_code <= 499) {
http_total_increment_4XX();
} else if (status_code >= 500 && status_code <= 599) {
http_total_increment_5XX();
}
#else
if (status_code >= 500 && status_code <= 599) { http_total_increment_5XX(); }
#endif
}

@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "admissions_control.h"
#include "runtime.h"
#include "scheduler_options.h"
@ -100,12 +101,12 @@ route_config_validate(struct route_config *config, bool *did_set)
if (config->admissions_percentile > 99 || config->admissions_percentile < 50) {
fprintf(stderr, "admissions-percentile must be > 50 and <= 99 but was %u\n",
route_config->admissions_percentile);
config->admissions_percentile);
return -1;
}
/* If the ratio is too big, admissions control is too coarse */
uint32_t ratio = route_config->relative_deadline_us / route_config->expected_execution_us;
uint32_t ratio = config->relative_deadline_us / config->expected_execution_us;
if (ratio > ADMISSIONS_CONTROL_GRANULARITY) {
fprintf(stderr,
"Ratio of Deadline to Execution time cannot exceed admissions control "

@ -1,8 +1,11 @@
#include <assert.h>
#include <stdatomic.h>
#include <unistd.h>
#include "admissions_control.h"
#include "debuglog.h"
#include "panic.h"
#include "runtime.h"
/*
* Unitless estimate of the instantaneous fraction of system capacity required to complete all previously

@ -1,5 +1,7 @@
#include "admissions_control.h"
#include "admissions_info.h"
#include "debuglog.h"
#include "perf_window.h"
/**
* Initializes perf window

@ -1,8 +1,11 @@
#include <stdlib.h>
#include <unistd.h>
#include "admissions_control.h"
#include "tcp_server.h"
#include "http_total.h"
#include "sandbox_total.h"
#include "sandbox_state.h"
struct tcp_server metrics_server;
@ -37,25 +40,98 @@ metrics_server_handler(int client_socket)
uint32_t total_reqs = atomic_load(&http_total_requests);
uint32_t total_5XX = atomic_load(&http_total_5XX);
#ifdef LOG_TOTAL_REQS_RESPS
uint32_t total_2XX = atomic_load(&http_total_2XX);
uint32_t total_4XX = atomic_load(&http_total_4XX);
#endif
uint32_t total_sandboxes = atomic_load(&sandbox_total);
#ifdef SANDBOX_STATE_TOTALS
uint32_t total_sandboxes_uninitialized = atomic_load(&sandbox_state_totals[SANDBOX_UNINITIALIZED]);
uint32_t total_sandboxes_allocated = atomic_load(&sandbox_state_totals[SANDBOX_ALLOCATED]);
uint32_t total_sandboxes_initialized = atomic_load(&sandbox_state_totals[SANDBOX_INITIALIZED]);
uint32_t total_sandboxes_runnable = atomic_load(&sandbox_state_totals[SANDBOX_RUNNABLE]);
uint32_t total_sandboxes_preempted = atomic_load(&sandbox_state_totals[SANDBOX_PREEMPTED]);
uint32_t total_sandboxes_running_sys = atomic_load(&sandbox_state_totals[SANDBOX_RUNNING_SYS]);
uint32_t total_sandboxes_running_user = atomic_load(&sandbox_state_totals[SANDBOX_RUNNING_USER]);
uint32_t total_sandboxes_interrupted = atomic_load(&sandbox_state_totals[SANDBOX_INTERRUPTED]);
uint32_t total_sandboxes_asleep = atomic_load(&sandbox_state_totals[SANDBOX_ASLEEP]);
uint32_t total_sandboxes_returned = atomic_load(&sandbox_state_totals[SANDBOX_RETURNED]);
uint32_t total_sandboxes_complete = atomic_load(&sandbox_state_totals[SANDBOX_COMPLETE]);
uint32_t total_sandboxes_error = atomic_load(&sandbox_state_totals[SANDBOX_ERROR]);
#endif
#ifdef ADMISSIONS_CONTROL
uint32_t work_admitted = atomic_load(&admissions_control_admitted);
double work_admitted_percentile = (double)work_admitted / admissions_control_capacity * 100;
#endif
fprintf(ostream, "HTTP/1.1 200 OK\r\n\r\n");
fprintf(ostream, "# TYPE total_requests counter\n");
fprintf(ostream, "total_requests: %d\n", total_reqs);
fprintf(ostream, "# TYPE total_rejections counter\n");
fprintf(ostream, "total_rejections: %d\n", total_5XX);
fflush(ostream);
#ifdef ADMISSIONS_CONTROL
fprintf(ostream, "# TYPE work_admitted_percentile gauge\n");
fprintf(ostream, "work_admitted_percentile: %f\n", work_admitted_percentile);
#endif
fprintf(ostream, "# TYPE total_5XX counter\n");
fprintf(ostream, "total_5XX: %d\n", total_5XX);
#ifdef LOG_TOTAL_REQS_RESPS
fprintf(ostream, "# TYPE total_2XX counter\n");
fprintf(ostream, "total_2XX: %d\n", total_2XX);
fprintf(ostream, "# TYPE total_4XX counter\n");
fprintf(ostream, "total_4XX: %d\n", total_4XX);
#endif
// This global is padded by 1 for error handling, so decrement here for true value
fprintf(ostream, "# TYPE total_sandboxes counter\n");
fprintf(ostream, "total_sandboxes: %d\n", total_sandboxes - 1);
#ifdef SANDBOX_STATE_TOTALS
fprintf(ostream, "# TYPE total_sandboxes_uninitialized gauge\n");
fprintf(ostream, "total_sandboxes_uninitialized: %d\n", total_sandboxes_uninitialized);
fprintf(ostream, "# TYPE total_sandboxes_allocated gauge\n");
fprintf(ostream, "total_sandboxes_allocated: %d\n", total_sandboxes_allocated);
fprintf(ostream, "# TYPE total_sandboxes_initialized gauge\n");
fprintf(ostream, "total_sandboxes_initialized: %d\n", total_sandboxes_initialized);
rewind(ostream);
fprintf(ostream, "# TYPE total_sandboxes_runnable gauge\n");
fprintf(ostream, "total_sandboxes_runnable: %d\n", total_sandboxes_runnable);
char buf[256] = { 0 };
size_t nread = 0;
do {
nread = fread(buf, 1, 255, ostream);
buf[nread] = '\0';
/* TODO: Deal with blocking here! */
write(client_socket, buf, nread);
} while (nread > 0);
fprintf(ostream, "# TYPE total_sandboxes_preempted gauge\n");
fprintf(ostream, "total_sandboxes_preempted: %d\n", total_sandboxes_preempted);
fprintf(ostream, "# TYPE total_sandboxes_running_sys gauge\n");
fprintf(ostream, "total_sandboxes_running_sys: %d\n", total_sandboxes_running_sys);
fprintf(ostream, "# TYPE total_sandboxes_running_user gauge\n");
fprintf(ostream, "total_sandboxes_running_user: %d\n", total_sandboxes_running_user);
fprintf(ostream, "# TYPE total_sandboxes_interrupted gauge\n");
fprintf(ostream, "total_sandboxes_interrupted: %d\n", total_sandboxes_interrupted);
fprintf(ostream, "# TYPE total_sandboxes_asleep gauge\n");
fprintf(ostream, "total_sandboxes_asleep: %d\n", total_sandboxes_asleep);
fprintf(ostream, "# TYPE total_sandboxes_returned gauge\n");
fprintf(ostream, "total_sandboxes_returned: %d\n", total_sandboxes_returned);
fprintf(ostream, "# TYPE total_sandboxes_complete gauge\n");
fprintf(ostream, "total_sandboxes_complete: %d\n", total_sandboxes_complete);
fprintf(ostream, "# TYPE total_sandboxes_error gauge\n");
fprintf(ostream, "total_sandboxes_error: %d\n", total_sandboxes_error);
#endif
fflush(ostream);
write(client_socket, ostream_base, ostream_size);
rc = fclose(ostream);
assert(rc == 0);

Loading…
Cancel
Save