rrd.h 48 KB

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