exporting_engine.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "exporting_engine.h"
  3. static void exporting_main_cleanup(void *ptr) {
  4. struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
  5. static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
  6. info("cleaning up...");
  7. static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
  8. }
  9. /**
  10. * Exporting engine main
  11. *
  12. * The main thread used to control the exporting engine.
  13. *
  14. * @param ptr a pointer to netdata_static_structure.
  15. *
  16. * @return It always returns NULL.
  17. */
  18. void *exporting_main(void *ptr)
  19. {
  20. netdata_thread_cleanup_push(exporting_main_cleanup, ptr);
  21. struct engine *engine = read_exporting_config();
  22. if (!engine) {
  23. info("EXPORTING: no exporting connectors configured");
  24. goto cleanup;
  25. }
  26. if (init_connectors(engine) != 0) {
  27. error("EXPORTING: cannot initialize exporting connectors");
  28. goto cleanup;
  29. }
  30. RRDSET *st_main_rusage = NULL;
  31. RRDDIM *rd_main_user = NULL;
  32. RRDDIM *rd_main_system = NULL;
  33. create_main_rusage_chart(&st_main_rusage, &rd_main_user, &rd_main_system);
  34. usec_t step_ut = localhost->rrd_update_every * USEC_PER_SEC;
  35. heartbeat_t hb;
  36. heartbeat_init(&hb);
  37. while (!netdata_exit) {
  38. heartbeat_next(&hb, step_ut);
  39. engine->now = now_realtime_sec();
  40. if (mark_scheduled_instances(engine)) {
  41. if (prepare_buffers(engine) != 0) {
  42. error("EXPORTING: cannot prepare data to send");
  43. break;
  44. }
  45. }
  46. if (notify_workers(engine) != 0) {
  47. error("EXPORTING: cannot communicate with exporting connector instance working threads");
  48. break;
  49. }
  50. send_main_rusage(st_main_rusage, rd_main_user, rd_main_system);
  51. #ifdef UNIT_TESTING
  52. break;
  53. #endif
  54. }
  55. cleanup:
  56. netdata_thread_cleanup_pop(1);
  57. return NULL;
  58. }