tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

metrics_store_entry.h (2957B)


      1 /* Copyright (c) 2020-2021, The Tor Project, Inc. */
      2 /* See LICENSE for licensing information */
      3 
      4 /**
      5 * @file metrics_store_entry.h
      6 * @brief Header for lib/metrics/metrics_store_entry.c
      7 **/
      8 
      9 #ifndef TOR_LIB_METRICS_METRICS_STORE_ENTRY_H
     10 #define TOR_LIB_METRICS_METRICS_STORE_ENTRY_H
     11 
     12 #include "lib/cc/torint.h"
     13 
     14 #include "lib/metrics/metrics_common.h"
     15 #include "lib/container/smartlist.h"
     16 
     17 #ifdef METRICS_STORE_ENTRY_PRIVATE
     18 
     19 /** Metrics store entry. They reside in a metrics_store_t object and are
     20 * opaque to the outside world. */
     21 struct metrics_store_entry_t {
     22  /** Type of entry. */
     23  metrics_type_t type;
     24 
     25  /** Name. */
     26  char *name;
     27 
     28  /** Help comment string. */
     29  char *help;
     30 
     31  /** Labels attached to that entry. If NULL, no labels.
     32   *
     33   * Labels are used to add extra context to a metrics. For example, a label
     34   * could be an onion address so the metrics can be differentiate. */
     35  smartlist_t *labels;
     36 
     37  /* Actual data. */
     38  union {
     39    metrics_counter_t counter;
     40    metrics_gauge_t gauge;
     41    metrics_histogram_t histogram;
     42  } u;
     43 };
     44 
     45 #endif /* defined(METRICS_STORE_ENTRY_PRIVATE) */
     46 
     47 typedef struct metrics_store_entry_t metrics_store_entry_t;
     48 
     49 /* Allocators. */
     50 metrics_store_entry_t *metrics_store_entry_new(const metrics_type_t type,
     51                                               const char *name,
     52                                               const char *help,
     53                                               size_t bucket_count,
     54                                               const int64_t *buckets);
     55 
     56 void metrics_store_entry_free_(metrics_store_entry_t *entry);
     57 #define metrics_store_entry_free(entry) \
     58  FREE_AND_NULL(metrics_store_entry_t, metrics_store_entry_free_, (entry));
     59 
     60 /* Accessors. */
     61 int64_t metrics_store_entry_get_value(const metrics_store_entry_t *entry);
     62 uint64_t metrics_store_hist_entry_get_value(const metrics_store_entry_t *entry,
     63                                           const int64_t bucket);
     64 bool metrics_store_entry_has_label(const metrics_store_entry_t *entry,
     65                                   const char *label);
     66 metrics_store_entry_t *metrics_store_find_entry_with_label(
     67        const smartlist_t *entries, const char *label);
     68 bool metrics_store_entry_is_histogram(const metrics_store_entry_t *entry);
     69 uint64_t metrics_store_hist_entry_get_count(
     70        const metrics_store_entry_t *entry);
     71 int64_t metrics_store_hist_entry_get_sum(const metrics_store_entry_t *entry);
     72 
     73 /* Modifiers. */
     74 void metrics_store_entry_add_label(metrics_store_entry_t *entry,
     75                                   const char *label);
     76 void metrics_store_entry_reset(metrics_store_entry_t *entry);
     77 void metrics_store_entry_update(metrics_store_entry_t *entry,
     78                                const int64_t value);
     79 void metrics_store_hist_entry_update(metrics_store_entry_t *entry,
     80                                const int64_t value, const int64_t obs);
     81 
     82 #endif /* !defined(TOR_LIB_METRICS_METRICS_STORE_ENTRY_H) */