summaryrefslogtreecommitdiffstats
path: root/exporting/check_filters.c
blob: 726fd02a1a0d787ec11a1d2de366036cdee3376e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// SPDX-License-Identifier: GPL-3.0-or-later

#include "exporting_engine.h"


bool exporting_labels_filter_callback(const char *name, const char *value, RRDLABEL_SRC ls, void *data) {
    (void)name;
    (void)value;
    struct instance *instance = (struct instance *)data;
    return should_send_label(instance, ls);
}

/**
 * Check if the connector instance should export the host metrics
 *
 * @param instance an exporting connector instance.
 * @param host a data collecting host.
 * @return Returns 1 if the connector instance should export the host metrics
 */
int rrdhost_is_exportable(struct instance *instance, RRDHOST *host)
{
    if (host->exporting_flags == NULL)
        host->exporting_flags = callocz(instance->engine->instance_num, sizeof(size_t));

    RRDHOST_FLAGS *flags = &host->exporting_flags[instance->index];

    if (unlikely((*flags & (RRDHOST_FLAG_EXPORTING_SEND | RRDHOST_FLAG_EXPORTING_DONT_SEND)) == 0)) {
        char *host_name = (host == localhost) ? "localhost" : host->hostname;

        if (!instance->config.hosts_pattern || simple_pattern_matches(instance->config.hosts_pattern, host_name)) {
            *flags |= RRDHOST_FLAG_EXPORTING_SEND;
            info("enabled exporting of host '%s' for instance '%s'", host_name, instance->config.name);
        } else {
            *flags |= RRDHOST_FLAG_EXPORTING_DONT_SEND;
            info("disabled exporting of host '%s' for instance '%s'", host_name, instance->config.name);
        }
    }

    if (likely(*flags & RRDHOST_FLAG_EXPORTING_SEND))
        return 1;
    else
        return 0;
}

/**
 * Check if the connector instance should export the chart
 *
 * @param instance an exporting connector instance.
 * @param st a chart.
 * @return Returns 1 if the connector instance should export the chart
 */
int rrdset_is_exportable(struct instance *instance, RRDSET *st)
{
#ifdef NETDATA_INTERNAL_CHECKS
    RRDHOST *host = st->rrdhost;
#endif

    // Do not export anomaly rates charts.
    if (st->state && st->state->is_ar_chart)
        return 0;

    if (st->exporting_flags == NULL)
        st->exporting_flags = callocz(instance->engine->instance_num, sizeof(size_t));

    RRDSET_FLAGS *flags = &st->exporting_flags[instance->index];

    if(unlikely(*flags & RRDSET_FLAG_EXPORTING_IGNORE))
        return 0;

    if(unlikely(!(*flags & RRDSET_FLAG_EXPORTING_SEND))) {
        // we have not checked this chart
        if(simple_pattern_matches(instance->config.charts_pattern, st->id) || simple_pattern_matches(instance->config.charts_pattern, st->name))
            *flags |= RRDSET_FLAG_EXPORTING_SEND;
        else {
            *flags |= RRDSET_FLAG_EXPORTING_IGNORE;
            debug(D_EXPORTING, "EXPORTING: not sending chart '%s' of host '%s', because it is disabled for exporting.", st->id, host->hostname);
            return 0;
        }
    }

    if(unlikely(!rrdset_is_available_for_exporting_and_alarms(st))) {
        debug(D_EXPORTING, "EXPORTING: not sending chart '%s' of host '%s', because it is not available for exporting.", st->id, host->hostname);
        return 0;
    }

    if(unlikely(st->rrd_memory_mode == RRD_MEMORY_MODE_NONE && !(EXPORTING_OPTIONS_DATA_SOURCE(instance->config.options) == EXPORTING_SOURCE_DATA_AS_COLLECTED))) {
        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));
        return 0;
    }

    return 1;
}