sqlite_context.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_SQLITE_CONTEXT_H
  3. #define NETDATA_SQLITE_CONTEXT_H
  4. #include "daemon/common.h"
  5. #include "sqlite3.h"
  6. typedef struct ctx_chart {
  7. uuid_t chart_id;
  8. const char *id;
  9. const char *name;
  10. const char *context;
  11. const char *title;
  12. const char *units;
  13. const char *family;
  14. int chart_type;
  15. int priority;
  16. int update_every;
  17. } SQL_CHART_DATA;
  18. typedef struct ctx_dimension {
  19. uuid_t dim_id;
  20. char *id;
  21. char *name;
  22. } SQL_DIMENSION_DATA;
  23. typedef struct ctx_label {
  24. char *label_key;
  25. char *label_value;
  26. int label_source;
  27. } SQL_CLABEL_DATA;
  28. // Structure to store or delete
  29. typedef struct versioned_context_data {
  30. uint64_t version; // the version of this context as EPOCH in seconds
  31. const char *id; // the id of the context
  32. const char *title; // the title of the context
  33. const char *chart_type; // the chart_type of the context
  34. const char *units; // the units of the context
  35. const char *family; // the family of the context
  36. uint64_t priority; // the chart priority of the context
  37. uint64_t first_time_t; // the first entry in the database, in seconds
  38. uint64_t last_time_t; // the last point in the database, in seconds
  39. bool deleted; // true when this is deleted
  40. } VERSIONED_CONTEXT_DATA;
  41. extern void ctx_get_context_list(uuid_t *host_uuid, void (*dict_cb)(VERSIONED_CONTEXT_DATA *, void *), void *data);
  42. extern void ctx_get_chart_list(uuid_t *host_uuid, void (*dict_cb)(SQL_CHART_DATA *, void *), void *data);
  43. extern void ctx_get_label_list(uuid_t *chart_uuid, void (*dict_cb)(SQL_CLABEL_DATA *, void *), void *data);
  44. extern void ctx_get_dimension_list(uuid_t *chart_uuid, void (*dict_cb)(SQL_DIMENSION_DATA *, void *), void *data);
  45. extern int ctx_store_context(uuid_t *host_uuid, VERSIONED_CONTEXT_DATA *context_data);
  46. #define ctx_update_context(host_uuid, context_data) ctx_store_context(host_uuid, context_data)
  47. extern int ctx_delete_context(uuid_t *host_id, VERSIONED_CONTEXT_DATA *context_data);
  48. extern int sql_init_context_database(int memory);
  49. extern void sql_close_context_database(void);
  50. extern int ctx_unittest(void);
  51. #endif //NETDATA_SQLITE_CONTEXT_H