| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | #ifndef DBENGINE_METRIC_H |
| 3 | #define DBENGINE_METRIC_H |
| 4 | |
| 5 | #include "../rrd.h" |
| 6 | |
| 7 | typedef struct metric METRIC; |
| 8 | typedef struct mrg MRG; |
| 9 | |
| 10 | typedef struct mrg_entry { |
| 11 | nd_uuid_t *uuid; |
| 12 | Word_t section; |
| 13 | time_t first_time_s; |
| 14 | time_t last_time_s; |
| 15 | uint32_t latest_update_every_s; |
| 16 | } MRG_ENTRY; |
| 17 | |
| 18 | struct mrg_statistics { |
| 19 | // --- non-atomic --- under a write lock |
| 20 | |
| 21 | size_t entries; |
| 22 | int64_t size; // total memory used, with indexing |
| 23 | |
| 24 | size_t additions; |
| 25 | size_t additions_duplicate; |
| 26 | |
| 27 | size_t deletions; |
| 28 | size_t delete_having_retention_or_referenced; |
| 29 | size_t delete_misses; |
| 30 | |
| 31 | // --- atomic --- multiple readers / writers |
| 32 | |
| 33 | PAD64(ssize_t) entries_acquired; |
| 34 | PAD64(ssize_t) current_references; |
| 35 | |
| 36 | PAD64(size_t) search_hits; |
| 37 | PAD64(size_t) search_misses; |
| 38 | |
| 39 | PAD64(size_t) writers; |
| 40 | PAD64(size_t) writers_conflicts; |
| 41 | }; |
| 42 | |
| 43 | MRG *mrg_create(void); |
| 44 | MRG *mrg_create_for_unittest(void); |
| 45 | |
| 46 | // returns the number of metrics that were freed, but were still referenced |
| 47 | size_t mrg_destroy(MRG *mrg); |
| 48 | |
| 49 | METRIC *mrg_metric_dup(MRG *mrg, METRIC *metric); |
| 50 | bool mrg_metric_release(MRG *mrg, METRIC *metric); |
| 51 | |
| 52 | METRIC *mrg_metric_add_and_acquire(MRG *mrg, MRG_ENTRY entry, bool *ret); |
| 53 | METRIC *mrg_metric_get_and_acquire_by_id(MRG *mrg, UUIDMAP_ID id, Word_t section); |
| 54 | METRIC *mrg_metric_get_and_acquire_by_uuid(MRG *mrg, nd_uuid_t *uuid, Word_t section); |
| 55 | bool mrg_metric_release_and_delete(MRG *mrg, METRIC *metric); |
| 56 | |
| 57 | Word_t mrg_metric_id(MRG *mrg, METRIC *metric); |
| 58 | nd_uuid_t *mrg_metric_uuid(MRG *mrg, METRIC *metric); |
| 59 | UUIDMAP_ID mrg_metric_uuidmap_id_dup(MRG *mrg, METRIC *metric); |
| 60 | Word_t mrg_metric_section(MRG *mrg, METRIC *metric); |
| 61 | |
| 62 | bool mrg_metric_set_first_time_s(MRG *mrg, METRIC *metric, time_t first_time_s); |
| 63 | bool mrg_metric_set_first_time_s_if_bigger(MRG *mrg, METRIC *metric, time_t first_time_s); |
| 64 | time_t mrg_metric_get_first_time_s(MRG *mrg, METRIC *metric); |
| 65 | |
| 66 | bool mrg_metric_set_clean_latest_time_s(MRG *mrg, METRIC *metric, time_t latest_time_s); |
| 67 | bool mrg_metric_set_hot_latest_time_s(MRG *mrg, METRIC *metric, time_t latest_time_s); |
| 68 | time_t mrg_metric_get_latest_time_s(MRG *mrg, METRIC *metric); |
| 69 | time_t mrg_metric_get_latest_clean_time_s(MRG *mrg, METRIC *metric); |
| 70 | |
| 71 | bool mrg_metric_set_update_every(MRG *mrg, METRIC *metric, uint32_t update_every_s); |
| 72 | bool mrg_metric_set_update_every_s_if_zero(MRG *mrg, METRIC *metric, uint32_t update_every_s); |
| 73 | uint32_t mrg_metric_get_update_every_s(MRG *mrg, METRIC *metric); |
| 74 | |
| 75 | void mrg_metric_expand_retention(MRG *mrg, METRIC *metric, time_t first_time_s, time_t last_time_s, uint32_t update_every_s); |
| 76 | void mrg_metric_get_retention(MRG *mrg, METRIC *metric, time_t *first_time_s, time_t *last_time_s, uint32_t *update_every_s); |
| 77 | bool mrg_metric_has_zero_disk_retention(MRG *mrg, METRIC *metric); |
| 78 | void mrg_metric_clear_retention(MRG *mrg, METRIC *metric); |
| 79 | |
| 80 | #ifdef NETDATA_INTERNAL_CHECKS |
| 81 | bool mrg_metric_set_writer(MRG *mrg, METRIC *metric); |
| 82 | bool mrg_metric_clear_writer(MRG *mrg, METRIC *metric); |
| 83 | #endif |
| 84 | |
| 85 | void mrg_get_statistics(MRG *mrg, struct mrg_statistics *s); |
| 86 | struct aral_statistics *mrg_aral_stats(void); |
| 87 | |
| 88 | void mrg_update_metric_retention_and_granularity_by_uuid( |
| 89 | MRG *mrg, |
| 90 | Word_t section, |
| 91 | nd_uuid_t(*uuid), |
| 92 | time_t first_time_s, |
| 93 | time_t last_time_s, |
| 94 | uint32_t update_every_s, |
| 95 | time_t now_s, |
| 96 | uint64_t *journal_samples); |
| 97 | |
| 98 | bool mrg_save(MRG *mrg); |
| 99 | bool mrg_load(MRG *mrg); |
| 100 | void mrg_metric_prepopulate_cleanup(MRG *mrg); |
| 101 | |
| 102 | int mrg_retention_benchmark(void); |
| 103 | |
| 104 | #endif // DBENGINE_METRIC_H |