📜 ⬆️ ⬇️

Zabbix 3.4: Macros in time intervals

Hey. We continue to cover the innovations of Zabbix 3.4. Today we will talk about the use of macros in the update intervals and other time periods.



A few words about macros


User macros are a long-established mechanism used in Zabbix everywhere and giving the monitoring system the flexibility it needs. In essence, these are variables that you can assign with a global level of visibility, pattern or host. The use of macros is strongly encouraged and recommended, for example, in templates, which makes them customizable in other environments and other users.
User macros look like this, you probably already met them:


{$MACRO} 

Interval update and storage history


Zabbix allows you to flexibly customize the time for polling metrics: each metric can have its own interval.



Updates for each metric can also be "flexible" (see User intervals ), and therefore take place on a specific schedule ("once a day at night" or "at 9:00 am on weekdays").


Similarly, we can determine the storage time of history and trends for each data element separately.


This subtlety of tuning is not always needed, so the use of macros gives a couple of new ideas for setting up these parameters.


Use cases


Update intervals and storage duration of the collected data


First, the metric update intervals (both regular and custom intervals), which are discussed above, now support custom macros. Secondly, you can use macros in the history and trend storage intervals. In the end, it looks like this:



Simply set the values ​​of these macros globally, and then reassign at the template or host level, if necessary:



In general, for update intervals, you can create a small global set of macros, which are then used by default for all new data items , depending on their type and importance. For example:



This will allow you not to spend time thinking each time, “do I want to collect this metric once 60 or once every 61 seconds? Or maybe once every 5 minutes will be enough?”, But just use the rules adopted on your server and the draft to collect and store items data recorded in global macros. Although, perhaps, this option is not suitable for everyone :)


In low level detection


Macro context is also supported, which can be very useful, for example, with LLD .
Imagine that we collect network interface traffic on multiple devices. In order not to load Zabbix, we would like to do this as follows:



First, let's define global macros {$ DELAY_IF}, {$ HISTORY_IF}, {$ TREND_IF}:



Then we use them in the prototype of the data element of the interface, but already with the context (in this case, it will be the name of the interface ifName):



Already at the host level, we indicate the new value of the macro with the context for the key interface (for example, take Gi0 / 0.114):



Now let's look at the refresh rate and retention time for various interfaces in the “Latest Data”. As you can see, our very important Gi0 / 0.114 now has its own rules for storage and collection:



If we want to change the total interval or increase the frequency of polling or the storage time of another interface - we just need to reassign the macros at the host level. There is no need to change the template, prototype and wait for detection - everything will apply immediately. In fact, even write access to the template is not required.


Where else?


And macros can now be used in other situations where it was necessary to specify the time or period. For example, in the actions:



or, via the macro, specify the availability time of the engineer for automatic notifications:



The exact list of places where macros can be used can be found here .


Eventually


New macro features in 3.4 open up a couple of good opportunities: on the one hand, for more fine-tuning (for LLD), and on the other hand, for centralizing and managing the polling time and storage. And by the way, in the time intervals there appeared support for the suffixes s, m, h, d, w - a trifle, but conveniently :)


See you!


PS Article is also available in our blog in English.


')

Source: https://habr.com/ru/post/344492/


All Articles