check_filters.c 3.5 KB

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