In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to understand Zabbix monitoring. The editor thinks it is practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
Chapter III Zabbix Monitoring methods
Some people say that any monitoring task can be accomplished through Zabbix, only what you can't think of, but nothing can't be monitored. Is that true? When you learn about the various monitoring methods provided by Zabbix through this chapter, you will find that this is true.
The monitoring method mentioned here is actually the type of monitoring item selected when configuring monitoring items in Zabbix. In order to meet the needs of various application scenarios, Zabbix provides a variety of ways to help you better complete the monitoring task.
The monitoring methods provided in Zabbix 3.0 include:
Active agents
Passive agents
Extending agents
Simple checks
SNMP agents
Zabbix Internal checks
Zabbix trapper
IPMI agents
JMX agents
External checks
Database monitoring
SSH agents
Telnet agents
SNMP Traps
Aggregate checks
Calculated checks
3.1 Active agents
There are two ways to create monitoring items using Zabbix agent, namely Active (active) agent and Passive (passive) agent.
In Active agent mode, after Zabbix agent is started, the communication between agent and Zabbix server is initialized, and a request for a list of monitoring items is sent to Zabbix server. After receiving the request, the server responds to the request issued by agent and sends the list of monitoring items to agent. The agent side communicates with Zabbix server regularly to ensure that the latest list of monitoring items is obtained. Agent queries the data of monitoring items according to the list of monitoring items and sends the results to Zabbixserver. The process is shown in figure 3-1 below.
Figure 3-1
To enable Active agent mode, you need to configure the ServerActive parameter in the zabbix_agentd.conf file to tell agent which servers can be contacted (the default port is 10051). By configuring the RefreshActiveChecks parameter, you can set how often the agent side asks server for the list of monitoring items. The default is 120 seconds. After the server side changes some settings related to the active agent monitoring item under the default settings, the server side needs 1 minute to refresh the configuration cache (through the parameter CacheUpdateFrequency setting in the server configuration file, the default is 60 seconds), and the agent needs to wait 2 minutes to know the change of the monitoring item. If querying the list of monitoring items from server fails (network problems or other reasons), the agent side will wait 1 minute before re-issuing the query request to server. Active agent also has its own cache, which can be set through BufferSend or BufferSize. The BufferSend parameter sets the time for monitoring item data to remain in the cache. The default is 5 seconds (which can be set to 3600). The BufferSize parameter sets the cache size of monitoring item data. The default is 100 (can be set to 65535).
To configure Active agent monitoring items:
1. After the Zabbix agent installation is complete, open the configuration file zabbix_agentd.conf.
2. Set the ServerActive parameter in the format of IP:port or DNS hostname: port. Here we can set multiple DNS hostnames or IP addresses for server or proxy, separated by commas.
3. Set the Hostname parameter, which must be unique and the same as the host name added in the Configuration-> Hosts page in Zabbixserver.
4. Verify that port 10051 of Zabbix server can be accessed.
5. Restart zabbix_agent (systemctlrestart zabbix-agent.service).
6. Check the agent log (tail-f/var/log/zabbix/zabbix_agentd.log).
7. Add active monitoring items (Configuration-- > Hosts-- > Items-- > Create item) to the host. Select the Type (type) of the monitoring item as Zabbix agent (active).
3.2 Passive agents
Passive agent provides us with a simple and easy method. According to the Update interval (data update interval) configured in the monitoring item, Zabbixserver or proxy periodically issues query requests to the CPU side, such as CPU load, disk usage space, and so on. Agent collects monitoring item data upon request and returns it to server or proxy. The whole process is a simple question and answer. I'll give you what value you want. From the agent point of view, it is a passive answer. This is shown in figure 3-2 below.
Figure 3-2
Recently, we have completed the recording and release of the video tutorial "zabbix 4.0", which is based on zabbix 4.2 and provides a comprehensive explanation of Zabbix. Welcome to watch. Course link: https://edu.51cto.com/sd/ce000
To configure Passive agent monitoring items:
1. Install Zabbix agent and open the configuration file zabbix_agentd.conf.
2. Set the Server parameter in the format of IP or DNS hostname. Here we can set multiple DNS hostnames or IP addresses for server or proxy, separated by commas.
3. Comment out the parameters ServerActive and Hostname, which are not needed in Passive agent mode. If you want to use active agent at the same time, these two parameters must be configured.
4. Verify that port 10050 on the agent side can be accessed.
5. Restart zabbix_agent (systemctlrestart zabbix-agent.service).
6. Check the agent log (tail-f/var/log/zabbix/zabbix_agentd.log).
7. Add passive monitoring items (Configuration-- > Hosts-- > Items-- > Create item) to the host. Select Zabbix agent as the Type (type) of the monitoring item.
3.3 Extending agents
Zabbix provides some standard monitoring items can use Key, when you add Zabbix agent monitoring items can choose to use, but in the actual environment these standard Key can not meet specific monitoring needs, in Zabbix can be extended using a variety of methods, one of which is to use UserParameter in the agent configuration file to expand.
By expanding the key of the monitoring item through the UserParameter parameter, a variety of monitoring requirements can be realized flexibly. The format of UserParameter defined in Zabbix is UserParameter=,.
To configure UserParameter:
1. Open the agent configuration file zabbix_agentd.conf.
2. Set UserParameter parameters. For example: UserParameter=mysql.threads,mysqladmin-u root-p status | cut-f3-d ":" | cut-f1murd "Q". This parameter returns the number of MySQL threads to the custom key:mysql.threads.
3. Save the configuration file and restart Zabbix agent service.
4. Add monitoring items to the Configuration-> Hosts-- > Items page of the Web frontend.
Set the monitor item name, such as MySQL Threads, in the u Name field.
Select Zabbix agent or Zabbix agent (active) in the u Type field.
Enter mysql.threads in the u Key field, which must be the same as defined in UserParameter.
Select Numeric (unsigned) in the u Type of Information field.
Select Decimal in u Data type.
U other configuration parameters remain unchanged. Click the Add button to save.
5. Monitoring-- > Latest data page to view the monitoring item MySQL Threads.
3.4 Simple checks
Simple checks in Zabbix is based on ICMP ping or port detection to determine whether the host is online or whether the service port can be connected properly. In this way, Zabbix agent does not need to be installed in the host. When we check the availability of the host or port, simplechecks returns a value of 1 or 0. When we test performance, it returns a floating-point number (for example, 0.02 seconds when testing the response time of ping), and returns 0 if the test fails.
In order to reduce network traffic and perform ICMP detection more efficiently, Zabbix uses a third-party tool, fping and fping6, to perform icmppingsec, icmpping and icmppingloss detection. Versions that depend on different distributions of linux are different. It is recommended to use fping 3.0 or above. When you need to install fping on a CentOS system, you can complete the installation by using the command yum install fping.
By default, 3 monitoring items for ICMP detection and 2 monitoring items for TCP/UDP connection detection are defined in Zabbix. They are:
Icmpping: the host returns 1 in response to ICMP ping, otherwise returns 0.
Icmppingloss: returns the percentage of lost ICMP ping packets.
Icmppingsec: returns the response time of ICMP ping in seconds. Returns 0 if the host does not respond (timeout reached). If the return value is less than 0.0001 seconds, the return value will be set to 0.0001.
Net.tcp.service / net.udp.service: returns 1 if the specified service on the host is running normally and can establish a TCP / UDP connection, otherwise 0 is returned.
Net.tcp.service.perf / net.udp.service.perf: returns the time, in seconds, used by the service connected to the specified TCP / UDP port. Returns 0.000000 if the service is not running.
Net.tcp.service and net.tcp.service.perf support most of the protocols we know, such as SSH, FTP, HTTP, and so on. These two projects are very useful. We can test the availability of a simple TCP handshake connection to a specific IP and port without any impact on the performance of the host or application.
Let's take a look at the usage of these items.
Icmpping
Format: Icmpping [,]. Where target is the host IP or DNS hostname; packets is the number of packets; interval is the interval between packets in microseconds; size is the size of packets in units of bytes;timeout timeout in microseconds. For example, icmpping [, 20pr 50256100], if you do not want to define target, packet, etc., you can write it as icmpping [, 4] without any parameters. As long as four packets have a response, the monitoring item will return 1.
Icmppingloss
Format: icmppingloss [,]. Where target is the host IP or DNS hostname; packets is the number of packets; interval is the interval between packets in microseconds; size is the size of packets in units of bytes;timeout timeout in microseconds.
Icmppingsec
Format: icmppingsec [,]. Where target is the host IP or DNS hostname; packets is the number of packets; interval is the interval between packets in microseconds; size is the size of packets in units of bytes;timeout timeout in microseconds.
Net.tcp.servic
Format: net.tcp.service [service,]. Where service is the name of the TCP protocol, such as ssh, ldap, smtp, ftp, http, pop, nntp, imap, Telnet, etc.; IP is the IP address or DNS hostname (default uses the IP or DNS hostname of the host that defines the monitoring item); port is the port number (default uses the service standard port number). For example: net.tcp.service [ftp,45]. Currently, the detection of encryption protocols is not supported, such as port 993 of IMAP or port 995 of POP, but we can use net.tcp.service [tcp,port] to detect them. Zabbix supports https and telnet since v2.0.
Net.tcp.service.perf
Format: net.tcp.service.perf [service,]. Where service is the name of the TCP protocol, such as ssh, ldap, smtp, ftp, http, pop, nntp, imap, Telnet, etc.; IP is the IP address or DNS hostname of the host (default uses the IP or DNS hostname that defines the monitor host); port is the port number (the service standard port number is used by default). For example: net.tcp.service.perf [ssh]. Currently, the detection of encryption protocols is not supported, such as IMAP on port 993or POP on port 995, but we can use net.tcp.service.perf [tcp,port] to detect them.
Net.udp.service
Format: net.udp.service [service,]. Where service is the name of the UDP protocol, for example: ntp;IP is the IP address or DNS hostname of the host (default uses the IP or DNS hostname that defines the monitor host), and port is the port number (the service standard port number is used by default). For example: net.udp.service [ntp,45], testing the availability of the NTP service on UDP port 45.
Net.udp.service.perf
Format: net.udp.service.perf [service,]. Where service is the name of the UDP protocol, for example: ntp;IP is the IP address or DNS hostname of the host (default uses the IP or DNS hostname that defines the monitor host), and port is the port number (the service standard port number is used by default). For example: net.udp.service.perf [ntp], which can detect the response time of the NTP service.
Simple checks is a simple and efficient monitoring method. Because it does not need to transmit complex monitoring data, it has the least impact on the overall network traffic when monitoring the availability of hundreds of hosts and services.
To configure Simple checks:
1. Create a new monitoring item (Configuration-- > Template-- > Items-- > Create item or Configuration-- > Host-- > Items-- > Create item).
2. On the monitoring item configuration page:
Fill in Name, for example: Check SSH port $3. ($3 is the third parameter {$SSH_PORT} in key).
Select Type as Simple check.
Fill in Key, for example: net.tcp.service [ssh, {$SSH_PORT}], {$SSH_PORT} is the defined macro.
Type of information Select Numeric.
Data type Select Decimal.
If necessary, you can fill in the name of a monitoring item group in NewApplication, such as ssh check.
Other configuration parameters can remain the same, click the Add button to save.
3. Monitoring-- > Latest data page to view monitoring items.
4.5 SNMP agents
When monitoring switches, routers, UPS and other devices, you have no way to monitor through Zabbixagent, because there is no way to install agent programs in these devices, but this does not mean that Zabbix can not monitor these devices. Using the standard SNMP protocol, you can easily achieve Zabbix monitoring of these devices.
SNMP (simple Network Management Protocol) is an application layer protocol of the TCP/IP protocol suite, which is widely used to monitor network devices (such as switches, routers, UPS, etc.). The SNMP agent that comes with the device is run in each monitored device. Zabbix uses the SNMP protocol to issue query instructions to the SNMP agent of the monitored device, and the query value is returned by SNMP agent.
Before setting up the SNMP agent monitor item, we need to determine the OID (SNMP object identifier). SNMP organizes managed objects in a tree, and managed objects are represented by OID, for example: 1.3.6.1.2.1.1.3 represents sysUpTime. Many manufacturers' products will be used in the actual environment, and the OID defined in each product is different, so before preparing to use SNMP agent to monitor the equipment, the manufacturer needs to provide the MIB file of the device. MIB file is based on SMI syntax definition of an OID in the OID tree location, data type, description and other information of the text file, if there is no MIB file, it is difficult to understand the meaning of a string of numbers.
To configure SNMP agent:
1. Make sure that net-snmp-utils is installed. If not, you can install it with the following command:
# yum install net-snmp-utils
If you are compiling source code to install Zabbix server, be sure to use the-- with-net-snmp option.
2. Add a new host to Zabbix server and fill in the SNMPInterface information, as shown in figure 3-3 below.
Figure 3-3
3. Use snmpwalk to check whether the value of OID can be obtained from the monitored device.
# snmpwalk-v 2c-cpublic 192.168.10.1 | more
Where-v 2c is the version of the SNMP protocol, and Zabbix supports SNMP v1, 2c, and 3. -c public is a community string. The result of executing the above command is returned, indicating that the monitored host can be connected and can be monitored using SNMP. We can further determine the value of OID.
# snmpget-v 2c-cpublic 192.168.10.1-On IF-MIB::ifInOctets.1
Return information: .1.3.6.1.2.2.2.1.10.1 = Counter32:1494804.
If you want to get the complete OID string, you can execute the following command.
# snmpget-v 2c-cpublic 192.168.10.1-Of IF-MIB::ifInOctets.1
Return information: .iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifInOctets.1= Counter32: 1566936.
4. Now create a new monitoring item:
Enter ifInOctets $1 in Name ($1 is the first parameter Port1 in Key).
Type chooses the correct version of SNMP, such as SNMPv2 agent.
Enter any name you want to use in Key, such as ifInOctets [Port1].
Host Interface uses the SNMP interface defined in the host.
Enter the OID returned in step 3 with the snmpget command in SNMP OID. No matter which format OID is used here, it is OK.
Fill in the community string in SNMP community.
Select Numeric (float) in Type of information.
Fill in Bytes in Units.
Select Delta (speed per seconds) in Store value.
Other parameters can remain the same, click the Add button to save.
As shown in figure 3-4 below.
Figure 3-4
5. Monitoring-- > Latest data page to view monitoring items.
3.6 Zabbix Internal checks
Zabbix Internal is mainly used to monitor the performance of Zabbixserver or proxy server itself. Zabbix Internal is calculated by Zabbix server or proxy server, and starting with Zabbix version 2.4, Zabbix Internal is processed even when the host is in maintenance state. Zabbix server does not rely on agent when dealing with Zabbix Internal, you only need to have the privileges of Super Admin.
Zabbix has preset templates for Zabbix server and proxy server in the system, and the names of templates are Template App Zabbix Server and Template App Zabbix Proxy.
To configure Zabbix Internal:
1. Create a new monitoring item (Configuration-- > Template-- > Items-- > Create item or Configuration-- > Host-- > Items-- > Create item).
Fill in the name of the monitoring item in Name.
Select Zabbix internal in Type.
Select (click the Select button on the right) zabbix [process,] in Key, where we use zabbix [process,poller,avg,busy].
Type of information Select Numeric (float).
Fill in% for Units.
Other parameters can be left as is, click the Add button to keep.
This is shown in figure 3-5 below.
Figure 3-5
2. Monitoring-- > Latest data page to view monitoring items.
3.7 Zabbix trapper
When Zabbix collects monitoring data using agent, IPMI, or SNMP, it sometimes times out because the script used in the monitoring item Key times out and cannot get the data. Therefore, Zabbix provides the monitoring mode of trapper, and the zabbix-sender tool can be used to actively send data from the monitored host to Zabbix server. In this way, there is no need to install Zabbix agent in the monitored host.
To configure Zabbix trapper:
1. First of all, we need to install the zabbix-sender program on the monitored host with the following installation command:
# yum installzabbix-sender
2. Create a monitoring item (Configuration-- > Template-- > Items-- > Create item or Configuration-- > Host-- > Items-- > Create item).
Fill in the monitoring item name in Name.
Select Zabbix trapper in Type.
Fill in the Key with the key name you want to use (for example: trapper.key).
Select the type of data to send to Zabbixserver in Type of information and Data type.
Allowed hosts can fill in the IP address or DNS hostname of the monitored host. If so, trapper only receives data from these hosts. Here you can set an IP address or DNS hostname, such as 192.168.10.22 or testtrapper.Zabbix.com. You can also set multiple IP addresses or DNS hostnames separated by commas, for example: 192.168.10.22192.168.10.23192.168.10.24 or testtrapper1.Zabbix.com, testtrapper2.Zabbix.com, testtrapper3.Zabbix.com.
Other parameters can remain the same, click the Add button to save.
This is shown in figure 3-6 below.
Figure 3-6
3. Run zabbix_sender-z-s-k-o in the monitored host. For example:
# zabbix_sender-z 192.168.10.102-s "trapper host"-k trapper.key-o 20
4. Monitoring-- > Latest data page to view monitoring items.
3.8 IPMI agents
IPMI (Intelligent PlatformManagement Interface) is an open standard hardware management interface specification, which defines a specific method for embedded management subsystem to communicate. At present, mainstream servers use remote control cards (such as Dell's DRAC, HP's ILO, etc.) to carry out remote control and management. Through IPMI, you can remotely boot, shut down, restart, remotely view the current running status of the server, install the operating system, and achieve out-of-band management. Zabbix server can monitor the server hardware directly through IPMI, even if the server is powered off.
If you are compiling and installing Zabbix and need to use IPMI agent in Zabbix, you need to compile with the-with-openipmi parameter.
Before using IPMI agent, we need to install IPMI-related tools on the host.
# yum install ipmitoolOpenIPMI OpenIPMI-libs
After the installation is complete, we can check the temperature:
# ipmitool sdr list | grepTemp
Ambient Temp | 23degrees C | ok
CPU 1 Temp | 45degrees C | ok
CPU 2 Temp | disabled | ns
CPU 3 Temp | disabled | ns
CPU 4 Temp | disabled | ns
Take a closer look at the details of CPU 1 Temp:
# ipmitool event "CPU 1Temp" list
Finding sensor CPU 1 Temp... Ok
Sensor States:
Lnr: Lower Non-Recoverable
Lcr: Lower Critical
Lnc: Lower Non-Critical
Unc: Upper Non-Critical
Ucr: Upper Critical
Unr: Upper Non-Recoverable
Next, we configure the management account of IPMI, which can be done through the remote control card management interface of the server or through the OpenIPMI tool.
Reset the administrator password, 2 is the ID of the root user.
# ipmitool user setpassword 2
Set the Zabbix user account. In the example, the user ID is 3. Make sure that ID 3 is not used by other users before setting it.
# ipmitool user set name 3 zabbix
Sets the Zabbix user password.
# ipmitool user setpassword 3
Password for user 3:
Password for user 3:
Authorization for Zabbix users.
# ipmitool channelsetaccess 1 3 link=on ipmi=on callin=on privilege=2
Enable Zabbix users.
# ipmitool user enable 3
Verify that the settings are correct.
# ipmitool channelgetaccess 1 3
Maximum User IDs: 15
Enabled User IDs: 2
User ID: 3
User Name: zabbix
Fixed Name: No
Access Available: call-in / callback
Link Authentication: enabled
IPMI Messaging: enabled
Privilege Level: USER
When you see the above information, it means that the Zabbix user has been created and Privilege Level is USER. But this account can not be accessed through the network, we need to authorize access.
# ipmitool lan set 1 authUSER MD5
Verify that the settings are correct.
# ipmitool lan print 1
Set in Progress: Set Complete
Auth Type Support: NONE MD5 PASSWORD
Auth Type Enable: Callback:
: User: MD5
: Operator:
: Admin: MD5
: OEM:
Now we use the Zabbix user to remotely query the status of the server.
# ipmitool-U Zabbix-H192.168.10.22-I lanplus sdr list | grep Temp
Ambient Temp | 23degrees C | ok
CPU 1 Temp | 45degrees C | ok
CPU 2 Temp | disabled | ns
CPU 3 Temp | disabled | ns
CPU 4 Temp | disabled | ns
Modify the zabbix_server.conf configuration file.
# vi zabbix_server.conf
StartIPMIPollers=5
Restart the Zabbix server service.
# systemctl restartzabbix-server
To configure IPMI checks:
1. On the Configuration-> Host page, click the host name in the Name column, such as Zabbix server, and add the IPMI interface configuration under the Host tag of the host configuration page, as shown in figure 3-7 below.
Figure 3-7
2. Configure the authentication algorithm, permission level, user name and password under the IPMI tag. This is shown in figure 3-8 below.
Figure 3-8
Click the Update button to save the configuration of the host.
4. Create a new monitoring item.
Fill in the monitoring item name in Name.
Select IPMI agent in Type.
Fill in the key name in Key, for example: CPU 1 Temp.
Select the IPMI interface in Host Interface.
Fill in CPU 1 Temp in IPMI Sensor.
Type of information Select Numeric (float)
Fill in ℃ in Units.
Other parameters can remain the same, click the Add button to save.
This is shown in figure 3-9 below.
Figure 3-9
5. Monitoring-- > Latest data page to view monitoring items.
3.9 JMX agents
Zabbix can monitor Java Application through JMX (Java Management Extensions), and Zabbix uses native Zabbix Java gateway, a Java daemon, to monitor JMX applications. When Zabbix wants to know the current data of a JMX counter, it only asks ZabbixJava gateway, while gateway queries the required data, all of which are done through the JMX management API.
When in use, a Java application does not need to install any other software, nor does it need to implement or extend new code to handle Zabbix queries. It only needs to set some parameters in the configuration file of the Java application to support remote JMX monitoring.
The main parameters are:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
For example:
Java\
-Dcom.sun.management.jmxremote\
-Dcom.sun.management.jmxremote.port=12345\
-Dcom.sun.management.jmxremote.authenticate=false\
-Dcom.sun.management.jmxremote.ssl=false\
-jar/usr/share/doc/openjdk-6-jre-headless/demo/jfc/Notepad/Notepad.jar
The above configuration defines that the Java program uses port 12345 to listen for connections from the local JMX and does not require authentication or encryption. If you want to access from another host, you need to configure the-Djava.rmi.server.hostname parameter.
In the real world, authentication and encryption need to be set up from a security point of view. The specific setting steps are as follows:
1. Enable authentication and specify a file that contains the password.
-Dcom.sun.management.jmxremote.authenticate=true
-Dcom.sun.management.jmxremote.password.file=/etc/java-6-penjdk/management/jmxremote.password
Contents of jmxremote.password file:
MonitorRole
ControlRole
2. Specify the profile of the user.
-Dcom.sun.management.jmxremote.access.file=/etc/java-6-penjdk/management/jmxremote.access
Contents of jmxremote.access file:
MonitorRole readonly
ControlRole readwrite
3. Enable SSL.
-Dcom.sun.management.jmxremote.ssl=true
Bind the following parameters:
-Djavax.net.ssl.keyStore=
-Djavax.net.ssl.keyStorePassword=
-Djavax.net.ssl.trustStore=
-Djavax.net.ssl.trustStorePassword=
-Dcom.sun.management.jmxremote.ssl.need.client.auth=true
The complete example is as follows:
Java\
-Djava.rmi.server.hostname=192.168.3.14\
-Dcom.sun.management.jmxremote\
-Dcom.sun.management.jmxremote.port=12345\
-Dcom.sun.management.jmxremote.authenticate=true\
-Dcom.sun.management.jmxremote.password.file=/etc/java-6-openjdk/management/jmxremote.password\
-Dcom.sun.management.jmxremote.access.file=/etc/java-6-openjdk/management/jmxremote.access\
-Dcom.sun.management.jmxremote.ssl=true\
-Djavax.net.ssl.keyStore=\
-Djavax.net.ssl.keyStorePassword=\
-Djavax.net.ssl.trustStore=\
-Djavax.net.ssl.trustStorePassword=\
-Dcom.sun.management.jmxremote.ssl.need.client.auth=true\
-jar/usr/share/doc/openjdk-6-jre-headless/demo/jfc/Notepad/Notepad.jar
The-D parameter needs to be written to the startup file of your application or application server. After completing the above configuration, your startup file will contain some sensitive contents (keyStore and trustStore password), so you need to protect your startup file.
In order to use JMX agent in Zabbix server, you also need to install Java gateway in Zabbix server.
# yum installzabbix-java-gateway
# systemctl enablezabbix-java-gateway
# systemctl startzabbix-java-gateway
If you are compiling source code to install Zabbix server, be sure to use the-- enable-java option.
Configure in the zabbix_server.conf file.
# vi zabbix_server.conf
Java gateway = 127.0.0.1
Java Gateway Port = 10052
Start Java pollers = 5
Don't forget to restart the Zabbixserver service after modifying the zabbix_server.conf file.
# systemctl restartzabbix-server
Next, we can configure a JMX agent monitoring item, as follows:
1. On the Configuration-> Host page, click the host name in the Name column, such as Zabbix server, and add the JMX interface configuration under the Host tag of the host configuration page, as shown in figure 3-10 below.
Figure 3-10
Click the Update button to save the configuration of the host.
3. Create a new monitoring item.
Fill in the monitoring item name in Name.
Select JMX agent in Type.
Enter the project you want to monitor in Key in the format of jmx [,]. For example:
Jmx ["java.lang:type=Memory", "HeapMemoryUsage.used"]
Select the JMX interface in Host interface.
For security after installing the JMX console, we usually set a user name and password to log in to the console, which is supported in Zabbix. Just enter it in User name and Password.
Type of information Select Numeric (unsigned).
Select Decimal in Data type.
Set the unit in Unit, such as: B.
Other parameters can remain the same, click the Add button to save.
This is shown in figure 3-11 below.
Figure 3-11
4. Monitoring-- > Latest data page to view monitoring items.
If you want to monitor monitoring items of type Boolean that return true or false, you can specify Typeof information as Numeric (unsigned) and Data type as Boolean,Zabbix server will save the value of this Boolean to 1 or 0.
Only one Javagateway can be installed in Zabbix server, and you can install one Javagateway in each proxyserver if you want.
If you encounter problems, you can check JMX's log file: / var/log/zabbix_java_gateway.log.
When setting up the Key of JMX agent, you need to be aware of the following:
The attribute name contains a dot delimiter (.), such as all.pen, which you need to escape with\, for example: jmx [com.example:Type=Test,all\ .pen.color]
The property name contains a backslash (\). You need to use two\\, for example: jmx [com.example:Type=Test,c:\\ utility]
The object name or attribute name contains spaces or commas, which need to be enclosed in two double quotes ("), for example: jmx [com.example:type=Hello," c:\\ documentsand settings "]
Through the External checks monitoring mode, you can execute scripts or binaries on Zabbixserver to collect monitoring data, which does not require the installation of agent in the monitored device.
Before using this approach, you need to define the path of the script or program in the zabbix-server.conf configuration file and set the correct execution permissions to ensure that Zabbix users can execute the script or program.
# vi / etc/zabbix/zabbix-server.conf
ExternalScripts=/usr/lib/zabbix/externalscripts
The default path of the system can be used in the ExternalScripts parameter, or you can specify other paths. The scripts or programs that need to be executed must be in the directory configured by ExternalScripts and set the appropriate execution permissions. Take a look at the setup process with the script that monitors the number of CPU cores on the system.
1. Create a script that detects the number of CPU cores of the system.
# touch cores.sh
2. Set executable permissions.
# chmod + x cores.sh
3. Edit the content of cores.sh script.
# vi cores.sh
#! / bin/bash
Nproc
4. Set the owner and group of the cores.sh script to zabbix.
# chown zabbix:zabbixcores.sh
In the External checks monitoring mode, the key that defines the monitoring item must follow a specific syntax, the syntax format is: script [,.]. Where script is the name of the script / executable and parameter is the optional command line argument. When the script takes no parameters, it can be written as script [] or script.
To configure External checks monitoring items:
1. On the Configuration-- > Host page, click the link in the Items column, such as the Items link of the host Zabbix server, and click the Create item button in the upper right corner of the Items page to create a new monitoring item.
Enter the name of the monitor item in Name, such as Number of CPU Core.
Select External check in Type.
Fill in the name of the script in Key, for example: cores.sh [].
Select the agent interface in Host Interface.
Select Numeric (unsigned) in Type of information.
Data Type Select Decimal.
Other parameters can remain the same, click the Add button to save.
This is shown in figure 3-12 below.
Figure 3-12
2. Monitoring-- > Latest data page to view monitoring items.
If a script or executable program needs to pass parameters, you can put them in square brackets after the name, for example: myscript.sh ["var1", "var2]", "var3"]. Macro variables defined in the system can also be passed to scripts or executable programs, such as myscript.sh ["{HOST.IP}", "var1"].
It should be noted that the execution time of the script or executable program should not be too long. If it takes more than 3 seconds, Zabbix will mark the item as unsupported and the script process will be killed. The default Timeout parameter in Zabbix server's configuration file is 3 seconds. You can adjust this parameter to a maximum of 30 seconds.
3.11 Database monitor
The database Zabbix also provides a monitoring method, which can query the database through the ODBC (Open Database Connectivity) interface. ODBC, as the middleware between Zabbix and the database system, allows Zabbix to query different databases to collect data. Of course, this database needs the support of unixODBC or Independent Open DataBase Connectivity (iODBC).
Before using ODBC to monitor the database, you need to make sure that Zabbix supports ODBC. Zabbixserver installed through the yum package manager supports ODBC by default. If you use source code to compile and install Zabbixserver, you need to use the option-- with-unixODBC.
First, you need to install unixODBC.
# yum-y install unixODBC
# yum-y installunixODBC-devel (required for source code compilation and installation of Zabbix server)
To install the connector for the database, let's take MySQL as an example.
# yum-y install mysql-connector-odbc
Next, configure the odbcinst.ini file to find the location of the ODBC database driver using the following command.
# odbcinst-j
# odbcinst-j
UnixODBC 2.3.1
DRIVERS.: / etc/odbcinst.ini
SYSTEM DATA SOURCES: / etc/odbc.ini
FILE DATA SOURCES..: / etc/ODBCDataSources
USER DATA SOURCES..: / root/.odbc.ini
SQLULEN Size.: 8
SQLLEN Size.: 8
SQLSETPOSIROW Size.: 8
Edit the configuration file.
# vi / etc/odbcinst.ini
# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = / usr/lib/libmyodbc5.so
Setup = / usr/lib/libodbcmyS.so
Driver64 = / usr/lib64/libmyodbc5.so
Setup64 = / usr/lib64/libodbcmyS.so
FileUsage = 1
Create or edit odbc.ini files, set up dsn (data source), and add database configuration.
# vi / etc/odbc.ini
[mysql-test] # dsn name
Description = Mysql test DB # description
Driver = mysql
Server = 127.0.0.1
User = root
Password = # password
Port = 3306
Database = # zabbix database
After completing the above configuration, we can test whether we can connect to the database.
# isql mysql-test
+-+
| | Connected! |
| | |
| | sql-statement |
| | help [tablename] |
| | quit |
| | |
+-+
SQL >
SQL > select count (*) from items
+-+
| | count (*) |
+-+
| | 708 |
+-+
SQLRowCount returns 1
1 rows fetched
When you see the output above and can execute the SQL query, it means there is nothing wrong with the configuration. Next, you can add monitoring items.
To configure ODBC monitoring items:
1. Create a new monitoring item (Configuration-- > Host-> Items-- > Ctreate item).
Enter the name of the monitor item in Name, such as item counts.
Select Database monitor in Type.
Select (click the Select button on the right) db.odbc.select [,] in Key, where is the only name of key defined by ourselves, which is the name of DSN defined in odbc.ini.
If the user name and password of the database are set in odbc.ini, Username and Password do not need to be filled in.
Fill in the SQL query statement we want to execute in SQL query, for example: select count (*) from items.
Select the appropriate data type in Type of information and Data type
Other configurations can remain the same, click the Add button to save.
As shown in figure 3-13 below
Figure 3-13
2. Monitoring-- > Latest data page to view monitoring items.
3.12 SSH agents
The monitoring goal can also be achieved through SSH protocol in Zabbix. Through SSH agent monitoring mode, it is very useful in the environment where the server needs to be monitored but Zabbix agent can not be installed. The minimum version of libssh3 is required to be 1.0.0 when using SSh agent in Zabbix.
SSH agent supports two authentication methods: based on user name and password and based on secret key. Using user name and password does not require any special configuration. When adding monitoring items, you need to enter the plaintext user name and password on the page. Therefore, it is recommended to use key-based authentication in the actual environment, but this method requires some additional configuration. Let's take a look at how the key-based approach is configured.
First, check the settings of the zabbix user, using the following command.
# grep zabbix / etc/passwd
Zabbix:x:996:994:Zabbix Monitoring System:/var/lib/zabbix:/sbin/nologin
You can see that the home directory of the zabbix user on the system is / var/lib/zabbix, confirm that the directory exists, and if not, use the following command to create the directory.
# mkdir-p / var/lib/zabbix/.ssh
# chown-R zabbix:zabbix / var/lib/zabbix
Next we need to modify the zabbix-server.conf file to configure the storage path of the SSH Key file.
# vi / etc/zabbix/zabbix-server.conf
SSHKeyLocation=/ var/lib/zabbix/.ssh
Restart Zabbixserver after modifying the zabbix-server.conf configuration file.
# systemctl restartzabbix-server
Now, we generate the SSH Key of the zabbix user, and you can enter directly when you ask passphrase.
# sudo-u zabbixssh-keygen-t rsa-b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/ var/lib/zabbix/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in / var/lib/zabbix/.ssh/id_rsa.
Your public key has been saved in / var/lib/zabbix/.ssh/id_rsa.pub.
The key fingerprint is:
15:3e:d5:61:ed:16:b3:0a:67:9d:35:f0:35:55:0b:7e zabbix@zbxserver
The key's randomart p_w_picpath is:
+-[RSA 2048]-+
|. . + + * |
|. O. Please tell me * |
| +. EB |
|. Oo.promoo |
| S +.. | |
|. | |
| | |
| | |
| | |
+-+
# ll
Total 8
-rw- 1 zabbix zabbix 1675 May 31 13:29 id_rsa
-rw-r--r-- 1 zabbix zabbix 398 May 31 13:29 id_rsa.pub
Next, copy the key file to the monitored host, assuming that the IP address of the monitored host is 192.168.10.112.
# sudo-u zabbixssh-copy-id root@192.168.10.112
The authenticity of host '192.168.10.112 (192.168.10.112)' can't beestablished.
ECDSA key fingerprint is0d:33:e5:5c:43:c3:5b:c4:da:e4:f0:6d:0c:fb:4a:6e.
Are you sure you want to continue connecting (yes/no)? Yes
/ bin/ssh-copy-id: INFO: attempting to log in with the new key (s), tofilter out any that are already installed
/ bin/ssh-copy-id: INFO: 1 key (s) remain to be installed-- if youare prompted now it is to install the new keys
Root@192.168.10.112's password:
Number of key (s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.10.112'"
And check to make sure that only the key (s) you wanted were added.
Now let's test whether the login is successful.
# sudo-u zabbix ssh root@192.168.10.112
When the above configuration is complete, you can create SSH agent monitoring items.
To configure SSH agent monitoring items:
1. Create a new host (Configuration-> Host-- > Create host). Add the Agentinterfaces interface configuration under the Host tag on the host configuration page, as shown in figure 3-14 below.
Figure 3-14
2. Create a new monitoring item in the host.
Enter the name of the monitor item in Name, such as Check uname.
Select SSH agent in Type.
Replace the content in Key with ssh.run [uname].
Select the agent interface in Host interface.
Select Public key in Authentication method.
Enter root in User name and id_rsa in id_rsa_pub,Private keyfile in Public keyfile.
Key passphrase is left blank. If you typed passphrase when generating the key, you need to enter the same passphrase here.
Enter uname-an in Executed script.
Select the Text type in Type of information.
Other parameters can remain the same, click the Add button to save.
As shown in figure 3-15 below.
Figure 3-15
3. Monitoring-- > Latest data page to view monitoring items.
One thing to note when using SSH agent monitoring is that libssh3 may truncate the output of an executable script to 32KB, and it is best to use the full path of the command in the script.
3.13 Telnet agents
Telnet agent monitoring is the same as SSH agent, and can be used in environments where agent software cannot be installed. But unlike SSH, Telnet is not an encrypted protocol and only supports user name and password authentication. Unless you can only use Telnetagent and you can use Telnetagent when you have no choice, it is generally not recommended to use it, and it is best to set the user account to read-only permission.
Before using Telnet agent, you need to confirm that Telnet server has been installed and started in the monitored device, and set up a user account to log in to the system using Telnet.
If Telnet server is not installed in the monitored device, you can install it using the following command.
# yum-y installtelnet-server
Edit the xinet.d configuration file, configure the parameters of telnetserver, and change the disabled setting from yes to no.
# vi / etc/xinetd.d/telnet
{
Flags = REUSE
Socket_type = stream
Wait = no
User = root
Server = / usr/sbin/in.telnetd
Log_on_failure + = USERID
Disable = no
}
Set the telnet service to start automatically after the device is restarted.
# systemctl starttelnet.socket
# systemctl enabletelnet.socket
Add users to the telnet server.
# useradd zabbix
# passwd zabbix
If the Telnet client is not installed in Zabbix server, you can install it using the following command.
# yum-y install telnet
Next we can create a monitor item that uses the Telnet agnet approach.
To configure Telnet agent monitoring items:
1. Create a new monitoring item in the host.
Enter the name of the monitoring item in Name, for example: Check uname.
Select TELNET agent in Type.
Enter telnet.run [uname] in Key.
Select the agent interface in Host Interface.
Enter the telnet user name in User name, such as zabbix.
Enter the telnet user password in Password, such as zabbix.
Enter a command in Executed script, such as: uanme-a.
Select Text in Type of information.
Other parameters can remain the same, click the Add button to save.
This is shown in figure 3-16 below.
Figure 3-16
2. Monitoring-- > Latest data page to view monitoring items.
3.14 SNMP Traps
The SNMP Traps monitoring method is different from the one described above, in which the monitored device can actively send information to the Zabbix server. When some specific events occur in the monitored device, such as device restart, network interface failure or disk damage, the SNMP agent in the monitored device will send event status information to Zabbix server.
There is no simple monitoring index corresponding to a specific event in Zabbix. In order to enable Zabbix to effectively manage SNMP Traps,Zabbix, additional snmptrapd daemon is used to help process traps information sent by SNMP agent in the monitored device. The result is sent to Zabbix server after formatting by script.
To configure SNMP Traps monitoring items:
Create a new host (Configuration-- > Host-- > Create host). Add the SNMP interfaces interface configuration under the Host tag on the host configuration page, as shown in figure 3-17 below.
Figure 3-17
Create a new monitoring item in the host.
Enter Link Down trap in u Name.
U Type Select SNMP trap.
Select snmptrap [] in u Key and replace it with linkDown. There are two main options here, and snmptrap.fallback is to capture SNMP traps that is not captured by the snmptrap [] monitor item on this interface. Snmptrap [] captures all SNMP traps that match the specified regexp, or arbitrary trap if no regexp is specified.
Select the SNMP interface in u Host Interface.
Select Log in u Type of information. It's OK to use other types like Numeric if you want, but we need to customize the trap handler handler.
U other parameters can remain the same, click the Add button to save.
This is shown in figure 3-18 below.
Figure 3-18
Monitoring-- > Latest data page to view the monitoring items.
3.15 Aggregate checks
Until now, we have seen that the monitoring method provided by Zabbix is to obtain the raw data of the monitoring items in different ways, but in the actual environment, when we want to know the total CPU load of all hosts in the same host group, we need to use the Aggregatechecks monitoring method. Aggregate can be understood as a summary. This method does not need to collect the original data directly from the monitored host, but obtains the data of monitoring items from the database for calculation, so Aggregate checks is only valid for monitoring items of Numeric type.
To configure Aggregate monitoring items:
1. Create a new host group, such as aggregated (Configuration-- > Host groups-- > Create host group), and add two or more Linux hosts to the group.
2. Create a new template (Configuration-- > Templates-- > Create template) and create a monitor item in this template with key as system.cpu.load. Link this template to all Linux hosts in the host group Aggregated.
3. Create a new host (Configuration-- > Host-- > Create host). Add the Agent interfaces API under the Host tag on the host configuration page. You can enter either 127.0.0.1 or 0.0.0.0 IP address.
4. Add a monitoring item on the new host.
Enter the name of the monitoring item in Name, such as avg cpu load.
Select Zabbix aggregate in Type.
Key is set to grpavg ["aggregated", "system.cpu.load", "last"]. Where aggregated is the host group created earlier, and system.cpu.load is the monitoring item on the host in this group.
Select Numeric (float) in Type of information.
Select Decimal in Date type.
Other parameters can remain the same, click the Add button to save.
As shown in figure 3-19 below.
Figure 3-19
5. Monitoring-- > Latest data page to view monitoring items.
3.16 Calculated checks
Calculatedchecks is similar to Aggregatechecks in that it fetches existing data from the database for calculation, but unlike Aggregatechecks, Calculatedchecks is not limited to specific host groups. The calculation results of Calculated monitoring items are saved to the database, and Calculated monitoring items can be used in trigger expressions or referenced like other types of monitoring items in macro variables, graphics, and actions.
The definition of Calculated monitoring items is contained in a formula (formula), which can be simple or complex according to your needs. The syntax of a simple formula is as follows.
Func (|,...)
Where func is the function supported in the trigger expression, including: last, min, max, avg, and count. Key or hostname:key are other monitoring items you want to use. It is recommended that you put the entire key in double quotes to avoid parsing errors caused by spaces or commas in the key. When the key contains double quotes, use slash (\) to escape. Parameter is the required parameter.
Calculated monitoring items may become unsupported when they encounter the following conditions:
No referenced monitoring items were found
There is no data for function calculation.
Divided by zero
Use incorrect syntax
When you reference a macro variable in a Calculated monitor formula, you can extend parameters and constants, not the function, hostname, key or operator of the monitor item. The data used by Zabbix when processing Calculated monitoring items relies on the monitoring data collected by the monitoring items on a regular basis, unlike trigger expressions that are evaluated as soon as new data is received.
To configure Calculated monitoring items:
1. Create a new host (Configuration-- > Host-- > Create host). Add the Agent interfaces API under the Host tag on the host configuration page. You can enter either 127.0.0.1 or 0.0.0.0 IP address.
2. Add a monitoring item on the new host.
Fill in the monitoring item name in Name, for example,% free on root.
Select Calculated in Type.
Enter free.root in the Key, which, like other monitoring items, must be unique.
Enter 100*last ("vfs.fs.size [/, free]", 0) / last ("vfs.fs.size [/, total]", 0) in Formula.
Select Numeric (float) in Type of information.
Fill in% in Units.
Other parameters can remain the same, click the Add button to save
As shown in figure 3-20 below.
Figure 3-20
3. Monitoring-- > Latest data page to view monitoring items.
The above is how to understand the way of Zabbix monitoring, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.