53 char date[RFC1123_TIME_LEN+1];
58 buf_add_printf(buf,
"Content-Type: text/plain; charset=utf-8\r\n");
59 buf_add_printf(buf,
"Content-Length: %" TOR_PRIuSZ
"\r\n", data_len);
76 for (
unsigned i = 0; i < n_tor_subsystems; ++i) {
88 } SMARTLIST_FOREACH_END(store);
103 char *headers = NULL, *
command = NULL, *url = NULL;
104 const char *errmsg = NULL;
116 const int http_status =
118 if (http_status < 0) {
119 errmsg =
"HTTP/1.0 400 Bad Request\r\n\r\n";
121 }
else if (http_status == 0) {
128 if (cmd_status < 0) {
129 errmsg =
"HTTP/1.0 400 Bad Request\r\n\r\n";
132 errmsg =
"HTTP/1.0 405 Method Not Allowed\r\n\r\n";
138 #define EXPECTED_URL_PATH "/metrics"
139 #define EXPECTED_URL_PATH_LEN (sizeof(EXPECTED_URL_PATH) - 1)
142 strlen(url) == EXPECTED_URL_PATH_LEN) {
149 errmsg =
"HTTP/1.0 404 Not Found\r\n\r\n";
158 log_info(
LD_EDGE,
"HTTP metrics error: saying %s",
escaped(errmsg));
159 connection_buf_add(errmsg, strlen(errmsg), conn);
161 connection_mark_and_flush(conn);
178 int num_elems, ok = 0, ret = -1;
179 const char *addrport_str = NULL, *fmt_str = NULL;
196 SPLIT_SKIP_SPACE | SPLIT_IGNORE_BLANK, 2);
198 *err_msg_out = tor_strdup(
"MetricsPort is missing port.");
202 addrport_str = smartlist_get(elems, 0);
203 if (num_elems >= 2) {
205 fmt_str = smartlist_get(elems, 1);
206 if (!strcasecmp(fmt_str,
"prometheus")) {
209 tor_asprintf(err_msg_out,
"MetricsPort unknown format: %s", fmt_str);
225 (uint16_t *) &cfg->
port) < 0) {
226 *err_msg_out = tor_strdup(
"MetricsPort address/port failed to parse or "
236 options->MetricsPort_set = 1;
246 smartlist_free(elems);
256 log_info(
LD_EDGE,
"Metrics connection reached EOF. Closing.");
257 connection_mark_for_close(conn);
int tor_addr_parse(tor_addr_t *addr, const char *src)
void buf_add_printf(buf_t *buf, const char *format,...)
buf_t * buf_new_with_capacity(size_t size)
size_t buf_datalen(const buf_t *buf)
void buf_add_string(buf_t *buf, const char *string)
port_cfg_t * port_cfg_new(size_t namelen)
tor_cmdline_mode_t command
Header file for config.c.
int connection_fetch_from_buf_http(connection_t *conn, char **headers_out, size_t max_headerlen, char **body_out, size_t *body_used, size_t max_bodylen, int force_complete)
void connection_buf_add_buf(connection_t *conn, buf_t *buf)
Header file for connection.c.
#define CONN_TYPE_METRICS
#define CONN_TYPE_METRICS_LISTENER
Header file for connection_or.c.
Base connection structure.
int parse_http_command(const char *headers, char **command_out, char **url_out)
Header file for directory.c.
const char * escaped(const char *s)
Headers for util_malloc.c.
int metrics_connection_process_inbuf(connection_t *conn)
static void write_metrics_http_response(const size_t data_len, connection_t *conn)
int metrics_connection_reached_eof(connection_t *conn)
int metrics_connection_finished_flushing(connection_t *conn)
static bool metrics_request_allowed(const tor_addr_t *peer_addr)
static metrics_format_t the_format
void metrics_cleanup(void)
int metrics_parse_ports(or_options_t *options, smartlist_t *ports, char **err_msg_out)
buf_t * metrics_get_output(const metrics_format_t fmt)
Header for feature/metrics/metrics.c.
@ METRICS_FORMAT_PROMETHEUS
void metrics_store_get_output(const metrics_format_t fmt, const metrics_store_t *store, buf_t *data)
Header for lib/metrics/metrics_store.c.
Declarations for types used throughout the Tor networking system.
Master header file for Tor-specific functionality.
long tor_parse_long(const char *s, int base, long min, long max, int *ok, char **next)
int metrics_policy_permits_address(const tor_addr_t *addr)
Header file for policies.c.
Listener port configuration structure.
int tor_asprintf(char **strp, const char *fmt,...)
int tor_addr_port_lookup(const char *s, tor_addr_t *addr_out, uint16_t *port_out)
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep, int flags, int max)
struct config_line_t * MetricsPort_lines
const struct smartlist_t *(* get_metrics)(void)
const struct subsys_fns_t * tor_subsystems[]
void format_rfc1123_time(char *buf, time_t t)
Macros to manage assertions, fatal and non-fatal.
int strcmpstart(const char *s1, const char *s2)