| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_SQLITE_CONTEXT_H |
| 4 | #define NETDATA_SQLITE_CONTEXT_H |
| 5 | |
| 6 | #include "database/rrd.h" |
| 7 | #include "database/sqlite/vendored/sqlite3.h" |
| 8 | |
| 9 | int sql_context_cache_stats(int op); |
| 10 | typedef struct ctx_chart { |
| 11 | nd_uuid_t chart_id; |
| 12 | const char *id; |
| 13 | const char *name; |
| 14 | const char *context; |
| 15 | const char *title; |
| 16 | const char *units; |
| 17 | const char *family; |
| 18 | int chart_type; |
| 19 | int priority; |
| 20 | int update_every; |
| 21 | } SQL_CHART_DATA; |
| 22 | |
| 23 | typedef struct ctx_dimension { |
| 24 | nd_uuid_t dim_id; |
| 25 | char *id; |
| 26 | char *name; |
| 27 | bool hidden; |
| 28 | int algorithm; |
| 29 | |
| 30 | char *context; |
| 31 | char *chart_id; |
| 32 | } SQL_DIMENSION_DATA; |
| 33 | |
| 34 | typedef struct ctx_label { |
| 35 | char *label_key; |
| 36 | char *label_value; |
| 37 | int label_source; |
| 38 | } SQL_CLABEL_DATA; |
| 39 | |
| 40 | // Structure to store or delete |
| 41 | typedef struct versioned_context_data { |
| 42 | uint64_t version; // the version of this context as EPOCH in seconds |
| 43 | |
| 44 | const char *id; // the id of the context |
| 45 | const char *title; // the title of the context |
| 46 | const char *chart_type; // the chart_type of the context |
| 47 | const char *units; // the units of the context |
| 48 | const char *family; // the family of the context |
| 49 | |
| 50 | uint64_t priority; // the chart priority of the context |
| 51 | |
| 52 | uint64_t first_time_s; // the first entry in the database, in seconds |
| 53 | uint64_t last_time_s; // the last point in the database, in seconds |
| 54 | |
| 55 | bool deleted; // true when this is deleted |
| 56 | |
| 57 | } VERSIONED_CONTEXT_DATA; |
| 58 | |
| 59 | void ctx_get_context_list(nd_uuid_t *host_uuid, void (*dict_cb)(VERSIONED_CONTEXT_DATA *, void *), void *data); |
| 60 | |
| 61 | void ctx_get_chart_list(nd_uuid_t *host_uuid, void (*dict_cb)(SQL_CHART_DATA *, void *), void *data); |
| 62 | void ctx_get_label_list(nd_uuid_t *chart_uuid, void (*dict_cb)(SQL_CLABEL_DATA *, void *), void *data); |
| 63 | void ctx_get_dimension_list(nd_uuid_t *host_uuid, void (*dict_cb)(SQL_DIMENSION_DATA *, void *), void *data); |
| 64 | |
| 65 | int ctx_store_context(nd_uuid_t *host_uuid, VERSIONED_CONTEXT_DATA *context_data); |
| 66 | #define ctx_update_context(host_uuid, context_data) ctx_store_context(host_uuid, context_data) |
| 67 | |
| 68 | int ctx_delete_context(nd_uuid_t *host_id, VERSIONED_CONTEXT_DATA *context_data); |
| 69 | |
| 70 | int sql_init_context_database(int memory); |
| 71 | uint64_t sqlite_get_context_space(void); |
| 72 | int ctx_unittest(void); |
| 73 | #endif //NETDATA_SQLITE_CONTEXT_H |