0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-17 11:12:42 +00:00

New alarm entities ()

Co-authored-by: Joel Hans <joel.g.hans@gmail.com>
Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud>
This commit is contained in:
thiagoftsm 2020-10-20 09:00:14 +00:00 committed by GitHub
parent 7c33c4c70f
commit 6b2ffc355a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 115 additions and 6 deletions

View file

@ -108,10 +108,22 @@ static void rrdsetcalc_link(RRDSET *st, RRDCALC *rc) {
}
}
static inline int rrdcalc_test_additional_restriction(RRDCALC *rc, RRDSET *st){
if (rc->module_match && !simple_pattern_matches(rc->module_pattern, st->module_name))
return 0;
if (rc->plugin_match && !simple_pattern_matches(rc->plugin_pattern, st->plugin_name))
return 0;
return 1;
}
static inline int rrdcalc_is_matching_this_rrdset(RRDCALC *rc, RRDSET *st) {
if( (rc->hash_chart == st->hash && !strcmp(rc->chart, st->id)) ||
(rc->hash_chart == st->hash_name && !strcmp(rc->chart, st->name)))
return 1;
if(((rc->hash_chart == st->hash && !strcmp(rc->chart, st->id)) ||
(rc->hash_chart == st->hash_name && !strcmp(rc->chart, st->name))) &&
rrdcalc_test_additional_restriction(rc, st)) {
return 1;
}
return 0;
}
@ -564,6 +576,10 @@ void rrdcalc_free(RRDCALC *rc) {
simple_pattern_free(rc->spdim);
freez(rc->labels);
simple_pattern_free(rc->splabels);
freez(rc->module_match);
simple_pattern_free(rc->module_pattern);
freez(rc->plugin_match);
simple_pattern_free(rc->plugin_pattern);
freez(rc);
}

View file

@ -45,6 +45,13 @@ struct rrdcalc {
char *chart; // the chart id this should be linked to
uint32_t hash_chart;
char *plugin_match; //the plugin name that should be linked to
SIMPLE_PATTERN *plugin_pattern;
char *module_match; //the module name that should be linked to
SIMPLE_PATTERN *module_pattern;
char *source; // the source of this alarm
char *units; // the units of the alarm
char *info; // a short description of the alarm

View file

@ -44,6 +44,19 @@ static int rrdcalctemplate_is_there_label_restriction(RRDCALCTEMPLATE *rt, RRDH
return ret;
}
static inline int rrdcalctemplate_test_additional_restriction(RRDCALCTEMPLATE *rt, RRDSET *st) {
if (rt->family_pattern && !simple_pattern_matches(rt->family_pattern, st->family))
return 0;
if (rt->module_pattern && !simple_pattern_matches(rt->module_pattern, st->module_name))
return 0;
if (rt->plugin_pattern && !simple_pattern_matches(rt->plugin_pattern, st->plugin_name))
return 0;
return 1;
}
// RRDCALCTEMPLATE management
/**
* RRDCALC TEMPLATE LINK MATCHING
@ -51,9 +64,9 @@ static int rrdcalctemplate_is_there_label_restriction(RRDCALCTEMPLATE *rt, RRDH
* @param rt is the template used to create the chart.
* @param st is the chart where the alarm will be attached.
*/
void rrdcalctemplate_link_matching_test(RRDCALCTEMPLATE *rt, RRDSET *st, RRDHOST *host ) {
if(rt->hash_context == st->hash_context && !strcmp(rt->context, st->context)
&& (!rt->family_pattern || simple_pattern_matches(rt->family_pattern, st->family))) {
void rrdcalctemplate_link_matching_test(RRDCALCTEMPLATE *rt, RRDSET *st, RRDHOST *host) {
if(rt->hash_context == st->hash_context && !strcmp(rt->context, st->context) &&
rrdcalctemplate_test_additional_restriction(rt, st) ) {
if (!rrdcalctemplate_is_there_label_restriction(rt, host)) {
RRDCALC *rc = rrdcalc_create_from_template(host, rt, st->id);
if (unlikely(!rc))
@ -92,6 +105,12 @@ inline void rrdcalctemplate_free(RRDCALCTEMPLATE *rt) {
freez(rt->family_match);
simple_pattern_free(rt->family_pattern);
freez(rt->plugin_match);
simple_pattern_free(rt->plugin_pattern);
freez(rt->module_match);
simple_pattern_free(rt->module_pattern);
freez(rt->name);
freez(rt->exec);
freez(rt->recipient);

View file

@ -21,6 +21,12 @@ struct rrdcalctemplate {
char *family_match;
SIMPLE_PATTERN *family_pattern;
char *plugin_match;
SIMPLE_PATTERN *plugin_pattern;
char *module_match;
SIMPLE_PATTERN *module_pattern;
char *source; // the source of this alarm
char *units; // the units of the alarm
char *info; // a short description of the alarm

View file

@ -60,6 +60,8 @@ Netdata parses the following lines. Beneath the table is an in-depth explanation
| [`on`](#alarm-line-on) | yes | The chart this alarm should attach to. |
| [`os`](#alarm-line-os) | no | Which operating systems to run this chart. |
| [`hosts`](#alarm-line-hosts) | no | Which hostnames will run this alarm. |
| [`plugin`](#alarm-line-plugin) | no | Restrict an alarm or template to only a certain plugin. |
| [`module`](#alarm-line-module) | no | Restrict an alarm or template to only a certain module. |
| [`families`](#alarm-line-families) | no | Restrict a template to only certain families. |
| [`lookup`](#alarm-line-lookup) | yes | The database lookup to find and process metrics for the chart specified through `on`. |
| [`calc`](#alarm-line-calc) | yes (see above) | A calculation to apply to the value found via `lookup` or another variable. |
@ -150,6 +152,31 @@ begin with `redis`.
hosts: server1 server2 database* !redis3 redis*
```
#### Alarm line `plugin`
The `plugin` line filters which plugin within the context this alarm should apply to. The value is a space-separated
list of [simple patterns](/libnetdata/simple_pattern/README.md). For example,
you can create a filter for an alarm that applies specifically to `python.d.plugin`:
```yaml
plugin: python.d.plugin
```
The `plugin` line is best used with other options like `module`. When used alone, the `plugin` line creates a very
inclusive filter that is unlikely to be of much use in production. See [`module`](#alarm-line-module) for a
comprehensive example using both.
#### Alarm line `module`
The `module` line filters which module within the context this alarm should apply to. The value is a space-separated
list of [simple patterns](/libnetdata/simple_pattern/README.md). For
example, you can create an alarm that applies only on the `isc_dhcpd` module started by `python.d.plugin`:
```yaml
plugin: python.d.plugin
module: isc_dhcpd
```
#### Alarm line `families`
The `families` line, used only alongside templates, filters which families within the context this alarm should apply

View file

@ -10,6 +10,8 @@
#define HEALTH_HOST_KEY "hosts"
#define HEALTH_OS_KEY "os"
#define HEALTH_FAMILIES_KEY "families"
#define HEALTH_PLUGIN_KEY "plugin"
#define HEALTH_MODULE_KEY "module"
#define HEALTH_LOOKUP_KEY "lookup"
#define HEALTH_CALC_KEY "calc"
#define HEALTH_EVERY_KEY "every"
@ -485,6 +487,8 @@ static int health_readfile(const char *filename, void *data) {
hash_on = 0,
hash_host = 0,
hash_families = 0,
hash_plugin = 0,
hash_module = 0,
hash_calc = 0,
hash_green = 0,
hash_red = 0,
@ -510,6 +514,8 @@ static int health_readfile(const char *filename, void *data) {
hash_os = simple_uhash(HEALTH_OS_KEY);
hash_host = simple_uhash(HEALTH_HOST_KEY);
hash_families = simple_uhash(HEALTH_FAMILIES_KEY);
hash_plugin = simple_uhash(HEALTH_PLUGIN_KEY);
hash_module = simple_uhash(HEALTH_MODULE_KEY);
hash_calc = simple_uhash(HEALTH_CALC_KEY);
hash_lookup = simple_uhash(HEALTH_LOOKUP_KEY);
hash_green = simple_uhash(HEALTH_GREEN_KEY);
@ -811,6 +817,20 @@ static int health_readfile(const char *filename, void *data) {
rc->labels = simple_pattern_trim_around_equal(value);
rc->splabels = simple_pattern_create(rc->labels, NULL, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_plugin && !strcasecmp(key, HEALTH_PLUGIN_KEY)) {
freez(rc->plugin_match);
simple_pattern_free(rc->plugin_pattern);
rc->plugin_match = strdupz(value);
rc->plugin_pattern = simple_pattern_create(rc->plugin_match, NULL, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_module && !strcasecmp(key, HEALTH_MODULE_KEY)) {
freez(rc->module_match);
simple_pattern_free(rc->module_pattern);
rc->module_match = strdupz(value);
rc->module_pattern = simple_pattern_create(rc->module_match, NULL, SIMPLE_PATTERN_EXACT);
}
else {
error("Health configuration at line %zu of file '%s' for alarm '%s' has unknown key '%s'.",
line, filename, rc->name, key);
@ -835,6 +855,20 @@ static int health_readfile(const char *filename, void *data) {
rt->family_match = strdupz(value);
rt->family_pattern = simple_pattern_create(rt->family_match, NULL, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_plugin && !strcasecmp(key, HEALTH_PLUGIN_KEY)) {
freez(rt->plugin_match);
simple_pattern_free(rt->plugin_pattern);
rt->plugin_match = strdupz(value);
rt->plugin_pattern = simple_pattern_create(rt->plugin_match, NULL, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_module && !strcasecmp(key, HEALTH_MODULE_KEY)) {
freez(rt->module_match);
simple_pattern_free(rt->module_pattern);
rt->module_match = strdupz(value);
rt->module_pattern = simple_pattern_create(rt->module_match, NULL, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_lookup && !strcasecmp(key, HEALTH_LOOKUP_KEY)) {
health_parse_db_lookup(line, filename, value, &rt->group, &rt->after, &rt->before,
&rt->update_every, &rt->options, &rt->dimensions, &rt->foreachdim);