Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Realization of automatic Discovery, automatic Registration and self-defined Monitoring of Zabbix

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

I. automatic discovery and automatic registration

There are three main types of Zabbix discoveries:

1) automatic network discovery of Zabbix

Zabbix provides very advantageous and flexible automatic network discovery capabilities. Through network discovery, you can accelerate Zabbix deployment, simplify management, and use Zabbix in a changing environment without requiring too much management

Zabbix network discovery is based on the following information:

1) automatic discovery of IP segments

2) available external services (FTP, SSH, WEB, TCP, etc.)

3) receive information from Zabbix client

4) receive information from SNMP client

1) the principle of automatic discovery

Network discovery mainly consists of two steps: discovery and action.

Zabbix periodically scans the IP address range defined in network discovery rules. Configure your own inspection frequency according to each rule. Each rule defines a collection of service checks for the specified IP segment.

The action is to make relevant settings for the discovered host. Common actions include adding hosts, deleting hosts, enabling hosts, deactivating hosts, adding hosts to a host group, discovery notification, and so on.

2) configure network discovery rules

As shown in the figure:

To sum up, this field discovers the meaning of the rule: zabbix automatically scans all IP addresses in the IP address fields 192.168.1.1 to 192.168.1.254 to connect to port 10050 of these IP, and then uses the "system.uname" key to see if data can be obtained, and if data can be obtained, the host is added to the auto-discovery rule.

After the auto-discovery rule is added, you can then add the auto-discovery action, as shown in the figure:

After the above operations, the automatic discovery configuration of zabbix has been completed, and in a moment, qualified hosts will be automatically added to the zabbix web.

2) automatic registration of active clients

The auto-registration feature is mainly used for Agent to actively and automatically register with Server. It has the same function as the previous network auto-discovery, but this function is more suitable for a specific environment. When a condition is unknown (such as the IP address field on the Agent side, the operating system version of the zabbix web side, and so on), Agent can still automatically add the host to the server when it requests the server. Such as monitoring in the cloud environment. In a cloud environment, IP allocation is random, and this feature can well solve similar problems.

There are two steps to configure automatic registration of active clients, as follows:

1) the client modifies the profile

Open the client configuration file and modify the configuration as follows:

[root@agent ~] # vim / etc/zabbix/zabbix_agentd.confServer=192.168.1.10 / / set the IP address of the zabbix server in the passive mode ServerActive=192.168.1.10 / / set the IP address of the zabbix server in the active mode Hostname=192.168.1.8HostMetadata= linux zabbix,lzj// sets two metadata, one declared as the linux server, one writes a common string

An automatic registration request occurs each time the client sends a refresh active check request to the server. The delay of the request is specified in the "RefreshActiveChecks" parameter in the configuration file in the client. The first request will be sent immediately after the client restarts.

2) configure network auto-registration rules

As shown in the figure:

After the above operations, the automatic discovery registration of zabbix has been completed, and in a moment, qualified hosts will be automatically added to the zabbix web.

3) low-level discovery Low-level discovery (LLD)

In Zabbix, three off-the-shelf types of data item discovery are supported, namely:

1) File system discovery

2) Network interface discovery

3) SNMP OID discovery

4) CPU core and state

The LLD key that comes with zabbix is as follows:

1) vfs.fs.discovery / / is suitable for zabbix agent monitoring.

2) snmp.discovery / / is suitable for SNMP agent monitoring.

3) net.if.discovery / / is suitable for zabbix agent monitoring.

4) system.cpu.discovery / / is suitable for zabbix agent monitoring.

You can use the zabbix_get tool to obtain the data obtained by key. For snmp, it cannot be verified by the zabbix_get tool and can only be configured and used in the web page.

For example:

[root@zabbix ~] # zabbix_get-s 192.168.1.8-k net.if.discovery {"data": [{"{# IFNAME}": "lo"}, {"{# IFNAME}": "virbr0-nic"}, {"{# IFNAME}": "virbr0"}, {"{# IFNAME}": "ens33"}]}

Where {# IFNAME} is a macro variable that returns the names of all network cards in the system. Macro variables can be defined on hosts, templates, and globally. Macro variables are capitalized. Using macro variables, you can make zabbix more powerful.

In LLD, common built-in macro variables are as follows:

1) {# FSNAME} indicates the file system name

2) {# FSTYPE} indicates the file system type

3) {# IFNAME} indicates the name of the network card

4) {# SNMPINDEX} will get the last value in OID

There are many kinds of macro levels, and the order of priority is as follows:

The macro priority at the host level is the highest.

Macros in the first-level template

Macros in the second-level template

Global-level macros

Therefore, the order in which zabbix looks for macros is as follows: first look for macros at the host level, and if there is no macro setting at the host level, then zabbix will go to the template to see if there are macros. If it is not in the template, it will look for macros that use the global. If no macros are found at all levels, macros are not used.

II. Zabbix custom monitoring items

Sometimes when the project we monitor is not defined in the zabbix predefined key, we can monitor the project item we require by writing zabbix user parameters. Figuratively speaking, UserParameters in the zabbix proxy configuration file is equivalent to a script that acquires the value to be monitored, then writes the relevant script or command to UserParameters, and then zabbix server reads the return value in the configuration file and returns it to the user by processing the front end.

1) enable the UserParameters instruction [root@agent ~] # vim / etc/zabbix/zabbix_agentd.confUnsafeUserParameters=1// on the zabbix side to enable the custom item function on the agent side. After setting this parameter to 1, you can use the UserParameters directive.

UserParameters is used to customize itme. The syntax format is:

UserParameters=,//UserParameters: keyword; / / key: customize the key name for the user; / / command: the command or script to run

A simple example is as follows:

UserParameters=ping, echo 1 echo / agent will always return 1 when we add the key of item to ping on the server side 2) ask key to accept parameters

The method of getting key to accept parameters also gives item more flexibility when added. For example, the system defines key:

Vm.memory.size [] / / where the mode mode is the parameter to be accepted by the user. If we enter "free", the remaining size of memory will be returned. If we enter "userd", the returned memory will be the size that has been used.

The syntax is as follows:

UserParameters=key [*], where the value of key must be unique in the host system, where * represents the parameters accepted in the command, and command represents the command, that is, the executable command on the client system

For example:

UserParameters=ping [*], echo $1 aaa / if you execute ping [0], you will consistently return '0percent. If you execute ping [aaa], you will always return' aaa' III, active mode and passive mode of zabbix.

By default, zabbix server grabs data directly on each agent, which is passive mode and default way for zabbix agent to fetch data. However, when the number of zabbix server monitoring hosts is too large, and the zabbix server side grabs the data on the agent, the zabbix server will have serious performance problems. The main manifestations are as follows:

1) web interface operation is stuttered, prone to 502 errors; 2) layer breakage in monitoring graphics; 3) monitoring alarm is not timely

Therefore, optimization is mainly carried out from two aspects, namely:

1) deploy multiple zabbix proxy modes for distributed monitoring; 2) adjust zabbix agentd to active mode

Zabbix agentd active mode means that the agentd side actively reports its collected data to zabbix server, so that zabbix server will have a lot of free time. Here is how to enable the active mode of agent.

1) enable the active mode of agent

Configuration on zabbix agent side:

[root@agent ~] # vim / etc/zabbix/zabbix_agentd.confServerActive=192.168.1.10 / / defines which host the Hostname=192.168.1.8 / / name collected by the agent side is sent to. The default value of StartAgents=1 / / StartAgents is 3 when the host name is added to the web page. If you need to turn off the passive mode, you can set the value to 0. After turning off the passive mode, port 10050 on the Aent side is also closed. In order to be compatible with passive mode, the value is not set to 0. if active mode is used in the first place, it is recommended to set the value to 0 and turn off passive mode.

Configuration on the zabbix server side

If agent enables active data sending mode, you need to do the following:

[root@zabbix ~] # vim / usr/local/zabbix/etc/zabbix_server.confStartPollers=10 / / reduce the zabbix server active data collection process by some StartTrappers=200 / / will be responsible for handling the data pushed by agent to expand the process

Adjust template

Because the mode of collecting data has changed, it is necessary to change the monitoring type of all monitoring items from "zabbix client" to "zabbix client (active)".

After the above operation, the active mode switch is completed, and after adjustment, it can be found that the load on the zabbix server side should be reduced a lot, and the problem of stutter and graphic layer fracture in operation will be solved!

-this is the end of this article. Thank you for reading-

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report