Tor  0.4.8.0-alpha-dev
Macros | Functions
hs_metrics.c File Reference

Onion service metrics exposed through the MetricsPort. More...

#include "orconfig.h"
#include "lib/malloc/malloc.h"
#include "lib/container/smartlist.h"
#include "lib/metrics/metrics_store.h"
#include "lib/log/util_bug.h"
#include "feature/hs/hs_metrics.h"
#include "feature/hs/hs_metrics_entry.h"
#include "feature/hs/hs_service.h"

Go to the source code of this file.

Functions

static const char * port_to_str (const uint16_t port)
 
static void add_metric_with_labels (hs_service_t *service, hs_metrics_key_t metric, bool port_as_label, uint16_t port)
 
static void init_store (hs_service_t *service)
 
void hs_metrics_update_by_service (const hs_metrics_key_t key, const hs_service_t *service, uint16_t port, const char *reason, int64_t n, int64_t obs)
 
void hs_metrics_update_by_ident (const hs_metrics_key_t key, const ed25519_public_key_t *ident_pk, const uint16_t port, const char *reason, int64_t n, int64_t obs)
 
const smartlist_ths_metrics_get_stores (void)
 
void hs_metrics_service_init (hs_service_t *service)
 
void hs_metrics_service_free (hs_service_t *service)
 

Detailed Description

Onion service metrics exposed through the MetricsPort.

Definition in file hs_metrics.c.

Function Documentation

◆ add_metric_with_labels()

static void add_metric_with_labels ( hs_service_t service,
hs_metrics_key_t  metric,
bool  port_as_label,
uint16_t  port 
)
static

Add a new metric to the metrics store of the service.

metric is the index of the metric in the base_metrics array.

Definition at line 38 of file hs_metrics.c.

Referenced by init_store().

◆ hs_metrics_get_stores()

const smartlist_t* hs_metrics_get_stores ( void  )

Return a list of all the onion service metrics stores. This is the function attached to the .get_metrics() member of the subsys_t.

Definition at line 213 of file hs_metrics.c.

◆ hs_metrics_service_free()

void hs_metrics_service_free ( hs_service_t service)

Free the metrics store in the given service.

Definition at line 244 of file hs_metrics.c.

◆ hs_metrics_service_init()

void hs_metrics_service_init ( hs_service_t service)

Initialize the metrics store in the given service.

Definition at line 226 of file hs_metrics.c.

Referenced by register_service().

◆ hs_metrics_update_by_ident()

void hs_metrics_update_by_ident ( const hs_metrics_key_t  key,
const ed25519_public_key_t ident_pk,
const uint16_t  port,
const char *  reason,
int64_t  n,
int64_t  obs 
)

Update the metrics key entry in the store of a service identified by the given identity public key. The port, if non 0, and the reason label, if non NULL, are used to find the correct metrics entry. The value n is the value used to update the entry.

This is used by callsite that have access to the key but not the service object so an extra lookup is done to find the service.

Definition at line 190 of file hs_metrics.c.

◆ hs_metrics_update_by_service()

void hs_metrics_update_by_service ( const hs_metrics_key_t  key,
const hs_service_t service,
uint16_t  port,
const char *  reason,
int64_t  n,
int64_t  obs 
)

Update the metrics key entry in the store in the given service. The port, if non 0, and the reason label, if non NULL, are used to find the correct metrics entry. The value n is the value used to update the entry.

Definition at line 146 of file hs_metrics.c.

Referenced by hs_metrics_update_by_ident().

◆ init_store()

static void init_store ( hs_service_t service)
static

Initialize a metrics store for the given service.

Essentially, this goes over the base_metrics array and adds them all to the store set with their label(s) if any.

Definition at line 124 of file hs_metrics.c.

Referenced by hs_metrics_service_init().

◆ port_to_str()

static const char* port_to_str ( const uint16_t  port)
static

Return a static buffer pointer that contains the port as a string.

Subsequent call to this function invalidates the previous buffer.

Definition at line 26 of file hs_metrics.c.