rrd.h 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  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 now; //TODO: remove now to implement next point iteration
  211. time_t dt; //TODO: remove dt to implement next point iteration
  212. } rrdeng; // state the database engine uses
  213. #endif
  214. };
  215. };
  216. // ----------------------------------------------------------------------------
  217. // volatile state per RRD dimension
  218. struct rrddim_volatile {
  219. #ifdef ENABLE_DBENGINE
  220. uuid_t *rrdeng_uuid; // database engine metric UUID
  221. #endif
  222. union rrddim_collect_handle handle;
  223. // ------------------------------------------------------------------------
  224. // function pointers that handle data collection
  225. struct rrddim_collect_ops {
  226. // an initialization function to run before starting collection
  227. void (*init)(RRDDIM *rd);
  228. // run this to store each metric into the database
  229. void (*store_metric)(RRDDIM *rd, usec_t point_in_time, storage_number number);
  230. // an finalization function to run after collection is over
  231. void (*finalize)(RRDDIM *rd);
  232. } collect_ops;
  233. // function pointers that handle database queries
  234. struct rrddim_query_ops {
  235. // run this before starting a series of next_metric() database queries
  236. void (*init)(RRDDIM *rd, struct rrddim_query_handle *handle, time_t start_time, time_t end_time);
  237. // run this to load each metric number from the database
  238. storage_number (*next_metric)(struct rrddim_query_handle *handle);
  239. // run this to test if the series of next_metric() database queries is finished
  240. int (*is_finished)(struct rrddim_query_handle *handle);
  241. // run this after finishing a series of load_metric() database queries
  242. void (*finalize)(struct rrddim_query_handle *handle);
  243. // get the timestamp of the last entry of this metric
  244. time_t (*latest_time)(RRDDIM *rd);
  245. // get the timestamp of the first entry of this metric
  246. time_t (*oldest_time)(RRDDIM *rd);
  247. } query_ops;
  248. };
  249. // ----------------------------------------------------------------------------
  250. // these loop macros make sure the linked list is accessed with the right lock
  251. #define rrddim_foreach_read(rd, st) \
  252. for((rd) = (st)->dimensions, rrdset_check_rdlock(st); (rd) ; (rd) = (rd)->next)
  253. #define rrddim_foreach_write(rd, st) \
  254. for((rd) = (st)->dimensions, rrdset_check_wrlock(st); (rd) ; (rd) = (rd)->next)
  255. // ----------------------------------------------------------------------------
  256. // RRDSET - this is a chart
  257. // use this for configuration flags, not for state control
  258. // flags are set/unset in a manner that is not thread safe
  259. // and may lead to missing information.
  260. typedef enum rrdset_flags {
  261. RRDSET_FLAG_ENABLED = 1 << 0, // enables or disables a chart
  262. RRDSET_FLAG_DETAIL = 1 << 1, // if set, the data set should be considered as a detail of another
  263. // (the master data set should be the one that has the same family and is not detail)
  264. RRDSET_FLAG_DEBUG = 1 << 2, // enables or disables debugging for a chart
  265. RRDSET_FLAG_OBSOLETE = 1 << 3, // this is marked by the collector/module as obsolete
  266. RRDSET_FLAG_BACKEND_SEND = 1 << 4, // if set, this chart should be sent to backends
  267. RRDSET_FLAG_BACKEND_IGNORE = 1 << 5, // if set, this chart should not be sent to backends
  268. RRDSET_FLAG_UPSTREAM_SEND = 1 << 6, // if set, this chart should be sent upstream (streaming)
  269. RRDSET_FLAG_UPSTREAM_IGNORE = 1 << 7, // if set, this chart should not be sent upstream (streaming)
  270. RRDSET_FLAG_UPSTREAM_EXPOSED = 1 << 8, // if set, we have sent this chart definition to netdata master (streaming)
  271. RRDSET_FLAG_STORE_FIRST = 1 << 9, // if set, do not eliminate the first collection during interpolation
  272. RRDSET_FLAG_HETEROGENEOUS = 1 << 10, // if set, the chart is not homogeneous (dimensions in it have multiple algorithms, multipliers or dividers)
  273. RRDSET_FLAG_HOMOGENEOUS_CHECK = 1 << 11, // if set, the chart should be checked to determine if the dimensions are homogeneous
  274. RRDSET_FLAG_HIDDEN = 1 << 12, // if set, do not show this chart on the dashboard, but use it for backends
  275. RRDSET_FLAG_SYNC_CLOCK = 1 << 13, // if set, microseconds on next data collection will be ignored (the chart will be synced to now)
  276. RRDSET_FLAG_OBSOLETE_DIMENSIONS = 1 << 14 // this is marked by the collector/module when a chart has obsolete dimensions
  277. } RRDSET_FLAGS;
  278. #ifdef HAVE_C___ATOMIC
  279. #define rrdset_flag_check(st, flag) (__atomic_load_n(&((st)->flags), __ATOMIC_SEQ_CST) & (flag))
  280. #define rrdset_flag_set(st, flag) __atomic_or_fetch(&((st)->flags), flag, __ATOMIC_SEQ_CST)
  281. #define rrdset_flag_clear(st, flag) __atomic_and_fetch(&((st)->flags), ~flag, __ATOMIC_SEQ_CST)
  282. #else
  283. #define rrdset_flag_check(st, flag) ((st)->flags & (flag))
  284. #define rrdset_flag_set(st, flag) (st)->flags |= (flag)
  285. #define rrdset_flag_clear(st, flag) (st)->flags &= ~(flag)
  286. #endif
  287. #define rrdset_flag_check_noatomic(st, flag) ((st)->flags & (flag))
  288. struct rrdset {
  289. // ------------------------------------------------------------------------
  290. // binary indexing structures
  291. avl avl; // the index, with key the id - this has to be first!
  292. avl avlname; // the index, with key the name
  293. // ------------------------------------------------------------------------
  294. // the set configuration
  295. char id[RRD_ID_LENGTH_MAX + 1]; // id of the data set
  296. const char *name; // the name of this dimension (as presented to user)
  297. // this is a pointer to the config structure
  298. // since the config always has a higher priority
  299. // (the user overwrites the name of the charts)
  300. char *config_section; // the config section for the chart
  301. char *type; // the type of graph RRD_TYPE_* (a category, for determining graphing options)
  302. char *family; // grouping sets under the same family
  303. char *title; // title shown to user
  304. char *units; // units of measurement
  305. char *context; // the template of this data set
  306. uint32_t hash_context; // the hash of the chart's context
  307. RRDSET_TYPE chart_type; // line, area, stacked
  308. int update_every; // every how many seconds is this updated?
  309. long entries; // total number of entries in the data set
  310. long current_entry; // the entry that is currently being updated
  311. // it goes around in a round-robin fashion
  312. RRDSET_FLAGS flags; // configuration flags
  313. int gap_when_lost_iterations_above; // after how many lost iterations a gap should be stored
  314. // netdata will interpolate values for gaps lower than this
  315. long priority; // the sorting priority of this chart
  316. // ------------------------------------------------------------------------
  317. // members for temporary data we need for calculations
  318. RRD_MEMORY_MODE rrd_memory_mode; // if set to 1, this is memory mapped
  319. char *cache_dir; // the directory to store dimensions
  320. char cache_filename[FILENAME_MAX+1]; // the filename to store this set
  321. netdata_rwlock_t rrdset_rwlock; // protects dimensions linked list
  322. size_t counter; // the number of times we added values to this database
  323. size_t counter_done; // the number of times rrdset_done() has been called
  324. time_t last_accessed_time; // the last time this RRDSET has been accessed
  325. time_t upstream_resync_time; // the timestamp up to which we should resync clock upstream
  326. char *plugin_name; // the name of the plugin that generated this
  327. char *module_name; // the name of the plugin module that generated this
  328. size_t unused[5];
  329. size_t rrddim_page_alignment; // keeps metric pages in alignment when using dbengine
  330. uint32_t hash; // a simple hash on the id, to speed up searching
  331. // we first compare hashes, and only if the hashes are equal we do string comparisons
  332. uint32_t hash_name; // a simple hash on the name
  333. usec_t usec_since_last_update; // the time in microseconds since the last collection of data
  334. struct timeval last_updated; // when this data set was last updated (updated every time the rrd_stats_done() function)
  335. struct timeval last_collected_time; // when did this data set last collected values
  336. total_number collected_total; // used internally to calculate percentages
  337. total_number last_collected_total; // used internally to calculate percentages
  338. RRDFAMILY *rrdfamily; // pointer to RRDFAMILY this chart belongs to
  339. RRDHOST *rrdhost; // pointer to RRDHOST this chart belongs to
  340. struct rrdset *next; // linking of rrdsets
  341. // ------------------------------------------------------------------------
  342. // local variables
  343. calculated_number green; // green threshold for this chart
  344. calculated_number red; // red threshold for this chart
  345. avl_tree_lock rrdvar_root_index; // RRDVAR index for this chart
  346. RRDSETVAR *variables; // RRDSETVAR linked list for this chart (one RRDSETVAR, many RRDVARs)
  347. RRDCALC *alarms; // RRDCALC linked list for this chart
  348. // ------------------------------------------------------------------------
  349. // members for checking the data when loading from disk
  350. unsigned long memsize; // how much mem we have allocated for this (without dimensions)
  351. char magic[sizeof(RRDSET_MAGIC) + 1]; // our magic
  352. // ------------------------------------------------------------------------
  353. // the dimensions
  354. avl_tree_lock dimensions_index; // the root of the dimensions index
  355. RRDDIM *dimensions; // the actual data for every dimension
  356. };
  357. #define rrdset_rdlock(st) netdata_rwlock_rdlock(&((st)->rrdset_rwlock))
  358. #define rrdset_wrlock(st) netdata_rwlock_wrlock(&((st)->rrdset_rwlock))
  359. #define rrdset_unlock(st) netdata_rwlock_unlock(&((st)->rrdset_rwlock))
  360. // ----------------------------------------------------------------------------
  361. // these loop macros make sure the linked list is accessed with the right lock
  362. #define rrdset_foreach_read(st, host) \
  363. for((st) = (host)->rrdset_root, rrdhost_check_rdlock(host); st ; (st) = (st)->next)
  364. #define rrdset_foreach_write(st, host) \
  365. for((st) = (host)->rrdset_root, rrdhost_check_wrlock(host); st ; (st) = (st)->next)
  366. // ----------------------------------------------------------------------------
  367. // RRDHOST flags
  368. // use this for configuration flags, not for state control
  369. // flags are set/unset in a manner that is not thread safe
  370. // and may lead to missing information.
  371. typedef enum rrdhost_flags {
  372. RRDHOST_FLAG_ORPHAN = 1 << 0, // this host is orphan (not receiving data)
  373. RRDHOST_FLAG_DELETE_OBSOLETE_CHARTS = 1 << 1, // delete files of obsolete charts
  374. RRDHOST_FLAG_DELETE_ORPHAN_HOST = 1 << 2, // delete the entire host when orphan
  375. RRDHOST_FLAG_BACKEND_SEND = 1 << 3, // send it to backends
  376. RRDHOST_FLAG_BACKEND_DONT_SEND = 1 << 4, // don't send it to backends
  377. } RRDHOST_FLAGS;
  378. #ifdef HAVE_C___ATOMIC
  379. #define rrdhost_flag_check(host, flag) (__atomic_load_n(&((host)->flags), __ATOMIC_SEQ_CST) & (flag))
  380. #define rrdhost_flag_set(host, flag) __atomic_or_fetch(&((host)->flags), flag, __ATOMIC_SEQ_CST)
  381. #define rrdhost_flag_clear(host, flag) __atomic_and_fetch(&((host)->flags), ~flag, __ATOMIC_SEQ_CST)
  382. #else
  383. #define rrdhost_flag_check(host, flag) ((host)->flags & (flag))
  384. #define rrdhost_flag_set(host, flag) (host)->flags |= (flag)
  385. #define rrdhost_flag_clear(host, flag) (host)->flags &= ~(flag)
  386. #endif
  387. #ifdef NETDATA_INTERNAL_CHECKS
  388. #define rrdset_debug(st, fmt, args...) do { if(unlikely(debug_flags & D_RRD_STATS && rrdset_flag_check(st, RRDSET_FLAG_DEBUG))) \
  389. debug_int(__FILE__, __FUNCTION__, __LINE__, "%s: " fmt, st->name, ##args); } while(0)
  390. #else
  391. #define rrdset_debug(st, fmt, args...) debug_dummy()
  392. #endif
  393. // ----------------------------------------------------------------------------
  394. // Health data
  395. struct alarm_entry {
  396. uint32_t unique_id;
  397. uint32_t alarm_id;
  398. uint32_t alarm_event_id;
  399. time_t when;
  400. time_t duration;
  401. time_t non_clear_duration;
  402. char *name;
  403. uint32_t hash_name;
  404. char *chart;
  405. uint32_t hash_chart;
  406. char *family;
  407. char *exec;
  408. char *recipient;
  409. time_t exec_run_timestamp;
  410. int exec_code;
  411. char *source;
  412. char *units;
  413. char *info;
  414. calculated_number old_value;
  415. calculated_number new_value;
  416. char *old_value_string;
  417. char *new_value_string;
  418. RRDCALC_STATUS old_status;
  419. RRDCALC_STATUS new_status;
  420. uint32_t flags;
  421. int delay;
  422. time_t delay_up_to_timestamp;
  423. uint32_t updated_by_id;
  424. uint32_t updates_id;
  425. time_t last_repeat;
  426. struct alarm_entry *next;
  427. };
  428. typedef struct alarm_log {
  429. uint32_t next_log_id;
  430. uint32_t next_alarm_id;
  431. unsigned int count;
  432. unsigned int max;
  433. ALARM_ENTRY *alarms;
  434. netdata_rwlock_t alarm_log_rwlock;
  435. } ALARM_LOG;
  436. // ----------------------------------------------------------------------------
  437. // RRD HOST
  438. struct rrdhost_system_info {
  439. char *os_name;
  440. char *os_id;
  441. char *os_id_like;
  442. char *os_version;
  443. char *os_version_id;
  444. char *os_detection;
  445. char *kernel_name;
  446. char *kernel_version;
  447. char *architecture;
  448. char *virtualization;
  449. char *virt_detection;
  450. char *container;
  451. char *container_detection;
  452. };
  453. struct rrdhost {
  454. avl avl; // the index of hosts
  455. // ------------------------------------------------------------------------
  456. // host information
  457. char *hostname; // the hostname of this host
  458. uint32_t hash_hostname; // the hostname hash
  459. char *registry_hostname; // the registry hostname for this host
  460. char machine_guid[GUID_LEN + 1]; // the unique ID of this host
  461. uint32_t hash_machine_guid; // the hash of the unique ID
  462. const char *os; // the O/S type of the host
  463. const char *tags; // tags for this host
  464. const char *timezone; // the timezone of the host
  465. RRDHOST_FLAGS flags; // flags about this RRDHOST
  466. int rrd_update_every; // the update frequency of the host
  467. long rrd_history_entries; // the number of history entries for the host's charts
  468. #ifdef ENABLE_DBENGINE
  469. unsigned page_cache_mb; // Database Engine page cache size in MiB
  470. unsigned disk_space_mb; // Database Engine disk space quota in MiB
  471. #endif
  472. RRD_MEMORY_MODE rrd_memory_mode; // the memory more for the charts of this host
  473. char *cache_dir; // the directory to save RRD cache files
  474. char *varlib_dir; // the directory to save health log
  475. char *program_name; // the program name that collects metrics for this host
  476. char *program_version; // the program version that collects metrics for this host
  477. struct rrdhost_system_info *system_info; // information collected from the host environment
  478. // ------------------------------------------------------------------------
  479. // streaming of data to remote hosts - rrdpush
  480. unsigned int rrdpush_send_enabled:1; // 1 when this host sends metrics to another netdata
  481. char *rrdpush_send_destination; // where to send metrics to
  482. char *rrdpush_send_api_key; // the api key at the receiving netdata
  483. // the following are state information for the threading
  484. // streaming metrics from this netdata to an upstream netdata
  485. volatile unsigned int rrdpush_sender_spawn:1; // 1 when the sender thread has been spawn
  486. netdata_thread_t rrdpush_sender_thread; // the sender thread
  487. volatile unsigned int rrdpush_sender_connected:1; // 1 when the sender is ready to push metrics
  488. int rrdpush_sender_socket; // the fd of the socket to the remote host, or -1
  489. volatile unsigned int rrdpush_sender_error_shown:1; // 1 when we have logged a communication error
  490. volatile unsigned int rrdpush_sender_join:1; // 1 when we have to join the sending thread
  491. SIMPLE_PATTERN *rrdpush_send_charts_matching; // pattern to match the charts to be sent
  492. // metrics may be collected asynchronously
  493. // these synchronize all the threads willing the write to our sending buffer
  494. netdata_mutex_t rrdpush_sender_buffer_mutex; // exclusive access to rrdpush_sender_buffer
  495. int rrdpush_sender_pipe[2]; // collector to sender thread signaling
  496. BUFFER *rrdpush_sender_buffer; // collector fills it, sender sends it
  497. // ------------------------------------------------------------------------
  498. // streaming of data from remote hosts - rrdpush
  499. volatile size_t connected_senders; // when remote hosts are streaming to this
  500. // host, this is the counter of connected clients
  501. time_t senders_disconnected_time; // the time the last sender was disconnected
  502. // ------------------------------------------------------------------------
  503. // health monitoring options
  504. unsigned int health_enabled:1; // 1 when this host has health enabled
  505. time_t health_delay_up_to; // a timestamp to delay alarms processing up to
  506. char *health_default_exec; // the full path of the alarms notifications program
  507. char *health_default_recipient; // the default recipient for all alarms
  508. char *health_log_filename; // the alarms event log filename
  509. size_t health_log_entries_written; // the number of alarm events writtern to the alarms event log
  510. FILE *health_log_fp; // the FILE pointer to the open alarms event log file
  511. uint32_t health_default_warn_repeat_every; // the default value for the interval between repeating warning notifications
  512. uint32_t health_default_crit_repeat_every; // the default value for the interval between repeating critical notifications
  513. // all RRDCALCs are primarily allocated and linked here
  514. // RRDCALCs may be linked to charts at any point
  515. // (charts may or may not exist when these are loaded)
  516. RRDCALC *alarms;
  517. avl_tree_lock alarms_idx_health_log;
  518. avl_tree_lock alarms_idx_name;
  519. ALARM_LOG health_log; // alarms historical events (event log)
  520. uint32_t health_last_processed_id; // the last processed health id from the log
  521. uint32_t health_max_unique_id; // the max alarm log unique id given for the host
  522. uint32_t health_max_alarm_id; // the max alarm id given for the host
  523. // templates of alarms
  524. // these are used to create alarms when charts
  525. // are created or renamed, that match them
  526. RRDCALCTEMPLATE *templates;
  527. // ------------------------------------------------------------------------
  528. // the charts of the host
  529. RRDSET *rrdset_root; // the host charts
  530. // ------------------------------------------------------------------------
  531. // locks
  532. netdata_rwlock_t rrdhost_rwlock; // lock for this RRDHOST (protects rrdset_root linked list)
  533. // ------------------------------------------------------------------------
  534. // indexes
  535. avl_tree_lock rrdset_root_index; // the host's charts index (by id)
  536. avl_tree_lock rrdset_root_index_name; // the host's charts index (by name)
  537. avl_tree_lock rrdfamily_root_index; // the host's chart families index
  538. avl_tree_lock rrdvar_root_index; // the host's chart variables index
  539. #ifdef ENABLE_DBENGINE
  540. struct rrdengine_instance *rrdeng_ctx; // DB engine instance for this host
  541. #endif
  542. #ifdef ENABLE_HTTPS
  543. struct netdata_ssl ssl; //Structure used to encrypt the connection
  544. #endif
  545. struct rrdhost *next;
  546. };
  547. extern RRDHOST *localhost;
  548. #define rrdhost_rdlock(host) netdata_rwlock_rdlock(&((host)->rrdhost_rwlock))
  549. #define rrdhost_wrlock(host) netdata_rwlock_wrlock(&((host)->rrdhost_rwlock))
  550. #define rrdhost_unlock(host) netdata_rwlock_unlock(&((host)->rrdhost_rwlock))
  551. // ----------------------------------------------------------------------------
  552. // these loop macros make sure the linked list is accessed with the right lock
  553. #define rrdhost_foreach_read(var) \
  554. for((var) = localhost, rrd_check_rdlock(); var ; (var) = (var)->next)
  555. #define rrdhost_foreach_write(var) \
  556. for((var) = localhost, rrd_check_wrlock(); var ; (var) = (var)->next)
  557. // ----------------------------------------------------------------------------
  558. // global lock for all RRDHOSTs
  559. extern netdata_rwlock_t rrd_rwlock;
  560. #define rrd_rdlock() netdata_rwlock_rdlock(&rrd_rwlock)
  561. #define rrd_wrlock() netdata_rwlock_wrlock(&rrd_rwlock)
  562. #define rrd_unlock() netdata_rwlock_unlock(&rrd_rwlock)
  563. // ----------------------------------------------------------------------------
  564. extern size_t rrd_hosts_available;
  565. extern time_t rrdhost_free_orphan_time;
  566. extern void rrd_init(char *hostname, struct rrdhost_system_info *system_info);
  567. extern RRDHOST *rrdhost_find_by_hostname(const char *hostname, uint32_t hash);
  568. extern RRDHOST *rrdhost_find_by_guid(const char *guid, uint32_t hash);
  569. extern RRDHOST *rrdhost_find_or_create(
  570. const char *hostname
  571. , const char *registry_hostname
  572. , const char *guid
  573. , const char *os
  574. , const char *timezone
  575. , const char *tags
  576. , const char *program_name
  577. , const char *program_version
  578. , int update_every
  579. , long history
  580. , RRD_MEMORY_MODE mode
  581. , unsigned int health_enabled
  582. , unsigned int rrdpush_enabled
  583. , char *rrdpush_destination
  584. , char *rrdpush_api_key
  585. , char *rrdpush_send_charts_matching
  586. , struct rrdhost_system_info *system_info
  587. );
  588. extern int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, char *name, char *value);
  589. #if defined(NETDATA_INTERNAL_CHECKS) && defined(NETDATA_VERIFY_LOCKS)
  590. extern void __rrdhost_check_wrlock(RRDHOST *host, const char *file, const char *function, const unsigned long line);
  591. extern void __rrdhost_check_rdlock(RRDHOST *host, const char *file, const char *function, const unsigned long line);
  592. extern void __rrdset_check_rdlock(RRDSET *st, const char *file, const char *function, const unsigned long line);
  593. extern void __rrdset_check_wrlock(RRDSET *st, const char *file, const char *function, const unsigned long line);
  594. extern void __rrd_check_rdlock(const char *file, const char *function, const unsigned long line);
  595. extern void __rrd_check_wrlock(const char *file, const char *function, const unsigned long line);
  596. #define rrdhost_check_rdlock(host) __rrdhost_check_rdlock(host, __FILE__, __FUNCTION__, __LINE__)
  597. #define rrdhost_check_wrlock(host) __rrdhost_check_wrlock(host, __FILE__, __FUNCTION__, __LINE__)
  598. #define rrdset_check_rdlock(st) __rrdset_check_rdlock(st, __FILE__, __FUNCTION__, __LINE__)
  599. #define rrdset_check_wrlock(st) __rrdset_check_wrlock(st, __FILE__, __FUNCTION__, __LINE__)
  600. #define rrd_check_rdlock() __rrd_check_rdlock(__FILE__, __FUNCTION__, __LINE__)
  601. #define rrd_check_wrlock() __rrd_check_wrlock(__FILE__, __FUNCTION__, __LINE__)
  602. #else
  603. #define rrdhost_check_rdlock(host) (void)0
  604. #define rrdhost_check_wrlock(host) (void)0
  605. #define rrdset_check_rdlock(st) (void)0
  606. #define rrdset_check_wrlock(st) (void)0
  607. #define rrd_check_rdlock() (void)0
  608. #define rrd_check_wrlock() (void)0
  609. #endif
  610. // ----------------------------------------------------------------------------
  611. // RRDSET functions
  612. extern int rrdset_set_name(RRDSET *st, const char *name);
  613. extern RRDSET *rrdset_create_custom(RRDHOST *host
  614. , const char *type
  615. , const char *id
  616. , const char *name
  617. , const char *family
  618. , const char *context
  619. , const char *title
  620. , const char *units
  621. , const char *plugin
  622. , const char *module
  623. , long priority
  624. , int update_every
  625. , RRDSET_TYPE chart_type
  626. , RRD_MEMORY_MODE memory_mode
  627. , long history_entries);
  628. #define rrdset_create(host, type, id, name, family, context, title, units, plugin, module, priority, update_every, chart_type) \
  629. 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)
  630. #define rrdset_create_localhost(type, id, name, family, context, title, units, plugin, module, priority, update_every, chart_type) \
  631. rrdset_create(localhost, type, id, name, family, context, title, units, plugin, module, priority, update_every, chart_type)
  632. extern void rrdhost_free_all(void);
  633. extern void rrdhost_save_all(void);
  634. extern void rrdhost_cleanup_all(void);
  635. extern void rrdhost_cleanup_orphan_hosts_nolock(RRDHOST *protected);
  636. extern void rrdhost_system_info_free(struct rrdhost_system_info *system_info);
  637. extern void rrdhost_free(RRDHOST *host);
  638. extern void rrdhost_save_charts(RRDHOST *host);
  639. extern void rrdhost_delete_charts(RRDHOST *host);
  640. extern int rrdhost_should_be_removed(RRDHOST *host, RRDHOST *protected, time_t now);
  641. extern void rrdset_update_heterogeneous_flag(RRDSET *st);
  642. extern RRDSET *rrdset_find(RRDHOST *host, const char *id);
  643. #define rrdset_find_localhost(id) rrdset_find(localhost, id)
  644. extern RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *id);
  645. #define rrdset_find_bytype_localhost(type, id) rrdset_find_bytype(localhost, type, id)
  646. extern RRDSET *rrdset_find_byname(RRDHOST *host, const char *name);
  647. #define rrdset_find_byname_localhost(name) rrdset_find_byname(localhost, name)
  648. extern void rrdset_next_usec_unfiltered(RRDSET *st, usec_t microseconds);
  649. extern void rrdset_next_usec(RRDSET *st, usec_t microseconds);
  650. #define rrdset_next(st) rrdset_next_usec(st, 0ULL)
  651. extern void rrdset_done(RRDSET *st);
  652. extern void rrdset_is_obsolete(RRDSET *st);
  653. extern void rrdset_isnot_obsolete(RRDSET *st);
  654. // checks if the RRDSET should be offered to viewers
  655. #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)
  656. #define rrdset_is_available_for_backends(st) (rrdset_flag_check(st, RRDSET_FLAG_ENABLED) && !rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE) && (st)->dimensions)
  657. // get the total duration in seconds of the round robin database
  658. #define rrdset_duration(st) ((time_t)( (((st)->counter >= ((unsigned long)(st)->entries))?(unsigned long)(st)->entries:(st)->counter) * (st)->update_every ))
  659. // get the timestamp of the last entry in the round robin database
  660. static inline time_t rrdset_last_entry_t(RRDSET *st) {
  661. if (st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
  662. RRDDIM *rd;
  663. time_t last_entry_t = 0;
  664. int ret = netdata_rwlock_tryrdlock(&st->rrdset_rwlock);
  665. rrddim_foreach_read(rd, st) {
  666. last_entry_t = MAX(last_entry_t, rd->state->query_ops.latest_time(rd));
  667. }
  668. if(0 == ret) netdata_rwlock_unlock(&st->rrdset_rwlock);
  669. return last_entry_t;
  670. } else {
  671. return (time_t)st->last_updated.tv_sec;
  672. }
  673. }
  674. // get the timestamp of first entry in the round robin database
  675. static inline time_t rrdset_first_entry_t(RRDSET *st) {
  676. if (st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
  677. RRDDIM *rd;
  678. time_t first_entry_t = LONG_MAX;
  679. int ret = netdata_rwlock_tryrdlock(&st->rrdset_rwlock);
  680. rrddim_foreach_read(rd, st) {
  681. first_entry_t = MIN(first_entry_t, rd->state->query_ops.oldest_time(rd));
  682. }
  683. if(0 == ret) netdata_rwlock_unlock(&st->rrdset_rwlock);
  684. if (unlikely(LONG_MAX == first_entry_t)) return 0;
  685. return first_entry_t;
  686. } else {
  687. return (time_t)(rrdset_last_entry_t(st) - rrdset_duration(st));
  688. }
  689. }
  690. // get the last slot updated in the round robin database
  691. #define rrdset_last_slot(st) ((size_t)(((st)->current_entry == 0) ? (st)->entries - 1 : (st)->current_entry - 1))
  692. // get the first / oldest slot updated in the round robin database
  693. // #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) ))
  694. // return the slot that has the oldest value
  695. static inline size_t rrdset_first_slot(RRDSET *st) {
  696. if(st->counter >= (size_t)st->entries) {
  697. // the database has been rotated at least once
  698. // the oldest entry is the one that will be next
  699. // overwritten by data collection
  700. return (size_t)st->current_entry;
  701. }
  702. // we do not have rotated the db yet
  703. // so 0 is the first entry
  704. return 0;
  705. }
  706. // get the slot of the round robin database, for the given timestamp (t)
  707. // it always returns a valid slot, although may not be for the time requested if the time is outside the round robin database
  708. static inline size_t rrdset_time2slot(RRDSET *st, time_t t) {
  709. size_t ret = 0;
  710. if(t >= rrdset_last_entry_t(st)) {
  711. // the requested time is after the last entry we have
  712. ret = rrdset_last_slot(st);
  713. }
  714. else {
  715. if(t <= rrdset_first_entry_t(st)) {
  716. // the requested time is before the first entry we have
  717. ret = rrdset_first_slot(st);
  718. }
  719. else {
  720. if(rrdset_last_slot(st) >= ((rrdset_last_entry_t(st) - t) / (size_t)(st->update_every)))
  721. ret = rrdset_last_slot(st) - ((rrdset_last_entry_t(st) - t) / (size_t)(st->update_every));
  722. else
  723. ret = rrdset_last_slot(st) - ((rrdset_last_entry_t(st) - t) / (size_t)(st->update_every)) + (unsigned long)st->entries;
  724. }
  725. }
  726. if(unlikely(ret >= (size_t)st->entries)) {
  727. error("INTERNAL ERROR: rrdset_time2slot() on %s returns values outside entries", st->name);
  728. ret = (size_t)(st->entries - 1);
  729. }
  730. return ret;
  731. }
  732. // get the timestamp of a specific slot in the round robin database
  733. static inline time_t rrdset_slot2time(RRDSET *st, size_t slot) {
  734. time_t ret;
  735. if(slot >= (size_t)st->entries) {
  736. error("INTERNAL ERROR: caller of rrdset_slot2time() gives invalid slot %zu", slot);
  737. slot = (size_t)st->entries - 1;
  738. }
  739. if(slot > rrdset_last_slot(st)) {
  740. ret = rrdset_last_entry_t(st) - (size_t)st->update_every * (rrdset_last_slot(st) - slot + (size_t)st->entries);
  741. }
  742. else {
  743. ret = rrdset_last_entry_t(st) - (size_t)st->update_every;
  744. }
  745. if(unlikely(ret < rrdset_first_entry_t(st))) {
  746. error("INTERNAL ERROR: rrdset_slot2time() on %s returns time too far in the past", st->name);
  747. ret = rrdset_first_entry_t(st);
  748. }
  749. if(unlikely(ret > rrdset_last_entry_t(st))) {
  750. error("INTERNAL ERROR: rrdset_slot2time() on %s returns time into the future", st->name);
  751. ret = rrdset_last_entry_t(st);
  752. }
  753. return ret;
  754. }
  755. // ----------------------------------------------------------------------------
  756. // RRD DIMENSION functions
  757. 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);
  758. #define rrddim_add(st, id, name, multiplier, divisor, algorithm) rrddim_add_custom(st, id, name, multiplier, divisor, algorithm, (st)->rrd_memory_mode)
  759. extern int rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name);
  760. extern int rrddim_set_algorithm(RRDSET *st, RRDDIM *rd, RRD_ALGORITHM algorithm);
  761. extern int rrddim_set_multiplier(RRDSET *st, RRDDIM *rd, collected_number multiplier);
  762. extern int rrddim_set_divisor(RRDSET *st, RRDDIM *rd, collected_number divisor);
  763. extern RRDDIM *rrddim_find(RRDSET *st, const char *id);
  764. extern int rrddim_hide(RRDSET *st, const char *id);
  765. extern int rrddim_unhide(RRDSET *st, const char *id);
  766. extern void rrddim_is_obsolete(RRDSET *st, RRDDIM *rd);
  767. extern void rrddim_isnot_obsolete(RRDSET *st, RRDDIM *rd);
  768. extern collected_number rrddim_set_by_pointer(RRDSET *st, RRDDIM *rd, collected_number value);
  769. extern collected_number rrddim_set(RRDSET *st, const char *id, collected_number value);
  770. extern long align_entries_to_pagesize(RRD_MEMORY_MODE mode, long entries);
  771. // ----------------------------------------------------------------------------
  772. // Miscellaneous functions
  773. extern int alarm_compare_id(void *a, void *b);
  774. extern int alarm_compare_name(void *a, void *b);
  775. // ----------------------------------------------------------------------------
  776. // RRD internal functions
  777. #ifdef NETDATA_RRD_INTERNALS
  778. extern avl_tree_lock rrdhost_root_index;
  779. extern char *rrdset_strncpyz_name(char *to, const char *from, size_t length);
  780. extern char *rrdset_cache_dir(RRDHOST *host, const char *id, const char *config_section);
  781. extern void rrddim_free(RRDSET *st, RRDDIM *rd);
  782. extern int rrddim_compare(void* a, void* b);
  783. extern int rrdset_compare(void* a, void* b);
  784. extern int rrdset_compare_name(void* a, void* b);
  785. extern int rrdfamily_compare(void *a, void *b);
  786. extern RRDFAMILY *rrdfamily_create(RRDHOST *host, const char *id);
  787. extern void rrdfamily_free(RRDHOST *host, RRDFAMILY *rc);
  788. #define rrdset_index_add(host, st) (RRDSET *)avl_insert_lock(&((host)->rrdset_root_index), (avl *)(st))
  789. #define rrdset_index_del(host, st) (RRDSET *)avl_remove_lock(&((host)->rrdset_root_index), (avl *)(st))
  790. extern RRDSET *rrdset_index_del_name(RRDHOST *host, RRDSET *st);
  791. extern void rrdset_free(RRDSET *st);
  792. extern void rrdset_reset(RRDSET *st);
  793. extern void rrdset_save(RRDSET *st);
  794. extern void rrdset_delete(RRDSET *st);
  795. extern void rrdset_delete_obsolete_dimensions(RRDSET *st);
  796. extern void rrdhost_cleanup_obsolete_charts(RRDHOST *host);
  797. #endif /* NETDATA_RRD_INTERNALS */
  798. // ----------------------------------------------------------------------------
  799. // RRD DB engine declarations
  800. #ifdef ENABLE_DBENGINE
  801. #include "database/engine/rrdengineapi.h"
  802. #endif
  803. #endif /* NETDATA_RRD_H */