Macros | Functions | Variables
metrics.c File Reference

Metrics subsystem. More...

#include "orconfig.h"
#include "core/or/or.h"
#include "lib/encoding/confline.h"
#include "lib/log/util_bug.h"
#include "lib/malloc/malloc.h"
#include "lib/metrics/metrics_store.h"
#include "lib/net/resolve.h"
#include "lib/string/printf.h"
#include "lib/net/nettypes.h"
#include "lib/net/address.h"
#include "core/mainloop/connection.h"
#include "core/or/connection_st.h"
#include "core/or/policies.h"
#include "core/or/port_cfg_st.h"
#include "core/proto/proto_http.h"
#include "feature/dircommon/directory.h"
#include "feature/metrics/metrics.h"
#include "app/config/config.h"
#include "app/main/subsysmgr.h"

Go to the source code of this file.


#define EXPECTED_URL_PATH   "/metrics"
#define EXPECTED_URL_PATH_LEN   (sizeof(EXPECTED_URL_PATH) - 1) /* No NUL */


static bool metrics_request_allowed (const tor_addr_t *peer_addr)
static void write_metrics_http_response (const size_t data_len, connection_t *conn)
buf_t * metrics_get_output (const metrics_format_t fmt)
int metrics_connection_process_inbuf (connection_t *conn)
int metrics_parse_ports (or_options_t *options, smartlist_t *ports, char **err_msg_out)
void metrics_init (void)
void metrics_cleanup (void)


static metrics_format_t the_format = METRICS_FORMAT_PROMETHEUS

Detailed Description

Metrics subsystem.

Definition in file metrics.c.

Function Documentation

◆ metrics_cleanup()

void metrics_cleanup ( void  )

Cleanup and free any global memory of this subsystem.

Definition at line 254 of file metrics.c.

◆ metrics_connection_process_inbuf()

int metrics_connection_process_inbuf ( connection_t conn)

Process what is in the inbuf of this connection of type metrics.

Return 0 on success else -1 on error which will close the connection.

Definition at line 98 of file metrics.c.

Referenced by connection_process_inbuf().

◆ metrics_get_output()

buf_t* metrics_get_output ( const metrics_format_t  fmt)

Return newly allocated buffer containing the output of all subsystems having metrics.

This is used to output the content on the MetricsPort.

Definition at line 70 of file metrics.c.

◆ metrics_init()

void metrics_init ( void  )

Initialize the subsystem.

Definition at line 248 of file metrics.c.

◆ metrics_parse_ports()

int metrics_parse_ports ( or_options_t options,
smartlist_t ports,
char **  err_msg_out 

Parse metrics ports from options. On success, add the port to the ports list and return 0. On failure, set err_msg_out to a newly allocated string describing the problem and return -1.

Definition at line 171 of file metrics.c.

◆ metrics_request_allowed()

static bool metrics_request_allowed ( const tor_addr_t peer_addr)

Return true iff the given peer address is allowed by our MetricsPortPolicy option that is is in that list.

Definition at line 40 of file metrics.c.

Referenced by metrics_connection_process_inbuf().

◆ write_metrics_http_response()

static void write_metrics_http_response ( const size_t  data_len,
connection_t conn 

Helper: For a metrics port connection, write the HTTP response header using the data length passed.

Definition at line 50 of file metrics.c.

Variable Documentation

◆ the_format

Metrics format driver set by the MetricsPort option.

Definition at line 35 of file metrics.c.