]> arthur.barton.de Git - netdata.git/blobdiff - src/rrd.h
each host can have its own settings for history, update_every, rrd memory mode, healt...
[netdata.git] / src / rrd.h
index dbaf986503675fde06923ddc66d01024e08c5b23..cbf2260b5c2149c05ad17c1c103ca32eb9b6737d 100644 (file)
--- a/src/rrd.h
+++ b/src/rrd.h
@@ -3,20 +3,17 @@
 
 #define UPDATE_EVERY 1
 #define UPDATE_EVERY_MAX 3600
-extern int rrd_update_every;
 
 #define RRD_DEFAULT_HISTORY_ENTRIES 3600
 #define RRD_HISTORY_ENTRIES_MAX (86400*10)
-extern int rrd_default_history_entries;
 
-// time in seconds to delete unupdated dimensions
-// set to zero to disable this feature
-extern int rrd_delete_unupdated_dimensions;
+extern int default_localhost_rrd_update_every;
+extern int default_localhost_rrd_history_entries;
 
-#define RRD_ID_LENGTH_MAX 400
+#define RRD_ID_LENGTH_MAX 200
 
-#define RRDSET_MAGIC        "NETDATA RRD SET FILE V018"
-#define RRDDIMENSION_MAGIC  "NETDATA RRD DIMENSION FILE V018"
+#define RRDSET_MAGIC        "NETDATA RRD SET FILE V019"
+#define RRDDIMENSION_MAGIC  "NETDATA RRD DIMENSION FILE V019"
 
 typedef long long total_number;
 #define TOTAL_NUMBER_FORMAT "%lld"
@@ -24,59 +21,73 @@ typedef long long total_number;
 // ----------------------------------------------------------------------------
 // chart types
 
+typedef enum rrdset_type {
+    RRDSET_TYPE_LINE    = 0,
+    RRDSET_TYPE_AREA    = 1,
+    RRDSET_TYPE_STACKED = 2
+} RRDSET_TYPE;
+
 #define RRDSET_TYPE_LINE_NAME "line"
 #define RRDSET_TYPE_AREA_NAME "area"
 #define RRDSET_TYPE_STACKED_NAME "stacked"
 
-#define RRDSET_TYPE_LINE    0
-#define RRDSET_TYPE_AREA    1
-#define RRDSET_TYPE_STACKED 2
-
-int rrdset_type_id(const char *name);
-const char *rrdset_type_name(int chart_type);
+RRDSET_TYPE rrdset_type_id(const char *name);
+const char *rrdset_type_name(RRDSET_TYPE chart_type);
 
 
 // ----------------------------------------------------------------------------
 // memory mode
 
+typedef enum rrd_memory_mode {
+    RRD_MEMORY_MODE_RAM  = 0,
+    RRD_MEMORY_MODE_MAP  = 1,
+    RRD_MEMORY_MODE_SAVE = 2
+} RRD_MEMORY_MODE;
+
 #define RRD_MEMORY_MODE_RAM_NAME "ram"
 #define RRD_MEMORY_MODE_MAP_NAME "map"
 #define RRD_MEMORY_MODE_SAVE_NAME "save"
 
-#define RRD_MEMORY_MODE_RAM 0
-#define RRD_MEMORY_MODE_MAP 1
-#define RRD_MEMORY_MODE_SAVE 2
+extern RRD_MEMORY_MODE default_localhost_rrd_memory_mode;
 
-extern int rrd_memory_mode;
-
-extern const char *rrd_memory_mode_name(int id);
-extern int rrd_memory_mode_id(const char *name);
+extern const char *rrd_memory_mode_name(RRD_MEMORY_MODE id);
+extern RRD_MEMORY_MODE rrd_memory_mode_id(const char *name);
 
 
 // ----------------------------------------------------------------------------
 // algorithms types
 
-#define RRDDIM_ABSOLUTE_NAME                "absolute"
-#define RRDDIM_INCREMENTAL_NAME             "incremental"
-#define RRDDIM_PCENT_OVER_DIFF_TOTAL_NAME   "percentage-of-incremental-row"
-#define RRDDIM_PCENT_OVER_ROW_TOTAL_NAME    "percentage-of-absolute-row"
+typedef enum rrd_algorithm {
+    RRD_ALGORITHM_ABSOLUTE              = 0,
+    RRD_ALGORITHM_INCREMENTAL           = 1,
+    RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL = 2,
+    RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL  = 3
+} RRD_ALGORITHM;
 
-#define RRDDIM_ABSOLUTE                 0
-#define RRDDIM_INCREMENTAL              1
-#define RRDDIM_PCENT_OVER_DIFF_TOTAL    2
-#define RRDDIM_PCENT_OVER_ROW_TOTAL     3
+#define RRD_ALGORITHM_ABSOLUTE_NAME                "absolute"
+#define RRD_ALGORITHM_INCREMENTAL_NAME             "incremental"
+#define RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL_NAME   "percentage-of-incremental-row"
+#define RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL_NAME    "percentage-of-absolute-row"
 
-extern int rrddim_algorithm_id(const char *name);
-extern const char *rrddim_algorithm_name(int chart_type);
+extern RRD_ALGORITHM rrd_algorithm_id(const char *name);
+extern const char *rrd_algorithm_name(RRD_ALGORITHM algorithm);
 
 // ----------------------------------------------------------------------------
 // flags
 
-#define RRDDIM_FLAG_HIDDEN 0x00000001 // this dimension will not be offered to callers
-#define RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS 0x00000002 // do not offer RESET or OVERFLOW info to callers
+typedef enum rrddim_flags {
+    RRDDIM_FLAG_HIDDEN                          = 1 << 0,  // this dimension will not be offered to callers
+    RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS = 1 << 1,  // do not offer RESET or OVERFLOW info to callers
+    RRDDIM_FLAG_UPDATED                         = 1 << 31  // the dimension has been updated since the last processing
+} RRDDIM_FLAGS;
+
+#define rrddim_flag_check(rd, flag) ((rd)->flags & flag)
+#define rrddim_flag_set(rd, flag)   (rd)->flags |= flag
+#define rrddim_flag_clear(rd, flag) (rd)->flags &= ~flag
+
 
 // ----------------------------------------------------------------------------
-// RRD CONTEXT
+// RRD FAMILY
 
 struct rrdfamily {
     avl avl;
@@ -90,8 +101,9 @@ struct rrdfamily {
 };
 typedef struct rrdfamily RRDFAMILY;
 
+
 // ----------------------------------------------------------------------------
-// RRD DIMENSION
+// RRD DIMENSION - this is a metric
 
 struct rrddim {
     // ------------------------------------------------------------------------
@@ -102,18 +114,20 @@ struct rrddim {
     // ------------------------------------------------------------------------
     // the dimension definition
 
-    char id[RRD_ID_LENGTH_MAX + 1];                 // the id of this dimension (for internal identification)
-
+    const char *id;                                 // the id of this dimension (for internal identification)
     const char *name;                               // the name of this dimension (as presented to user)
                                                     // this is a pointer to the config structure
                                                     // since the config always has a higher priority
                                                     // (the user overwrites the name of the charts)
+                                                    // DO NOT FREE THIS - IT IS ALLOCATED IN CONFIG
+
+    RRD_ALGORITHM algorithm;                        // the algorithm that is applied to add new collected values
+    RRD_MEMORY_MODE memory_mode;                    // the memory mode for this dimension
 
-    int algorithm;                                  // the algorithm that is applied to add new collected values
-    long multiplier;                                // the multiplier of the collected values
-    long divisor;                                   // the divider of the collected values
+    collected_number multiplier;                    // the multiplier of the collected values
+    collected_number divisor;                       // the divider of the collected values
 
-    int mapped;                                     // if set to non zero, this dimension is mapped to a file
+    uint32_t flags;                                 // options and status options for the dimension
 
     // ------------------------------------------------------------------------
     // members for temporary data we need for calculations
@@ -122,17 +136,11 @@ struct rrddim {
                                                     // instead of strcmp() every item in the binary index
                                                     // we first compare the hashes
 
-    // FIXME
-    // we need the hash_name too!
-
-    uint32_t flags;
-
-    char cache_filename[FILENAME_MAX+1];            // the filename we load/save from/to this set
+    uint32_t hash_name;                             // a simple hash of the name
 
-    unsigned long counter;                          // the number of times we added values to this rrdim
+    char *cache_filename;                           // the filename we load/save from/to this set
 
-    int updated;                                    // set to 0 after each calculation, to 1 after each collected value
-                                                    // we use this to detect that a dimension is not updated
+    size_t counter;                                 // the number of times we added values to this rrdim
 
     struct timeval last_collected_time;             // when was this dimension last updated
                                                     // this is actual date time we updated the last_collected_value
@@ -163,7 +171,7 @@ struct rrddim {
 
     int update_every;                               // every how many seconds is this updated
 
-    unsigned long memsize;                          // the memory allocated for this dimension
+    size_t memsize;                                 // the memory allocated for this dimension
 
     char magic[sizeof(RRDDIMENSION_MAGIC) + 1];     // a string to be saved, used to identify our data file
 
@@ -178,7 +186,7 @@ typedef struct rrddim RRDDIM;
 
 
 // ----------------------------------------------------------------------------
-// RRDSET
+// RRDSET - this is a chart
 
 struct rrdset {
     // ------------------------------------------------------------------------
@@ -205,7 +213,7 @@ struct rrdset {
     char *context;                                  // the template of this data set
     uint32_t hash_context;
 
-    int chart_type;
+    RRDSET_TYPE chart_type;
 
     int update_every;                               // every how many seconds is this updated?
 
@@ -287,30 +295,58 @@ typedef struct rrdset RRDSET;
 // RRD HOST
 
 struct rrdhost {
-    avl avl;
+    avl avl;                                        // the index of hosts
 
-    char *hostname;
+    char *hostname;                                 // the hostname of this host
+    uint32_t hash_hostname;                         // the hostname hash
 
-    RRDSET *rrdset_root;
-    pthread_rwlock_t rrdset_root_rwlock;
+    char machine_guid[GUID_LEN + 1];                // the unique ID of this host
+    uint32_t hash_machine_guid;                     // the hash of the unique ID
 
-    avl_tree_lock rrdset_root_index;
-    avl_tree_lock rrdset_root_index_name;
+    int rrd_update_every;                           // the update frequency of the host
+    int rrd_history_entries;                        // the number of history entries for the host's charts
 
-    avl_tree_lock rrdfamily_root_index;
-    avl_tree_lock variables_root_index;
+    int health_enabled;                             // 1 when this host has health enabled
+    RRD_MEMORY_MODE rrd_memory_mode;                // the memory more for the charts of this host
+
+    RRDSET *rrdset_root;                            // the host charts
+    pthread_rwlock_t rrdset_root_rwlock;            // lock for the host charts
+
+    avl_tree_lock rrdset_root_index;                // the host's charts index (by id)
+    avl_tree_lock rrdset_root_index_name;           // the host's charts index (by name)
+
+    avl_tree_lock rrdfamily_root_index;             // the host's chart families index
+    avl_tree_lock variables_root_index;             // the host's chart variables index
 
     // all RRDCALCs are primarily allocated and linked here
     // RRDCALCs may be linked to charts at any point
     // (charts may or may not exist when these are loaded)
     RRDCALC *alarms;
-    ALARM_LOG health_log;
 
+    ALARM_LOG health_log;                           // alarms historical events (event log)
+
+    // templates of alarms
+    // these are used to create alarms when charts
+    // are created or renamed, that match them
     RRDCALCTEMPLATE *templates;
+
+    // health / alarm settings
+    char *health_default_exec;
+    char *health_default_recipient;
+    char *health_log_filename;
+    size_t health_log_entries_written;
+    FILE *health_log_fp;
+
+    struct rrdhost *next;
 };
 typedef struct rrdhost RRDHOST;
-extern RRDHOST localhost;
-extern void rrdhost_init(char *hostname);
+
+extern RRDHOST *localhost;
+
+extern void rrd_init(char *hostname);
+
+extern RRDHOST *rrdhost_find(const char *guid, uint32_t hash);
+extern RRDHOST *rrdhost_find_or_create(const char *hostname, const char *guid);
 
 #ifdef NETDATA_INTERNAL_CHECKS
 #define rrdhost_check_wrlock(host) rrdhost_check_wrlock_int(host, __FILE__, __FUNCTION__, __LINE__)
@@ -328,32 +364,38 @@ extern void rrdhost_rdlock(RRDHOST *host);
 extern void rrdhost_unlock(RRDHOST *host);
 
 // ----------------------------------------------------------------------------
-// RRD SET functions
+// RRDSET functions
 
-extern char *rrdset_strncpyz_name(char *to, const char *from, size_t length);
 extern void rrdset_set_name(RRDSET *st, const char *name);
 
-extern char *rrdset_cache_dir(const char *id);
+extern RRDSET *rrdset_create(RRDHOST *host
+                             , const char *type
+                             , const char *id
+                             , const char *name
+                             , const char *family
+                             , const char *context
+                             , const char *title
+                             , const char *units
+                             , long priority
+                             , int update_every
+                             , int chart_type);
 
-extern void rrdset_reset(RRDSET *st);
+#define rrdset_create_localhost(type, id, name, family, context, title, units, priority, update_every, chart_type) rrdset_create(localhost, type, id, name, family, context, title, units, priority, update_every, chart_type)
+
+extern void rrdhost_free_all(void);
+extern void rrdhost_save_all(void);
 
-extern RRDSET *rrdset_create(const char *type
-        , const char *id
-        , const char *name
-        , const char *family
-        , const char *context
-        , const char *title
-        , const char *units
-        , long priority
-        , int update_every
-        , int chart_type);
+extern void rrdhost_free(RRDHOST *host);
+extern void rrdhost_save(RRDHOST *host);
 
-extern void rrdset_free_all(void);
-extern void rrdset_save_all(void);
+extern RRDSET *rrdset_find(RRDHOST *host, const char *id);
+#define rrdset_find_localhost(id) rrdset_find(localhost, id)
 
-extern RRDSET *rrdset_find(const char *id);
-extern RRDSET *rrdset_find_bytype(const char *type, const char *id);
-extern RRDSET *rrdset_find_byname(const char *name);
+extern RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *id);
+#define rrdset_find_bytype_localhost(type, id) rrdset_find_bytype(localhost, type, id)
+
+extern RRDSET *rrdset_find_byname(RRDHOST *host, const char *name);
+#define rrdset_find_byname_localhost(name)  rrdset_find_byname(localhost, name)
 
 extern void rrdset_next_usec_unfiltered(RRDSET *st, usec_t microseconds);
 extern void rrdset_next_usec(RRDSET *st, usec_t microseconds);
@@ -397,11 +439,9 @@ extern usec_t rrdset_done(RRDSET *st);
 // ----------------------------------------------------------------------------
 // RRD DIMENSION functions
 
-extern RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier, long divisor, int algorithm);
+extern RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, collected_number multiplier, collected_number divisor, RRD_ALGORITHM algorithm);
 
 extern void rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name);
-extern void rrddim_free(RRDSET *st, RRDDIM *rd);
-
 extern RRDDIM *rrddim_find(RRDSET *st, const char *id);
 
 extern int rrddim_hide(RRDSET *st, const char *id);
@@ -410,4 +450,34 @@ extern int rrddim_unhide(RRDSET *st, const char *id);
 extern collected_number rrddim_set_by_pointer(RRDSET *st, RRDDIM *rd, collected_number value);
 extern collected_number rrddim_set(RRDSET *st, const char *id, collected_number value);
 
+
+// ----------------------------------------------------------------------------
+// RRD internal functions
+
+#ifdef NETDATA_RRD_INTERNALS
+
+extern avl_tree_lock rrdhost_root_index;
+
+extern char *rrdset_strncpyz_name(char *to, const char *from, size_t length);
+extern char *rrdset_cache_dir(RRDHOST *host, const char *id);
+
+extern void rrdset_reset(RRDSET *st);
+
+extern void rrddim_free(RRDSET *st, RRDDIM *rd);
+
+extern int rrddim_compare(void* a, void* b);
+extern int rrdset_compare(void* a, void* b);
+extern int rrdset_compare_name(void* a, void* b);
+extern int rrdfamily_compare(void *a, void *b);
+
+extern RRDFAMILY *rrdfamily_create(RRDHOST *host, const char *id);
+extern void rrdfamily_free(RRDHOST *host, RRDFAMILY *rc);
+
+#define rrdset_index_add(host, st) (RRDSET *)avl_insert_lock(&((host)->rrdset_root_index), (avl *)(st))
+#define rrdset_index_del(host, st) (RRDSET *)avl_remove_lock(&((host)->rrdset_root_index), (avl *)(st))
+extern RRDSET *rrdset_index_del_name(RRDHOST *host, RRDSET *st);
+
+#endif /* NETDATA_RRD_INTERNALS */
+
+
 #endif /* NETDATA_RRD_H */