Tor  0.4.8.0-alpha-dev
hs_metrics_entry.c
Go to the documentation of this file.
1 /* Copyright (c) 2020-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 /**
5  * @file hs_metrics_entry.c
6  * @brief Defines the metrics entry that are collected by an onion service.
7  **/
8 
9 #define HS_METRICS_ENTRY_PRIVATE
10 
11 #include <stddef.h>
12 
13 #include "orconfig.h"
14 
15 #include "lib/cc/compat_compiler.h"
16 #include "lib/log/log.h"
17 #include "lib/log/util_bug.h"
18 
20 
21 /* Histogram time buckets (in milliseconds). */
22 static const int64_t hs_metrics_circ_build_time_buckets[] =
23 {
24  1000, /* 1s */
25  5000, /* 5s */
26  10000, /* 10s */
27  30000, /* 30s */
28  60000 /* 60s */
29 };
30 
31 static const size_t hs_metrics_circ_build_time_buckets_size =
32  ARRAY_LENGTH(hs_metrics_circ_build_time_buckets);
33 
34 /** The base metrics that is a static array of metrics that are added to every
35  * single new stores.
36  *
37  * The key member MUST be also the index of the entry in the array. */
38 const hs_metrics_entry_t base_metrics[] =
39 {
40  {
41  .key = HS_METRICS_NUM_INTRODUCTIONS,
42  .type = METRICS_TYPE_COUNTER,
43  .name = METRICS_NAME(hs_intro_num_total),
44  .help = "Total number of introduction received",
45  .port_as_label = false,
46  },
47  {
48  .key = HS_METRICS_APP_WRITE_BYTES,
49  .type = METRICS_TYPE_COUNTER,
50  .name = METRICS_NAME(hs_app_write_bytes_total),
51  .help = "Total number of bytes written to the application",
52  .port_as_label = true,
53  },
54  {
55  .key = HS_METRICS_APP_READ_BYTES,
56  .type = METRICS_TYPE_COUNTER,
57  .name = METRICS_NAME(hs_app_read_bytes_total),
58  .help = "Total number of bytes read from the application",
59  .port_as_label = true,
60  },
61  {
62  .key = HS_METRICS_NUM_ESTABLISHED_RDV,
63  .type = METRICS_TYPE_GAUGE,
64  .name = METRICS_NAME(hs_rdv_established_count),
65  .help = "Total number of established rendezvous circuits",
66  },
67  {
68  .key = HS_METRICS_NUM_RDV,
69  .type = METRICS_TYPE_COUNTER,
70  .name = METRICS_NAME(hs_rdv_num_total),
71  .help = "Total number of rendezvous circuits created",
72  },
73  {
74  .key = HS_METRICS_NUM_FAILED_RDV,
75  .type = METRICS_TYPE_COUNTER,
76  .name = METRICS_NAME(hs_rdv_error_count),
77  .help = "Total number of rendezvous circuit errors",
78  },
79  {
80  .key = HS_METRICS_NUM_ESTABLISHED_INTRO,
81  .type = METRICS_TYPE_GAUGE,
82  .name = METRICS_NAME(hs_intro_established_count),
83  .help = "Total number of established introduction circuit",
84  },
85  {
86  .key = HS_METRICS_NUM_REJECTED_INTRO_REQ,
87  .type = METRICS_TYPE_COUNTER,
88  .name = METRICS_NAME(hs_intro_rejected_intro_req_count),
89  .help = "Total number of rejected introduction circuits",
90  },
91  {
92  .key = HS_METRICS_INTRO_CIRC_BUILD_TIME,
93  .type = METRICS_TYPE_HISTOGRAM,
94  .name = METRICS_NAME(hs_intro_circ_build_time),
95  .buckets = hs_metrics_circ_build_time_buckets,
96  .bucket_count = hs_metrics_circ_build_time_buckets_size,
97  .help = "The introduction circuit build time in milliseconds",
98  },
99  {
100  .key = HS_METRICS_REND_CIRC_BUILD_TIME,
101  .type = METRICS_TYPE_HISTOGRAM,
102  .name = METRICS_NAME(hs_rend_circ_build_time),
103  .buckets = hs_metrics_circ_build_time_buckets,
104  .bucket_count = hs_metrics_circ_build_time_buckets_size,
105  .help = "The rendezvous circuit build time in milliseconds",
106  },
107 };
108 
109 /** Size of base_metrics array that is number of entries. */
111 
112 /** Possible values for the reason label of the
113  * hs_intro_rejected_intro_req_count metric. */
115 {
116  HS_METRICS_ERR_INTRO_REQ_BAD_AUTH_KEY,
117  HS_METRICS_ERR_INTRO_REQ_INTRODUCE2,
118  HS_METRICS_ERR_INTRO_REQ_SUBCREDENTIAL,
119  HS_METRICS_ERR_INTRO_REQ_INTRODUCE2_REPLAY,
120 };
121 
122 /** The number of entries in the hs_metrics_intro_req_error_reasons array. */
125 
126 /** Possible values for the reason label of the hs_rdv_error_count metric. */
128 {
129  HS_METRICS_ERR_RDV_RP_CONN_FAILURE,
130  HS_METRICS_ERR_RDV_PATH,
131  HS_METRICS_ERR_RDV_RENDEZVOUS1,
132  HS_METRICS_ERR_RDV_E2E,
133  HS_METRICS_ERR_RDV_RETRY,
134 };
135 
136 /** The number of entries in the hs_metrics_rend_error_reasons array. */
Utility macros to handle different features and behavior in different compilers.
#define ARRAY_LENGTH(x)
const char * hs_metrics_rend_error_reasons[]
const hs_metrics_entry_t base_metrics[]
const size_t hs_metrics_intro_req_error_reasons_size
const size_t base_metrics_size
const char * hs_metrics_intro_req_error_reasons[]
const size_t hs_metrics_rend_error_reasons_size
Header for feature/hs/hs_metrics_entry.c.
Headers for log.c.
Macros to manage assertions, fatal and non-fatal.