check_filters.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "exporting_engine.h"
  3. /**
  4. * Check if the connector instance should export the host metrics
  5. *
  6. * @param instance an exporting connector instance.
  7. * @param host a data collecting host.
  8. * @return Returns 1 if the connector instance should export the host metrics
  9. */
  10. int rrdhost_is_exportable(struct instance *instance, RRDHOST *host)
  11. {
  12. if (host->exporting_flags == NULL)
  13. host->exporting_flags = callocz(instance->engine->instance_num, sizeof(size_t));
  14. RRDHOST_FLAGS *flags = &host->exporting_flags[instance->index];
  15. if (unlikely((*flags & (RRDHOST_FLAG_EXPORTING_SEND | RRDHOST_FLAG_EXPORTING_DONT_SEND)) == 0)) {
  16. char *host_name = (host == localhost) ? "localhost" : host->hostname;
  17. if (!instance->config.hosts_pattern || simple_pattern_matches(instance->config.hosts_pattern, host_name)) {
  18. *flags |= RRDHOST_FLAG_EXPORTING_SEND;
  19. info("enabled exporting of host '%s' for instance '%s'", host_name, instance->config.name);
  20. } else {
  21. *flags |= RRDHOST_FLAG_EXPORTING_DONT_SEND;
  22. info("disabled exporting of host '%s' for instance '%s'", host_name, instance->config.name);
  23. }
  24. }
  25. if (likely(*flags & RRDHOST_FLAG_EXPORTING_SEND))
  26. return 1;
  27. else
  28. return 0;
  29. }
  30. /**
  31. * Check if the connector instance should export the chart
  32. *
  33. * @param instance an exporting connector instance.
  34. * @param st a chart.
  35. * @return Returns 1 if the connector instance should export the chart
  36. */
  37. int rrdset_is_exportable(struct instance *instance, RRDSET *st)
  38. {
  39. #ifdef NETDATA_INTERNAL_CHECKS
  40. RRDHOST *host = st->rrdhost;
  41. #endif
  42. // Do not export anomaly rates charts.
  43. if (st->state && st->state->is_ar_chart)
  44. return 0;
  45. if (st->exporting_flags == NULL)
  46. st->exporting_flags = callocz(instance->engine->instance_num, sizeof(size_t));
  47. RRDSET_FLAGS *flags = &st->exporting_flags[instance->index];
  48. if(unlikely(*flags & RRDSET_FLAG_EXPORTING_IGNORE))
  49. return 0;
  50. if(unlikely(!(*flags & RRDSET_FLAG_EXPORTING_SEND))) {
  51. // we have not checked this chart
  52. if(simple_pattern_matches(instance->config.charts_pattern, st->id) || simple_pattern_matches(instance->config.charts_pattern, st->name))
  53. *flags |= RRDSET_FLAG_EXPORTING_SEND;
  54. else {
  55. *flags |= RRDSET_FLAG_EXPORTING_IGNORE;
  56. debug(D_EXPORTING, "EXPORTING: not sending chart '%s' of host '%s', because it is disabled for exporting.", st->id, host->hostname);
  57. return 0;
  58. }
  59. }
  60. if(unlikely(!rrdset_is_available_for_exporting_and_alarms(st))) {
  61. debug(D_EXPORTING, "EXPORTING: not sending chart '%s' of host '%s', because it is not available for exporting.", st->id, host->hostname);
  62. return 0;
  63. }
  64. if(unlikely(st->rrd_memory_mode == RRD_MEMORY_MODE_NONE && !(EXPORTING_OPTIONS_DATA_SOURCE(instance->config.options) == EXPORTING_SOURCE_DATA_AS_COLLECTED))) {
  65. debug(D_EXPORTING, "EXPORTING: not sending chart '%s' of host '%s' because its memory mode is '%s' and the exporting engine requires database access.", st->id, host->hostname, rrd_memory_mode_name(host->rrd_memory_mode));
  66. return 0;
  67. }
  68. return 1;
  69. }