aclk.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef ACLK_H
  3. #define ACLK_H
  4. typedef struct aclk_rrdhost_state {
  5. char *claimed_id; // Claimed ID if host has one otherwise NULL
  6. } aclk_rrdhost_state;
  7. #include "../daemon/common.h"
  8. #include "aclk_util.h"
  9. // minimum and maximum supported version of ACLK
  10. // in this version of agent
  11. #define ACLK_VERSION_MIN 2
  12. #define ACLK_VERSION_MAX 2
  13. // Version negotiation messages have they own versioning
  14. // this is also used for LWT message as we set that up
  15. // before version negotiation
  16. #define ACLK_VERSION_NEG_VERSION 1
  17. // Maximum time to wait for version negotiation before aborting
  18. // and defaulting to oldest supported version
  19. #define VERSION_NEG_TIMEOUT 3
  20. #if ACLK_VERSION_MIN > ACLK_VERSION_MAX
  21. #error "ACLK_VERSION_MAX must be >= than ACLK_VERSION_MIN"
  22. #endif
  23. // Define ACLK Feature Version Boundaries Here
  24. #define ACLK_V_COMPRESSION 2
  25. // How many MQTT PUBACKs we need to get to consider connection
  26. // stable for the purposes of TBEB (truncated binary exponential backoff)
  27. #define ACLK_PUBACKS_CONN_STABLE 3
  28. // TODO get rid of this shit
  29. extern int aclk_disable_runtime;
  30. extern int aclk_disable_single_updates;
  31. extern int aclk_kill_link;
  32. extern int aclk_connected;
  33. extern usec_t aclk_session_us;
  34. extern time_t aclk_session_sec;
  35. void *aclk_main(void *ptr);
  36. void aclk_single_update_disable();
  37. void aclk_single_update_enable();
  38. #define NETDATA_ACLK_HOOK \
  39. { .name = "ACLK_Main", \
  40. .config_section = NULL, \
  41. .config_name = NULL, \
  42. .enabled = 1, \
  43. .thread = NULL, \
  44. .init_routine = NULL, \
  45. .start_routine = aclk_main },
  46. extern netdata_mutex_t aclk_shared_state_mutex;
  47. #define ACLK_SHARED_STATE_LOCK netdata_mutex_lock(&aclk_shared_state_mutex)
  48. #define ACLK_SHARED_STATE_UNLOCK netdata_mutex_unlock(&aclk_shared_state_mutex)
  49. typedef enum aclk_agent_state {
  50. AGENT_INITIALIZING,
  51. AGENT_STABLE
  52. } ACLK_AGENT_STATE;
  53. extern struct aclk_shared_state {
  54. ACLK_AGENT_STATE agent_state;
  55. time_t last_popcorn_interrupt;
  56. // read only while ACLK connected
  57. // protect by lock otherwise
  58. int version_neg;
  59. usec_t version_neg_wait_till;
  60. // To wait for `disconnect` message PUBACK
  61. // when shuting down
  62. // at the same time if > 0 we know link is
  63. // shutting down
  64. int mqtt_shutdown_msg_id;
  65. int mqtt_shutdown_msg_rcvd;
  66. } aclk_shared_state;
  67. void aclk_alarm_reload(void);
  68. int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae);
  69. // TODO this is for bacward compatibility with ACLK legacy
  70. #define ACLK_CMD_CHART 1
  71. #define ACLK_CMD_CHARTDEL 0
  72. /* Informs ACLK about created/deleted chart
  73. * @param create 0 - if chart was deleted, other if chart created
  74. */
  75. int aclk_update_chart(RRDHOST *host, char *chart_name, int create);
  76. void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
  77. void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
  78. struct label *add_aclk_host_labels(struct label *label);
  79. #endif /* ACLK_H */