Add `charts` to templates (#11054)
Add new entities to Netdata templates.
thiagoftsm committed
Apr 28, 2021 at 23:32 UTC
e1b409efd10491b281e39f5637a08fb7b542866d
4 files changed
+35
database/rrdcalctemplate.c
+8
@@ -45,6 +45,11 @@ static int rrdcalctemplate_is_there_label_restriction(RRDCALCTEMPLATE *rt, RRDH
45
}
46
47
static inline int rrdcalctemplate_test_additional_restriction(RRDCALCTEMPLATE *rt, RRDSET *st) {
48
+ if (rt->charts_pattern &&
49
+ !(simple_pattern_matches(rt->charts_pattern, st->id) ||
50
+ simple_pattern_matches(rt->charts_pattern, st->name)))
51
+ return 0;
52
+
53
if (rt->family_pattern && !simple_pattern_matches(rt->family_pattern, st->family))
54
return 0;
55
@@ -111,6 +116,9 @@ inline void rrdcalctemplate_free(RRDCALCTEMPLATE *rt) {
116
freez(rt->module_match);
117
simple_pattern_free(rt->module_pattern);
118
119
+ freez(rt->charts_match);
120
+ simple_pattern_free(rt->charts_pattern);
121
+
122
freez(rt->name);
123
freez(rt->exec);
124
freez(rt->recipient);
database/rrdcalctemplate.h
+3
@@ -31,6 +31,9 @@ struct rrdcalctemplate {
31
char *module_match;
32
SIMPLE_PATTERN *module_pattern;
33
34
+ char *charts_match;
35
+ SIMPLE_PATTERN *charts_pattern;
36
+
37
char *source; // the source of this alarm
38
char *units; // the units of the alarm
39
char *info; // a short description of the alarm
health/REFERENCE.md
+14
@@ -62,6 +62,7 @@ Netdata parses the following lines. Beneath the table is an in-depth explanation
62
| [`hosts`](#alarm-line-hosts) | no | Which hostnames will run this alarm. |
63
| [`plugin`](#alarm-line-plugin) | no | Restrict an alarm or template to only a certain plugin. |
64
| [`module`](#alarm-line-module) | no | Restrict an alarm or template to only a certain module. |
65
+| [`charts`](#alarm-line-charts) | no | Restrict an alarm or template to only certain charts. |
66
| [`families`](#alarm-line-families) | no | Restrict a template to only certain families. |
67
| [`lookup`](#alarm-line-lookup) | yes | The database lookup to find and process metrics for the chart specified through `on`. |
68
| [`calc`](#alarm-line-calc) | yes (see above) | A calculation to apply to the value found via `lookup` or another variable. |
@@ -177,6 +178,19 @@ plugin: python.d.plugin
178
module: isc_dhcpd
179
```
180
181
+#### Alarm line `charts`
182
+
183
+The `charts` line filters which chart this alarm should apply to. It is only available on entities using the
184
+[`template`](#alarm-line-alarm-or-template) line.
185
+The value is a space-separated list of [simple patterns](/libnetdata/simple_pattern/README.md). For
186
+example, a template that applies to `disk.svctm` (Average Service Time) context, but excludes the disk `sdb` from alarms:
187
+
188
+```yaml
189
+template: disk_svctm_alarm
190
+ on: disk.svctm
191
+ charts: !*sdb* *
192
+```
193
+
194
#### Alarm line `families`
195
196
The `families` line, used only alongside templates, filters which families within the context this alarm should apply
health/health_config.c
+10
@@ -12,6 +12,7 @@
12
#define HEALTH_FAMILIES_KEY "families"
13
#define HEALTH_PLUGIN_KEY "plugin"
14
#define HEALTH_MODULE_KEY "module"
15
+#define HEALTH_CHARTS_KEY "charts"
16
#define HEALTH_LOOKUP_KEY "lookup"
17
#define HEALTH_CALC_KEY "calc"
18
#define HEALTH_EVERY_KEY "every"
@@ -493,6 +494,7 @@ static int health_readfile(const char *filename, void *data) {
494
hash_families = 0,
495
hash_plugin = 0,
496
hash_module = 0,
497
+ hash_charts = 0,
498
hash_calc = 0,
499
hash_green = 0,
500
hash_red = 0,
@@ -523,6 +525,7 @@ static int health_readfile(const char *filename, void *data) {
525
hash_families = simple_uhash(HEALTH_FAMILIES_KEY);
526
hash_plugin = simple_uhash(HEALTH_PLUGIN_KEY);
527
hash_module = simple_uhash(HEALTH_MODULE_KEY);
528
+ hash_charts = simple_uhash(HEALTH_CHARTS_KEY);
529
hash_calc = simple_uhash(HEALTH_CALC_KEY);
530
hash_lookup = simple_uhash(HEALTH_LOOKUP_KEY);
531
hash_green = simple_uhash(HEALTH_GREEN_KEY);
@@ -945,6 +948,13 @@ static int health_readfile(const char *filename, void *data) {
948
rt->module_match = strdupz(value);
949
rt->module_pattern = simple_pattern_create(rt->module_match, NULL, SIMPLE_PATTERN_EXACT);
950
}
951
+ else if(hash == hash_charts && !strcasecmp(key, HEALTH_CHARTS_KEY)) {
952
+ freez(rt->charts_match);
953
+ simple_pattern_free(rt->charts_pattern);
954
+
955
+ rt->charts_match = strdupz(value);
956
+ rt->charts_pattern = simple_pattern_create(rt->charts_match, NULL, SIMPLE_PATTERN_EXACT);
957
+ }
958
else if(hash == hash_lookup && !strcasecmp(key, HEALTH_LOOKUP_KEY)) {
959
health_parse_db_lookup(line, filename, value, &rt->group, &rt->after, &rt->before,
960
&rt->update_every, &rt->options, &rt->dimensions, &rt->foreachdim);