rrd.h 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_RRD_H
  3. #define NETDATA_RRD_H 1
  4. // forward typedefs
  5. typedef struct rrdhost RRDHOST;
  6. typedef struct rrddim RRDDIM;
  7. typedef struct rrdset RRDSET;
  8. typedef struct rrdvar RRDVAR;
  9. typedef struct rrdsetvar RRDSETVAR;
  10. typedef struct rrddimvar RRDDIMVAR;
  11. typedef struct rrdcalc RRDCALC;
  12. typedef struct rrdcalctemplate RRDCALCTEMPLATE;
  13. typedef struct alarm_entry ALARM_ENTRY;
  14. // forward declarations
  15. struct rrddim_volatile;
  16. #ifdef ENABLE_DBENGINE
  17. struct rrdeng_page_descr;
  18. struct rrdengine_instance;
  19. struct pg_cache_page_index;
  20. #endif
  21. #include "../daemon/common.h"
  22. #include "web/api/queries/query.h"
  23. #include "rrdvar.h"
  24. #include "rrdsetvar.h"
  25. #include "rrddimvar.h"
  26. #include "rrdcalc.h"
  27. #include "rrdcalctemplate.h"
  28. #define UPDATE_EVERY 1
  29. #define UPDATE_EVERY_MAX 3600
  30. #define RRD_DEFAULT_HISTORY_ENTRIES 3600
  31. #define RRD_HISTORY_ENTRIES_MAX (86400*365)
  32. extern int default_rrd_update_every;
  33. extern int default_rrd_history_entries;
  34. extern int gap_when_lost_iterations_above;
  35. extern time_t rrdset_free_obsolete_time;
  36. #define RRD_ID_LENGTH_MAX 200
  37. #define RRDSET_MAGIC "NETDATA RRD SET FILE V019"
  38. #define RRDDIMENSION_MAGIC "NETDATA RRD DIMENSION FILE V019"
  39. typedef long long total_number;
  40. #define TOTAL_NUMBER_FORMAT "%lld"
  41. // ----------------------------------------------------------------------------
  42. // chart types
  43. typedef enum rrdset_type {
  44. RRDSET_TYPE_LINE = 0,
  45. RRDSET_TYPE_AREA = 1,
  46. RRDSET_TYPE_STACKED = 2
  47. } RRDSET_TYPE;
  48. #define RRDSET_TYPE_LINE_NAME "line"
  49. #define RRDSET_TYPE_AREA_NAME "area"
  50. #define RRDSET_TYPE_STACKED_NAME "stacked"
  51. RRDSET_TYPE rrdset_type_id(const char *name);
  52. const char *rrdset_type_name(RRDSET_TYPE chart_type);
  53. // ----------------------------------------------------------------------------
  54. // memory mode
  55. typedef enum rrd_memory_mode {
  56. RRD_MEMORY_MODE_NONE = 0,
  57. RRD_MEMORY_MODE_RAM = 1,
  58. RRD_MEMORY_MODE_MAP = 2,
  59. RRD_MEMORY_MODE_SAVE = 3,
  60. RRD_MEMORY_MODE_ALLOC = 4,
  61. RRD_MEMORY_MODE_DBENGINE = 5
  62. } RRD_MEMORY_MODE;
  63. #define RRD_MEMORY_MODE_NONE_NAME "none"
  64. #define RRD_MEMORY_MODE_RAM_NAME "ram"
  65. #define RRD_MEMORY_MODE_MAP_NAME "map"
  66. #define RRD_MEMORY_MODE_SAVE_NAME "save"
  67. #define RRD_MEMORY_MODE_ALLOC_NAME "alloc"
  68. #define RRD_MEMORY_MODE_DBENGINE_NAME "dbengine"
  69. extern RRD_MEMORY_MODE default_rrd_memory_mode;
  70. extern const char *rrd_memory_mode_name(RRD_MEMORY_MODE id);
  71. extern RRD_MEMORY_MODE rrd_memory_mode_id(const char *name);
  72. // ----------------------------------------------------------------------------
  73. // algorithms types
  74. typedef enum rrd_algorithm {
  75. RRD_ALGORITHM_ABSOLUTE = 0,
  76. RRD_ALGORITHM_INCREMENTAL = 1,
  77. RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL = 2,
  78. RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL = 3
  79. } RRD_ALGORITHM;
  80. #define RRD_ALGORITHM_ABSOLUTE_NAME "absolute"
  81. #define RRD_ALGORITHM_INCREMENTAL_NAME "incremental"
  82. #define RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL_NAME "percentage-of-incremental-row"
  83. #define RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL_NAME "percentage-of-absolute-row"
  84. extern RRD_ALGORITHM rrd_algorithm_id(const char *name);
  85. extern const char *rrd_algorithm_name(RRD_ALGORITHM algorithm);
  86. // ----------------------------------------------------------------------------
  87. // RRD FAMILY
  88. struct rrdfamily {
  89. avl avl;
  90. const char *family;
  91. uint32_t hash_family;
  92. size_t use_count;
  93. avl_tree_lock rrdvar_root_index;
  94. };
  95. typedef struct rrdfamily RRDFAMILY;
  96. // ----------------------------------------------------------------------------
  97. // flags
  98. // use this for configuration flags, not for state control
  99. // flags are set/unset in a manner that is not thread safe
  100. // and may lead to missing information.
  101. typedef enum rrddim_flags {
  102. RRDDIM_FLAG_NONE = 0,
  103. RRDDIM_FLAG_HIDDEN = (1 << 0), // this dimension will not be offered to callers
  104. RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS = (1 << 1), // do not offer RESET or OVERFLOW info to callers
  105. RRDDIM_FLAG_OBSOLETE = (1 << 2) // this is marked by the collector/module as obsolete
  106. } RRDDIM_FLAGS;
  107. #ifdef HAVE_C___ATOMIC
  108. #define rrddim_flag_check(rd, flag) (__atomic_load_n(&((rd)->flags), __ATOMIC_SEQ_CST) & (flag))
  109. #define rrddim_flag_set(rd, flag) __atomic_or_fetch(&((rd)->flags), (flag), __ATOMIC_SEQ_CST)
  110. #define rrddim_flag_clear(rd, flag) __atomic_and_fetch(&((rd)->flags), ~(flag), __ATOMIC_SEQ_CST)
  111. #else
  112. #define rrddim_flag_check(rd, flag) ((rd)->flags & (flag))
  113. #define rrddim_flag_set(rd, flag) (rd)->flags |= (flag)
  114. #define rrddim_flag_clear(rd, flag) (rd)->flags &= ~(flag)
  115. #endif
  116. // ----------------------------------------------------------------------------
  117. // RRD DIMENSION - this is a metric
  118. struct rrddim {
  119. // ------------------------------------------------------------------------
  120. // binary indexing structures
  121. avl avl; // the binary index - this has to be first member!
  122. // ------------------------------------------------------------------------
  123. // the dimension definition
  124. const char *id; // the id of this dimension (for internal identification)
  125. const char *name; // the name of this dimension (as presented to user)
  126. // this is a pointer to the config structure
  127. // since the config always has a higher priority
  128. // (the user overwrites the name of the charts)
  129. // DO NOT FREE THIS - IT IS ALLOCATED IN CONFIG
  130. RRD_ALGORITHM algorithm; // the algorithm that is applied to add new collected values
  131. RRD_MEMORY_MODE rrd_memory_mode; // the memory mode for this dimension
  132. collected_number multiplier; // the multiplier of the collected values
  133. collected_number divisor; // the divider of the collected values
  134. uint32_t flags; // configuration flags for the dimension
  135. // ------------------------------------------------------------------------
  136. // members for temporary data we need for calculations
  137. uint32_t hash; // a simple hash of the id, to speed up searching / indexing
  138. // instead of strcmp() every item in the binary index
  139. // we first compare the hashes
  140. uint32_t hash_name; // a simple hash of the name
  141. char *cache_filename; // the filename we load/save from/to this set
  142. size_t collections_counter; // the number of times we added values to this rrdim
  143. struct rrddim_volatile *state; // volatile state that is not persistently stored
  144. size_t unused[8];
  145. collected_number collected_value_max; // the absolute maximum of the collected value
  146. unsigned int updated:1; // 1 when the dimension has been updated since the last processing
  147. unsigned int exposed:1; // 1 when set what have sent this dimension to the central netdata
  148. struct timeval last_collected_time; // when was this dimension last updated
  149. // this is actual date time we updated the last_collected_value
  150. // THIS IS DIFFERENT FROM THE SAME MEMBER OF RRDSET
  151. calculated_number calculated_value; // the current calculated value, after applying the algorithm - resets to zero after being used
  152. calculated_number last_calculated_value; // the last calculated value processed
  153. calculated_number last_stored_value; // the last value as stored in the database (after interpolation)
  154. collected_number collected_value; // the current value, as collected - resets to 0 after being used
  155. collected_number last_collected_value; // the last value that was collected, after being processed
  156. // the *_volume members are used to calculate the accuracy of the rounding done by the
  157. // storage number - they are printed to debug.log when debug is enabled for a set.
  158. calculated_number collected_volume; // the sum of all collected values so far
  159. calculated_number stored_volume; // the sum of all stored values so far
  160. struct rrddim *next; // linking of dimensions within the same data set
  161. struct rrdset *rrdset;
  162. // ------------------------------------------------------------------------
  163. // members for checking the data when loading from disk
  164. long entries; // how many entries this dimension has in ram
  165. // this is the same to the entries of the data set
  166. // we set it here, to check the data when we load it from disk.
  167. int update_every; // every how many seconds is this updated
  168. size_t memsize; // the memory allocated for this dimension
  169. char magic[sizeof(RRDDIMENSION_MAGIC) + 1]; // a string to be saved, used to identify our data file
  170. struct rrddimvar *variables;
  171. // ------------------------------------------------------------------------
  172. // the values stored in this dimension, using our floating point numbers
  173. storage_number values[]; // the array of values - THIS HAS TO BE THE LAST MEMBER
  174. };
  175. // ----------------------------------------------------------------------------
  176. // iterator state for RRD dimension data collection
  177. union rrddim_collect_handle {
  178. struct {
  179. long slot;
  180. long entries;
  181. } slotted; // state the legacy code uses
  182. #ifdef ENABLE_DBENGINE
  183. struct rrdeng_collect_handle {
  184. struct rrdeng_page_descr *descr, *prev_descr;
  185. unsigned long page_correlation_id;
  186. struct rrdengine_instance *ctx;
  187. struct pg_cache_page_index *page_index;
  188. // set to 1 when this dimension is not page aligned with the other dimensions in the chart
  189. uint8_t unaligned_page;
  190. } rrdeng; // state the database engine uses
  191. #endif
  192. };
  193. // ----------------------------------------------------------------------------
  194. // iterator state for RRD dimension data queries
  195. struct rrddim_query_handle {
  196. RRDDIM *rd;
  197. time_t start_time;
  198. time_t end_time;
  199. union {
  200. struct {
  201. long slot;
  202. long last_slot;
  203. uint8_t finished;
  204. } slotted; // state the legacy code uses
  205. #ifdef ENABLE_DBENGINE
  206. struct rrdeng_query_handle {
  207. struct rrdeng_page_descr *descr;
  208. struct rrdengine_instance *ctx;
  209. struct pg_cache_page_index *page_index;
  210. time_t next_page_time;
  211. time_t now;
  212. unsigned position;
  213. } rrdeng; // state the database engine uses
  214. #endif
  215. };
  216. };
  217. // ----------------------------------------------------------------------------
  218. // volatile state per RRD dimension
  219. struct rrddim_volatile {
  220. #ifdef ENABLE_DBENGINE
  221. uuid_t *rrdeng_uuid; // database engine metric UUID
  222. #endif
  223. union rrddim_collect_handle handle;
  224. // ------------------------------------------------------------------------
  225. // function pointers that handle data collection
  226. struct rrddim_collect_ops {
  227. // an initialization function to run before starting collection
  228. void (*init)(RRDDIM *rd);
  229. // run this to store each metric into the database
  230. void (*store_metric)(RRDDIM *rd, usec_t point_in_time, storage_number number);
  231. // an finalization function to run after collection is over
  232. void (*finalize)(RRDDIM *rd);
  233. } collect_ops;
  234. // function pointers that handle database queries
  235. struct rrddim_query_ops {
  236. // run this before starting a series of next_metric() database queries
  237. void (*init)(RRDDIM *rd, struct rrddim_query_handle *handle, time_t start_time, time_t end_time);
  238. // run this to load each metric number from the database
  239. storage_number (*next_metric)(struct rrddim_query_handle *handle, time_t *current_time);
  240. // run this to test if the series of next_metric() database queries is finished
  241. int (*is_finished)(struct rrddim_query_handle *handle);
  242. // run this after finishing a series of load_metric() database queries
  243. void (*finalize)(struct rrddim_query_handle *handle);
  244. // get the timestamp of the last entry of this metric
  245. time_t (*latest_time)(RRDDIM *rd);
  246. // get the timestamp of the first entry of this metric
  247. time_t (*oldest_time)(RRDDIM *rd);
  248. } query_ops;
  249. };
  250. // ----------------------------------------------------------------------------
  251. // these loop macros make sure the linked list is accessed with the right lock
  252. #define rrddim_foreach_read(rd, st) \
  253. for((rd) = (st)->dimensions, rrdset_check_rdlock(st); (rd) ; (rd) = (rd)->next)
  254. #define rrddim_foreach_write(rd, st) \
  255. for((rd) = (st)->dimensions, rrdset_check_wrlock(st); (rd) ; (rd) = (rd)->next)
  256. // ----------------------------------------------------------------------------
  257. // RRDSET - this is a chart
  258. // use this for configuration flags, not for state control
  259. // flags are set/unset in a manner that is not thread safe
  260. // and may lead to missing information.
  261. typedef enum rrdset_flags {
  262. RRDSET_FLAG_ENABLED = 1 << 0, // enables or disables a chart
  263. RRDSET_FLAG_DETAIL = 1 << 1, // if set, the data set should be considered as a detail of another
  264. // (the master data set should be the one that has the same family and is not detail)
  265. RRDSET_FLAG_DEBUG = 1 << 2, // enables or disables debugging for a chart
  266. RRDSET_FLAG_OBSOLETE = 1 << 3, // this is marked by the collector/module as obsolete
  267. RRDSET_FLAG_BACKEND_SEND = 1 << 4, // if set, this chart should be sent to backends
  268. RRDSET_FLAG_BACKEND_IGNORE = 1 << 5, // if set, this chart should not be sent to backends
  269. RRDSET_FLAG_UPSTREAM_SEND = 1 << 6, // if set, this chart should be sent upstream (streaming)
  270. RRDSET_FLAG_UPSTREAM_IGNORE = 1 << 7, // if set, this chart should not be sent upstream (streaming)
  271. RRDSET_FLAG_UPSTREAM_EXPOSED = 1 << 8, // if set, we have sent this chart definition to netdata master (streaming)
  272. RRDSET_FLAG_STORE_FIRST = 1 << 9, // if set, do not eliminate the first collection during interpolation
  273. RRDSET_FLAG_HETEROGENEOUS = 1 << 10, // if set, the chart is not homogeneous (dimensions in it have multiple algorithms, multipliers or dividers)
  274. RRDSET_FLAG_HOMOGENEOUS_CHECK = 1 << 11, // if set, the chart should be checked to determine if the dimensions are homogeneous
  275. RRDSET_FLAG_HIDDEN = 1 << 12, // if set, do not show this chart on the dashboard, but use it for backends
  276. RRDSET_FLAG_SYNC_CLOCK = 1 << 13, // if set, microseconds on next data collection will be ignored (the chart will be synced to now)
  277. RRDSET_FLAG_OBSOLETE_DIMENSIONS = 1 << 14 // this is marked by the collector/module when a chart has obsolete dimensions
  278. } RRDSET_FLAGS;
  279. #ifdef HAVE_C___ATOMIC
  280. #define rrdset_flag_check(st, flag) (__atomic_load_n(&((st)->flags), __ATOMIC_SEQ_CST) & (flag))
  281. #define rrdset_flag_set(st, flag) __atomic_or_fetch(&((st)->flags), flag, __ATOMIC_SEQ_CST)
  282. #define rrdset_flag_clear(st, flag) __atomic_and_fetch(&((st)->flags), ~flag, __ATOMIC_SEQ_CST)
  283. #else
  284. #define rrdset_flag_check(st, flag) ((st)->flags & (flag))
  285. #define rrdset_flag_set(st, flag) (st)->flags |= (flag)
  286. #define rrdset_flag_clear(st, flag) (st)->flags &= ~(flag)
  287. #endif
  288. #define rrdset_flag_check_noatomic(st, flag) ((st)->flags & (flag))
  289. struct rrdset {
  290. // ------------------------------------------------------------------------
  291. // binary indexing structures
  292. avl avl; // the index, with key the id - this has to be first!
  293. avl avlname; // the index, with key the name
  294. // ------------------------------------------------------------------------
  295. // the set configuration
  296. char id[RRD_ID_LENGTH_MAX + 1]; // id of the data set
  297. const char *name; // the name of this dimension (as presented to user)
  298. // this is a pointer to the config structure
  299. // since the config always has a higher priority
  300. // (the user overwrites the name of the charts)
  301. char *config_section; // the config section for the chart
  302. char *type; // the type of graph RRD_TYPE_* (a category, for determining graphing options)
  303. char *family; // grouping sets under the same family
  304. char *title; // title shown to user
  305. char *units; // units of measurement
  306. char *context; // the template of this data set
  307. uint32_t hash_context; // the hash of the chart's context
  308. RRDSET_TYPE chart_type; // line, area, stacked
  309. int update_every; // every how many seconds is this updated?
  310. long entries; // total number of entries in the data set
  311. long current_entry; // the entry that is currently being updated
  312. // it goes around in a round-robin fashion
  313. RRDSET_FLAGS flags; // configuration flags
  314. int gap_when_lost_iterations_above; // after how many lost iterations a gap should be stored
  315. // netdata will interpolate values for gaps lower than this
  316. long priority; // the sorting priority of this chart
  317. // ------------------------------------------------------------------------
  318. // members for temporary data we need for calculations
  319. RRD_MEMORY_MODE rrd_memory_mode; // if set to 1, this is memory mapped
  320. char *cache_dir; // the directory to store dimensions
  321. char cache_filename[FILENAME_MAX+1]; // the filename to store this set
  322. netdata_rwlock_t rrdset_rwlock; // protects dimensions linked list
  323. size_t counter; // the number of times we added values to this database
  324. size_t counter_done; // the number of times rrdset_done() has been called
  325. time_t last_accessed_time; // the last time this RRDSET has been accessed
  326. time_t upstream_resync_time; // the timestamp up to which we should resync clock upstream
  327. char *plugin_name; // the name of the plugin that generated this
  328. char *module_name; // the name of the plugin module that generated this
  329. size_t unused[5];
  330. size_t rrddim_page_alignment; // keeps metric pages in alignment when using dbengine
  331. uint32_t hash; // a simple hash on the id, to speed up searching
  332. // we first compare hashes, and only if the hashes are equal we do string comparisons
  333. uint32_t hash_name; // a simple hash on the name
  334. usec_t usec_since_last_update; // the time in microseconds since the last collection of data
  335. struct timeval last_updated; // when this data set was last updated (updated every time the rrd_stats_done() function)
  336. struct timeval last_collected_time; // when did this data set last collected values
  337. total_number collected_total; // used internally to calculate percentages
  338. total_number last_collected_total; // used internally to calculate percentages
  339. RRDFAMILY *rrdfamily; // pointer to RRDFAMILY this chart belongs to
  340. RRDHOST *rrdhost; // pointer to RRDHOST this chart belongs to
  341. struct rrdset *next; // linking of rrdsets
  342. // ------------------------------------------------------------------------
  343. // local variables
  344. calculated_number green; // green threshold for this chart
  345. calculated_number red; // red threshold for this chart
  346. avl_tree_lock rrdvar_root_index; // RRDVAR index for this chart
  347. RRDSETVAR *variables; // RRDSETVAR linked list for this chart (one RRDSETVAR, many RRDVARs)
  348. RRDCALC *alarms; // RRDCALC linked list for this chart
  349. // ------------------------------------------------------------------------
  350. // members for checking the data when loading from disk
  351. unsigned long memsize; // how much mem we have allocated for this (without dimensions)
  352. char magic[sizeof(RRDSET_MAGIC) + 1]; // our magic
  353. // ------------------------------------------------------------------------
  354. // the dimensions
  355. avl_tree_lock dimensions_index; // the root of the dimensions index
  356. RRDDIM *dimensions; // the actual data for every dimension
  357. };
  358. #define rrdset_rdlock(st) netdata_rwlock_rdlock(&((st)->rrdset_rwlock))
  359. #define rrdset_wrlock(st) netdata_rwlock_wrlock(&((st)->rrdset_rwlock))
  360. #define rrdset_unlock(st) netdata_rwlock_unlock(&((st)->rrdset_rwlock))
  361. // ----------------------------------------------------------------------------
  362. // these loop macros make sure the linked list is accessed with the right lock
  363. #define rrdset_foreach_read(st, host) \
  364. for((st) = (host)->rrdset_root, rrdhost_check_rdlock(host); st ; (st) = (st)->next)
  365. #define rrdset_foreach_write(st, host) \
  366. for((st) = (host)->rrdset_root, rrdhost_check_wrlock(host); st ; (st) = (st)->next)
  367. // ----------------------------------------------------------------------------
  368. // RRDHOST flags
  369. // use this for configuration flags, not for state control
  370. // flags are set/unset in a manner that is not thread safe
  371. // and may lead to missing information.
  372. typedef enum rrdhost_flags {
  373. RRDHOST_FLAG_ORPHAN = 1 << 0, // this host is orphan (not receiving data)
  374. RRDHOST_FLAG_DELETE_OBSOLETE_CHARTS = 1 << 1, // delete files of obsolete charts
  375. RRDHOST_FLAG_DELETE_ORPHAN_HOST = 1 << 2, // delete the entire host when orphan
  376. RRDHOST_FLAG_BACKEND_SEND = 1 << 3, // send it to backends
  377. RRDHOST_FLAG_BACKEND_DONT_SEND = 1 << 4, // don't send it to backends
  378. } RRDHOST_FLAGS;
  379. #ifdef HAVE_C___ATOMIC
  380. #define rrdhost_flag_check(host, flag) (__atomic_load_n(&((host)->flags), __ATOMIC_SEQ_CST) & (flag))
  381. #define rrdhost_flag_set(host, flag) __atomic_or_fetch(&((host)->flags), flag, __ATOMIC_SEQ_CST)
  382. #define rrdhost_flag_clear(host, flag) __atomic_and_fetch(&((host)->flags), ~flag, __ATOMIC_SEQ_CST)
  383. #else
  384. #define rrdhost_flag_check(host, flag) ((host)->flags & (flag))
  385. #define rrdhost_flag_set(host, flag) (host)->flags |= (flag)
  386. #define rrdhost_flag_clear(host, flag) (host)->flags &= ~(flag)
  387. #endif
  388. #ifdef NETDATA_INTERNAL_CHECKS
  389. #define rrdset_debug(st, fmt, args...) do { if(unlikely(debug_flags & D_RRD_STATS && rrdset_flag_check(st, RRDSET_FLAG_DEBUG))) \
  390. debug_int(__FILE__, __FUNCTION__, __LINE__, "%s: " fmt, st->name, ##args); } while(0)
  391. #else
  392. #define rrdset_debug(st, fmt, args...) debug_dummy()
  393. #endif
  394. // ----------------------------------------------------------------------------
  395. // Health data
  396. struct alarm_entry {
  397. uint32_t unique_id;
  398. uint32_t alarm_id;
  399. uint32_t alarm_event_id;
  400. time_t when;
  401. time_t duration;
  402. time_t non_clear_duration;
  403. char *name;
  404. uint32_t hash_name;
  405. char *chart;
  406. uint32_t hash_chart;
  407. char *family;
  408. char *exec;
  409. char *recipient;
  410. time_t exec_run_timestamp;
  411. int exec_code;
  412. char *source;
  413. char *units;
  414. char *info;
  415. calculated_number old_value;
  416. calculated_number new_value;
  417. char *old_value_string;
  418. char *new_value_string;
  419. RRDCALC_STATUS old_status;
  420. RRDCALC_STATUS new_status;
  421. uint32_t flags;
  422. int delay;
  423. time_t delay_up_to_timestamp;
  424. uint32_t updated_by_id;
  425. uint32_t updates_id;
  426. time_t last_repeat;
  427. struct alarm_entry *next;
  428. };
  429. typedef struct alarm_log {
  430. uint32_t next_log_id;
  431. uint32_t next_alarm_id;
  432. unsigned int count;
  433. unsigned int max;
  434. ALARM_ENTRY *alarms;
  435. netdata_rwlock_t alarm_log_rwlock;
  436. } ALARM_LOG;
  437. // ----------------------------------------------------------------------------
  438. // RRD HOST
  439. struct rrdhost_system_info {
  440. char *os_name;
  441. char *os_id;
  442. char *os_id_like;
  443. char *os_version;
  444. char *os_version_id;
  445. char *os_detection;
  446. char *kernel_name;
  447. char *kernel_version;
  448. char *architecture;
  449. char *virtualization;
  450. char *virt_detection;
  451. char *container;
  452. char *container_detection;
  453. };
  454. struct rrdhost {
  455. avl avl; // the index of hosts
  456. // ------------------------------------------------------------------------
  457. // host information
  458. char *hostname; // the hostname of this host
  459. uint32_t hash_hostname; // the hostname hash
  460. char *registry_hostname; // the registry hostname for this host
  461. char machine_guid[GUID_LEN + 1]; // the unique ID of this host
  462. uint32_t hash_machine_guid; // the hash of the unique ID
  463. const char *os; // the O/S type of the host
  464. const char *tags; // tags for this host
  465. const char *timezone; // the timezone of the host
  466. RRDHOST_FLAGS flags; // flags about this RRDHOST
  467. int rrd_update_every; // the update frequency of the host
  468. long rrd_history_entries; // the number of history entries for the host's charts
  469. #ifdef ENABLE_DBENGINE
  470. unsigned page_cache_mb; // Database Engine page cache size in MiB
  471. unsigned disk_space_mb; // Database Engine disk space quota in MiB
  472. #endif
  473. RRD_MEMORY_MODE rrd_memory_mode; // the memory more for the charts of this host
  474. char *cache_dir; // the directory to save RRD cache files
  475. char *varlib_dir; // the directory to save health log
  476. char *program_name; // the program name that collects metrics for this host
  477. char *program_version; // the program version that collects metrics for this host
  478. struct rrdhost_system_info *system_info; // information collected from the host environment
  479. // ------------------------------------------------------------------------
  480. // streaming of data to remote hosts - rrdpush
  481. unsigned int rrdpush_send_enabled:1; // 1 when this host sends metrics to another netdata
  482. char *rrdpush_send_destination; // where to send metrics to
  483. char *rrdpush_send_api_key; // the api key at the receiving netdata
  484. // the following are state information for the threading
  485. // streaming metrics from this netdata to an upstream netdata
  486. volatile unsigned int rrdpush_sender_spawn:1; // 1 when the sender thread has been spawn
  487. netdata_thread_t rrdpush_sender_thread; // the sender thread
  488. volatile unsigned int rrdpush_sender_connected:1; // 1 when the sender is ready to push metrics
  489. int rrdpush_sender_socket; // the fd of the socket to the remote host, or -1
  490. volatile unsigned int rrdpush_sender_error_shown:1; // 1 when we have logged a communication error
  491. volatile unsigned int rrdpush_sender_join:1; // 1 when we have to join the sending thread
  492. SIMPLE_PATTERN *rrdpush_send_charts_matching; // pattern to match the charts to be sent
  493. // metrics may be collected asynchronously
  494. // these synchronize all the threads willing the write to our sending buffer
  495. netdata_mutex_t rrdpush_sender_buffer_mutex; // exclusive access to rrdpush_sender_buffer
  496. int rrdpush_sender_pipe[2]; // collector to sender thread signaling
  497. BUFFER *rrdpush_sender_buffer; // collector fills it, sender sends it
  498. // ------------------------------------------------------------------------
  499. // streaming of data from remote hosts - rrdpush
  500. volatile size_t connected_senders; // when remote hosts are streaming to this
  501. // host, this is the counter of connected clients
  502. time_t senders_disconnected_time; // the time the last sender was disconnected
  503. // ------------------------------------------------------------------------
  504. // health monitoring options
  505. unsigned int health_enabled:1; // 1 when this host has health enabled
  506. time_t health_delay_up_to; // a timestamp to delay alarms processing up to
  507. char *health_default_exec; // the full path of the alarms notifications program
  508. char *health_default_recipient; // the default recipient for all alarms
  509. char *health_log_filename; // the alarms event log filename
  510. size_t health_log_entries_written; // the number of alarm events writtern to the alarms event log
  511. FILE *health_log_fp; // the FILE pointer to the open alarms event log file
  512. uint32_t health_default_warn_repeat_every; // the default value for the interval between repeating warning notifications
  513. uint32_t health_default_crit_repeat_every; // the default value for the interval between repeating critical notifications
  514. // all RRDCALCs are primarily allocated and linked here
  515. // RRDCALCs may be linked to charts at any point
  516. // (charts may or may not exist when these are loaded)
  517. RRDCALC *alarms;
  518. RRDCALC *alarms_with_foreach;
  519. avl_tree_lock alarms_idx_health_log;
  520. avl_tree_lock alarms_idx_name;
  521. ALARM_LOG health_log; // alarms historical events (event log)
  522. uint32_t health_last_processed_id; // the last processed health id from the log
  523. uint32_t health_max_unique_id; // the max alarm log unique id given for the host
  524. uint32_t health_max_alarm_id; // the max alarm id given for the host
  525. // templates of alarms
  526. // these are used to create alarms when charts
  527. // are created or renamed, that match them
  528. RRDCALCTEMPLATE *templates;
  529. RRDCALCTEMPLATE *alarms_template_with_foreach;
  530. // ------------------------------------------------------------------------
  531. // the charts of the host
  532. RRDSET *rrdset_root; // the host charts
  533. // ------------------------------------------------------------------------
  534. // locks
  535. netdata_rwlock_t rrdhost_rwlock; // lock for this RRDHOST (protects rrdset_root linked list)
  536. // ------------------------------------------------------------------------
  537. // indexes
  538. avl_tree_lock rrdset_root_index; // the host's charts index (by id)
  539. avl_tree_lock rrdset_root_index_name; // the host's charts index (by name)
  540. avl_tree_lock rrdfamily_root_index; // the host's chart families index
  541. avl_tree_lock rrdvar_root_index; // the host's chart variables index
  542. #ifdef ENABLE_DBENGINE
  543. struct rrdengine_instance *rrdeng_ctx; // DB engine instance for this host
  544. #endif
  545. #ifdef ENABLE_HTTPS
  546. struct netdata_ssl ssl; //Structure used to encrypt the connection
  547. struct netdata_ssl stream_ssl; //Structure used to encrypt the stream
  548. #endif
  549. struct rrdhost *next;
  550. };
  551. extern RRDHOST *localhost;
  552. #define rrdhost_rdlock(host) netdata_rwlock_rdlock(&((host)->rrdhost_rwlock))
  553. #define rrdhost_wrlock(host) netdata_rwlock_wrlock(&((host)->rrdhost_rwlock))
  554. #define rrdhost_unlock(host) netdata_rwlock_unlock(&((host)->rrdhost_rwlock))
  555. // ----------------------------------------------------------------------------
  556. // these loop macros make sure the linked list is accessed with the right lock
  557. #define rrdhost_foreach_read(var) \
  558. for((var) = localhost, rrd_check_rdlock(); var ; (var) = (var)->next)
  559. #define rrdhost_foreach_write(var) \
  560. for((var) = localhost, rrd_check_wrlock(); var ; (var) = (var)->next)
  561. // ----------------------------------------------------------------------------
  562. // global lock for all RRDHOSTs
  563. extern netdata_rwlock_t rrd_rwlock;
  564. #define rrd_rdlock() netdata_rwlock_rdlock(&rrd_rwlock)
  565. #define rrd_wrlock() netdata_rwlock_wrlock(&rrd_rwlock)
  566. #define rrd_unlock() netdata_rwlock_unlock(&rrd_rwlock)
  567. // ----------------------------------------------------------------------------
  568. extern size_t rrd_hosts_available;
  569. extern time_t rrdhost_free_orphan_time;
  570. extern void rrd_init(char *hostname, struct rrdhost_system_info *system_info);
  571. extern RRDHOST *rrdhost_find_by_hostname(const char *hostname, uint32_t hash);
  572. extern RRDHOST *rrdhost_find_by_guid(const char *guid, uint32_t hash);
  573. extern RRDHOST *rrdhost_find_or_create(
  574. const char *hostname
  575. , const char *registry_hostname
  576. , const char *guid
  577. , const char *os
  578. , const char *timezone
  579. , const char *tags
  580. , const char *program_name
  581. , const char *program_version
  582. , int update_every
  583. , long history
  584. , RRD_MEMORY_MODE mode
  585. , unsigned int health_enabled
  586. , unsigned int rrdpush_enabled
  587. , char *rrdpush_destination
  588. , char *rrdpush_api_key
  589. , char *rrdpush_send_charts_matching
  590. , struct rrdhost_system_info *system_info
  591. );
  592. extern int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, char *name, char *value);
  593. #if defined(NETDATA_INTERNAL_CHECKS) && defined(NETDATA_VERIFY_LOCKS)
  594. extern void __rrdhost_check_wrlock(RRDHOST *host, const char *file, const char *function, const unsigned long line);
  595. extern void __rrdhost_check_rdlock(RRDHOST *host, const char *file, const char *function, const unsigned long line);
  596. extern void __rrdset_check_rdlock(RRDSET *st, const char *file, const char *function, const unsigned long line);
  597. extern void __rrdset_check_wrlock(RRDSET *st, const char *file, const char *function, const unsigned long line);
  598. extern void __rrd_check_rdlock(const char *file, const char *function, const unsigned long line);
  599. extern void __rrd_check_wrlock(const char *file, const char *function, const unsigned long line);
  600. #define rrdhost_check_rdlock(host) __rrdhost_check_rdlock(host, __FILE__, __FUNCTION__, __LINE__)
  601. #define rrdhost_check_wrlock(host) __rrdhost_check_wrlock(host, __FILE__, __FUNCTION__, __LINE__)
  602. #define rrdset_check_rdlock(st) __rrdset_check_rdlock(st, __FILE__, __FUNCTION__, __LINE__)
  603. #define rrdset_check_wrlock(st) __rrdset_check_wrlock(st, __FILE__, __FUNCTION__, __LINE__)
  604. #define rrd_check_rdlock() __rrd_check_rdlock(__FILE__, __FUNCTION__, __LINE__)
  605. #define rrd_check_wrlock() __rrd_check_wrlock(__FILE__, __FUNCTION__, __LINE__)
  606. #else
  607. #define rrdhost_check_rdlock(host) (void)0
  608. #define rrdhost_check_wrlock(host) (void)0
  609. #define rrdset_check_rdlock(st) (void)0
  610. #define rrdset_check_wrlock(st) (void)0
  611. #define rrd_check_rdlock() (void)0
  612. #define rrd_check_wrlock() (void)0
  613. #endif
  614. // ----------------------------------------------------------------------------
  615. // RRDSET functions
  616. extern int rrdset_set_name(RRDSET *st, const char *name);
  617. extern RRDSET *rrdset_create_custom(RRDHOST *host
  618. , const char *type
  619. , const char *id
  620. , const char *name
  621. , const char *family
  622. , const char *context
  623. , const char *title
  624. , const char *units
  625. , const char *plugin
  626. , const char *module
  627. , long priority
  628. , int update_every
  629. , RRDSET_TYPE chart_type
  630. , RRD_MEMORY_MODE memory_mode
  631. , long history_entries);
  632. #define rrdset_create(host, type, id, name, family, context, title, units, plugin, module, priority, update_every, chart_type) \
  633. rrdset_create_custom(host, type, id, name, family, context, title, units, plugin, module, priority, update_every, chart_type, (host)->rrd_memory_mode, (host)->rrd_history_entries)
  634. #define rrdset_create_localhost(type, id, name, family, context, title, units, plugin, module, priority, update_every, chart_type) \
  635. rrdset_create(localhost, type, id, name, family, context, title, units, plugin, module, priority, update_every, chart_type)
  636. extern void rrdhost_free_all(void);
  637. extern void rrdhost_save_all(void);
  638. extern void rrdhost_cleanup_all(void);
  639. extern void rrdhost_cleanup_orphan_hosts_nolock(RRDHOST *protected);
  640. extern void rrdhost_system_info_free(struct rrdhost_system_info *system_info);
  641. extern void rrdhost_free(RRDHOST *host);
  642. extern void rrdhost_save_charts(RRDHOST *host);
  643. extern void rrdhost_delete_charts(RRDHOST *host);
  644. extern int rrdhost_should_be_removed(RRDHOST *host, RRDHOST *protected, time_t now);
  645. extern void rrdset_update_heterogeneous_flag(RRDSET *st);
  646. extern RRDSET *rrdset_find(RRDHOST *host, const char *id);
  647. #define rrdset_find_localhost(id) rrdset_find(localhost, id)
  648. extern RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *id);
  649. #define rrdset_find_bytype_localhost(type, id) rrdset_find_bytype(localhost, type, id)
  650. extern RRDSET *rrdset_find_byname(RRDHOST *host, const char *name);
  651. #define rrdset_find_byname_localhost(name) rrdset_find_byname(localhost, name)
  652. extern void rrdset_next_usec_unfiltered(RRDSET *st, usec_t microseconds);
  653. extern void rrdset_next_usec(RRDSET *st, usec_t microseconds);
  654. #define rrdset_next(st) rrdset_next_usec(st, 0ULL)
  655. extern void rrdset_done(RRDSET *st);
  656. extern void rrdset_is_obsolete(RRDSET *st);
  657. extern void rrdset_isnot_obsolete(RRDSET *st);
  658. // checks if the RRDSET should be offered to viewers
  659. #define rrdset_is_available_for_viewers(st) (rrdset_flag_check(st, RRDSET_FLAG_ENABLED) && !rrdset_flag_check(st, RRDSET_FLAG_HIDDEN) && !rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE) && (st)->dimensions && (st)->rrd_memory_mode != RRD_MEMORY_MODE_NONE)
  660. #define rrdset_is_available_for_backends(st) (rrdset_flag_check(st, RRDSET_FLAG_ENABLED) && !rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE) && (st)->dimensions)
  661. // get the total duration in seconds of the round robin database
  662. #define rrdset_duration(st) ((time_t)( (((st)->counter >= ((unsigned long)(st)->entries))?(unsigned long)(st)->entries:(st)->counter) * (st)->update_every ))
  663. // get the timestamp of the last entry in the round robin database
  664. static inline time_t rrdset_last_entry_t(RRDSET *st) {
  665. if (st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
  666. RRDDIM *rd;
  667. time_t last_entry_t = 0;
  668. int ret = netdata_rwlock_tryrdlock(&st->rrdset_rwlock);
  669. rrddim_foreach_read(rd, st) {
  670. last_entry_t = MAX(last_entry_t, rd->state->query_ops.latest_time(rd));
  671. }
  672. if(0 == ret) netdata_rwlock_unlock(&st->rrdset_rwlock);
  673. return last_entry_t;
  674. } else {
  675. return (time_t)st->last_updated.tv_sec;
  676. }
  677. }
  678. // get the timestamp of first entry in the round robin database
  679. static inline time_t rrdset_first_entry_t(RRDSET *st) {
  680. if (st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
  681. RRDDIM *rd;
  682. time_t first_entry_t = LONG_MAX;
  683. int ret = netdata_rwlock_tryrdlock(&st->rrdset_rwlock);
  684. rrddim_foreach_read(rd, st) {
  685. first_entry_t = MIN(first_entry_t, rd->state->query_ops.oldest_time(rd));
  686. }
  687. if(0 == ret) netdata_rwlock_unlock(&st->rrdset_rwlock);
  688. if (unlikely(LONG_MAX == first_entry_t)) return 0;
  689. return first_entry_t;
  690. } else {
  691. return (time_t)(rrdset_last_entry_t(st) - rrdset_duration(st));
  692. }
  693. }
  694. // get the last slot updated in the round robin database
  695. #define rrdset_last_slot(st) ((size_t)(((st)->current_entry == 0) ? (st)->entries - 1 : (st)->current_entry - 1))
  696. // get the first / oldest slot updated in the round robin database
  697. // #define rrdset_first_slot(st) ((size_t)( (((st)->counter >= ((unsigned long)(st)->entries)) ? (unsigned long)( ((unsigned long)(st)->current_entry > 0) ? ((unsigned long)(st)->current_entry) : ((unsigned long)(st)->entries) ) - 1 : 0) ))
  698. // return the slot that has the oldest value
  699. static inline size_t rrdset_first_slot(RRDSET *st) {
  700. if(st->counter >= (size_t)st->entries) {
  701. // the database has been rotated at least once
  702. // the oldest entry is the one that will be next
  703. // overwritten by data collection
  704. return (size_t)st->current_entry;
  705. }
  706. // we do not have rotated the db yet
  707. // so 0 is the first entry
  708. return 0;
  709. }
  710. // get the slot of the round robin database, for the given timestamp (t)
  711. // it always returns a valid slot, although may not be for the time requested if the time is outside the round robin database
  712. static inline size_t rrdset_time2slot(RRDSET *st, time_t t) {
  713. size_t ret = 0;
  714. if(t >= rrdset_last_entry_t(st)) {
  715. // the requested time is after the last entry we have
  716. ret = rrdset_last_slot(st);
  717. }
  718. else {
  719. if(t <= rrdset_first_entry_t(st)) {
  720. // the requested time is before the first entry we have
  721. ret = rrdset_first_slot(st);
  722. }
  723. else {
  724. if(rrdset_last_slot(st) >= ((rrdset_last_entry_t(st) - t) / (size_t)(st->update_every)))
  725. ret = rrdset_last_slot(st) - ((rrdset_last_entry_t(st) - t) / (size_t)(st->update_every));
  726. else
  727. ret = rrdset_last_slot(st) - ((rrdset_last_entry_t(st) - t) / (size_t)(st->update_every)) + (unsigned long)st->entries;
  728. }
  729. }
  730. if(unlikely(ret >= (size_t)st->entries)) {
  731. error("INTERNAL ERROR: rrdset_time2slot() on %s returns values outside entries", st->name);
  732. ret = (size_t)(st->entries - 1);
  733. }
  734. return ret;
  735. }
  736. // get the timestamp of a specific slot in the round robin database
  737. static inline time_t rrdset_slot2time(RRDSET *st, size_t slot) {
  738. time_t ret;
  739. if(slot >= (size_t)st->entries) {
  740. error("INTERNAL ERROR: caller of rrdset_slot2time() gives invalid slot %zu", slot);
  741. slot = (size_t)st->entries - 1;
  742. }
  743. if(slot > rrdset_last_slot(st)) {
  744. ret = rrdset_last_entry_t(st) - (size_t)st->update_every * (rrdset_last_slot(st) - slot + (size_t)st->entries);
  745. }
  746. else {
  747. ret = rrdset_last_entry_t(st) - (size_t)st->update_every;
  748. }
  749. if(unlikely(ret < rrdset_first_entry_t(st))) {
  750. error("INTERNAL ERROR: rrdset_slot2time() on %s returns time too far in the past", st->name);
  751. ret = rrdset_first_entry_t(st);
  752. }
  753. if(unlikely(ret > rrdset_last_entry_t(st))) {
  754. error("INTERNAL ERROR: rrdset_slot2time() on %s returns time into the future", st->name);
  755. ret = rrdset_last_entry_t(st);
  756. }
  757. return ret;
  758. }
  759. // ----------------------------------------------------------------------------
  760. // RRD DIMENSION functions
  761. extern void rrdcalc_link_to_rrddim(RRDDIM *rd, RRDSET *st, RRDHOST *host);
  762. extern RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collected_number multiplier, collected_number divisor, RRD_ALGORITHM algorithm, RRD_MEMORY_MODE memory_mode);
  763. #define rrddim_add(st, id, name, multiplier, divisor, algorithm) rrddim_add_custom(st, id, name, multiplier, divisor, algorithm, (st)->rrd_memory_mode)
  764. extern int rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name);
  765. extern int rrddim_set_algorithm(RRDSET *st, RRDDIM *rd, RRD_ALGORITHM algorithm);
  766. extern int rrddim_set_multiplier(RRDSET *st, RRDDIM *rd, collected_number multiplier);
  767. extern int rrddim_set_divisor(RRDSET *st, RRDDIM *rd, collected_number divisor);
  768. extern RRDDIM *rrddim_find(RRDSET *st, const char *id);
  769. extern int rrddim_hide(RRDSET *st, const char *id);
  770. extern int rrddim_unhide(RRDSET *st, const char *id);
  771. extern void rrddim_is_obsolete(RRDSET *st, RRDDIM *rd);
  772. extern void rrddim_isnot_obsolete(RRDSET *st, RRDDIM *rd);
  773. extern collected_number rrddim_set_by_pointer(RRDSET *st, RRDDIM *rd, collected_number value);
  774. extern collected_number rrddim_set(RRDSET *st, const char *id, collected_number value);
  775. extern long align_entries_to_pagesize(RRD_MEMORY_MODE mode, long entries);
  776. // ----------------------------------------------------------------------------
  777. // Miscellaneous functions
  778. extern int alarm_compare_id(void *a, void *b);
  779. extern int alarm_compare_name(void *a, void *b);
  780. // ----------------------------------------------------------------------------
  781. // RRD internal functions
  782. #ifdef NETDATA_RRD_INTERNALS
  783. extern avl_tree_lock rrdhost_root_index;
  784. extern char *rrdset_strncpyz_name(char *to, const char *from, size_t length);
  785. extern char *rrdset_cache_dir(RRDHOST *host, const char *id, const char *config_section);
  786. extern void rrddim_free(RRDSET *st, RRDDIM *rd);
  787. extern int rrddim_compare(void* a, void* b);
  788. extern int rrdset_compare(void* a, void* b);
  789. extern int rrdset_compare_name(void* a, void* b);
  790. extern int rrdfamily_compare(void *a, void *b);
  791. extern RRDFAMILY *rrdfamily_create(RRDHOST *host, const char *id);
  792. extern void rrdfamily_free(RRDHOST *host, RRDFAMILY *rc);
  793. #define rrdset_index_add(host, st) (RRDSET *)avl_insert_lock(&((host)->rrdset_root_index), (avl *)(st))
  794. #define rrdset_index_del(host, st) (RRDSET *)avl_remove_lock(&((host)->rrdset_root_index), (avl *)(st))
  795. extern RRDSET *rrdset_index_del_name(RRDHOST *host, RRDSET *st);
  796. extern void rrdset_free(RRDSET *st);
  797. extern void rrdset_reset(RRDSET *st);
  798. extern void rrdset_save(RRDSET *st);
  799. extern void rrdset_delete(RRDSET *st);
  800. extern void rrdset_delete_obsolete_dimensions(RRDSET *st);
  801. extern void rrdhost_cleanup_obsolete_charts(RRDHOST *host);
  802. #endif /* NETDATA_RRD_INTERNALS */
  803. // ----------------------------------------------------------------------------
  804. // RRD DB engine declarations
  805. #ifdef ENABLE_DBENGINE
  806. #include "database/engine/rrdengineapi.h"
  807. #endif
  808. #endif /* NETDATA_RRD_H */