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/02 Report--
Chapter XIV flexible script extensions
By the time you learn this chapter, I believe you have mastered how the various components of the Zabbix server work and how to collect data through Zabbix, but in the real world, you may be faced with a large, heterogeneous, complex infrastructure, and you will find that there are many different application platforms and systems, servers and network devices, as well as many custom devices and dedicated hardware products. What these devices have in common is that they all provide network interfaces. For conventional servers and network devices, we can easily use the monitoring method provided by Zabbix to collect data, but there will still be some application systems or devices that can not collect monitoring data through the standard query method provided by Zabbix or SNMP.
Suppose that in the real environment, with a user-customized device, the current temperature provided by the internal temperature sensor of the device can only be collected through specific client software, which is a key indicator that must now be monitored through Zabbix. In this scenario, the client software must be called through a script to collect monitoring data. In addition, there are many application systems, such as Nginx, which provides running status information through the stub_status module, and Redis can collect the running status of the system through the command redis-cli info.
In order to meet such scenarios, Zabbix provides the following ways to collect monitoring data:
Run scripts in Zabbix server to collect monitoring data (External checks)
Run scripts in Zabbix agent to collect monitoring data (UserParameter)
Run scripts in Zabbix server or agent to collect monitoring data (Zabbix_sender)
Self-developed tools to collect monitoring data according to Zabbix protocol
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
Running scripts in 14.1 Zabbix Server
In the real world, you may not be able to install standard Zabbix agent in the monitoring device to collect monitoring data. Through Externalchecks monitoring, you can execute scripts or binaries on Zabbix server to collect monitoring data.
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 permissions to allow Zabbix to execute.
# vi / etc/zabbix/zabbix-server.conf
ExternalScripts=/usr/lib/zabbix/externalscripts
ExternalScripts can use system-standard paths, or you can specify other paths. Here we can put the script or program here and set the appropriate permissions.
Note the following when using External checks:
Multiple comma-separated parameters are supported in Key syntax.
User-defined macro variables are supported in script commands.
External checks returns errors through standard output (STDOUT) and can be managed in triggers.
Return values for multiple rows are supported.
Complex monitoring tasks can be accomplished through External checks, but server performance should be paid attention to when used in the real environment. Each script execution requires Zabbix server to start a process, which will degrade the performance of Zabbix server when there are many scripts running.
For more information on how to create External checks monitoring items, please see Chapter 3.
Running scripts in 14.2 Zabbix agent
In order to prevent running scripts on the server from taking up a lot of resources and affecting server performance, Zabbix provides a method called UserParameter, where we can run scripts on Zabbix agent.
UserParameter is defined in the agent configuration file. The syntax is as follows:
UserParameter=
User parameter consists of two parts, one is Key, the Key defined here will be used when creating item in the front-end page of Zabbix server, and the name must be unique in the host referencing this Key. We can use dots or underscores in the name of Key, but there can be no spaces or other special characters. The other part is command, which is an executable command or script.
When defining key in User parameter, we can also set parameters that can be passed to commands or scripts. The syntax is:
UserParameter=key [*], command
[*] indicates that multiple parameters can be passed. Corresponding to the position of the parameters in [*], you can use $1meme "2meme" 3 in command. $9 refers to the parameter, and $0 represents command itself. If you reference the parameter $2 on the command line you are using, it needs to be changed to $2, for example: awk'{print $$2}', in which case $2 actually refers to the $2 parameter. In addition, parameters like $2 will parse the parameters in the corresponding position even if you enclose them in double quotes (") or single quotes (').
Commands in User parameter are supported through Zabbix agent, and data of up to 512KB size is returned. If the timeout defined in the agent configuration file is reached, the User parameter process will be killed. The text returned by Userparameter (type ofinformation is character, log, or text) can include spaces, and if the return value is invalid, item will become unsupported.
To better understand UserParameter, here are a few examples.
UserParameter=ping,echo 1
Always returns 1.
UserParameter=ping [*], echo $1
Ping [0] will return '0destroy ping [aaa] will return' aaa'.
UserParameter=mysql.ping,mysqladmin-uroot-p ping | grep-c alive
Return 1 if MySQL is running normally, otherwise return 0.
UserParameter=mysql.ping [*], mysqladmin-u$1-pendant 2 ping | grep-c alive
Mysql.ping [zabbix,our_password] passes the user name and password to the location of the parameter reference on the command line.
UserParameter=wc [*], grep-c "$2" $1
Wc [/ etc/services,zabbix], which calculates the number of lines containing zabbix in the services file, where $2 is enclosed in double quotation marks and the parameters in the corresponding position are still referenced correctly on the command line.
The usual practice is:
1. Edit the zabbix_agentd.conf configuration file and configure the UserParameter options. For example:
UserParameter= process.number [*], ps-e | grep $1 | wc-l
2. Use zabbix-agentd-t to test the defined UserParameter
# zabbix_agentd-t process.number [httpd]
Process.number [t | 8]
3. Save the agent configuration file and restart agent.
# systemctl restart zabbix-agent.service
4. Use zabbix_get tool to test:
# zabbix_get-s 127.0.0.1-k process.number [httpd]
eight
5. Create a new monitoring item on the host in Zabbix server. The type can be Zabbix agent or Zabbix agent (active). This is shown in figure 14-1 below.
Figure 14-1
6. Open the Monitoring-> Latest data page, and you can see the return value of the monitoring item httpd process number after a while.
14.3 send data using zabbix_sender
Zabbix also provides tools to send data to server, which is called zabbix_sender. Before using zabbix_sender, you need to add a monitor item of type Zabbixtrapper to the Zabbix server front-end page. This is shown in figure 14-2 below.
Figure 14-2
The Zabbix_sender usage can be read through the help file via-h, or you can browse the page https://www.zabbix.com/documentation/3.0/manpages/zabbix_sender of the Zabbix website. Here are some of the main parameters and usage.
Parameter description:
-c,-- config config-file:Zabbix sender reads information about server from the agent configuration file, and if this parameter is not used, the default Zabbixsender does not read the configuration file. Config-file must specify the absolute path to the configuration file. Currently, only Hostname, ServerActive, and SourceIP,ServerActive configurations with multiple servers will use the configuration of the first server.
-z,-- hostname or IP address of the zabbix-server server:Zabbix server. If you are using proxy for monitoring, this should be the hostname or IP address of proxy. If used with-- config, the current setting of this parameter overrides the IP or hostname of the first server configuration of ServerActive in the configuration file.
-p,-- the port on which port port:Zabbix server trapper runs. The default is 10051. If used with-- config, the current setting of this parameter overrides the port configured by the first server of ServerActive in the configuration file.
-I,-- source-address IP-address: specify the source IP address. If used with-- config, the current setting of this parameter overrides the setting of SourceIP in the configuration file.
-s,-- host host: specifies the name of the host that receives the monitoring item data. The host IP or DNS hostname cannot be used here. If used with-- config, the current setting of this parameter overrides the setting of Hostname in the configuration file.
-k,-- key key: specifies the key of the monitoring item from which the data is sent.
-o,-- value value: specify the value of the monitoring item.
-I,-- input-file input-file: loads the sent data from the file. Data is read from standard input when input-file is specified as -. The format of each line of the contents of the input file is, and each parameter is directly separated by a space. Where hostname is the host name added in the Zabbix server front-end page, and key is the value of the monitoring item item key,value. If hostname is specified as -, hostname uses the Hostname or-host parameter in the agent configuration file. For example:
-iostat.avgrq-sz [sda] 39.48 # use-- host or agent configuration file Hostname
Server1 db.connections 60 # host server1, the key of the monitoring item is db.connections, and the value is 60
The correct value type of item must be set in the Zabbix server front-end page, and Zabbix sender can send up to 250 values per connection.
Here is an example of monitoring disk IO. In this example, disk data is collected through iostat (version 10.1.5 of sysstat), auto-discovery rules and item, graph, trigger prototypes are defined in the template, and item, graph and trigger are automatically created when the template is linked to the host. Create an item in the template to collect monitoring data on a regular basis.
1. Define UserParameter
# vi / etc/zabbix/zabbix_agentd.d/userparameter_io.conf
UserParameter = iostat_status,/etc/zabbix/script/io_stat.sh
UserParameter = iostat.discovery_disks,/etc/zabbix/script/io_stat.shdisks
2. Edit the script file
# vi / etc/zabbix/script/io_stat.sh
#! / bin/bash
If [- z $1]; then
RespStr=$ (/ usr/bin/iostat-dkxy 2 > / dev/null)
(cat / dev/null 2 > & 1
Echo 1
Exit 0
Elif ["$1" = 'disks']; then
DiskStr= `/ usr/bin/iostat-d | awk'$1 ~ / ^ [hsv] d [amurz] $/ {print $1}'`
Es=''
For disk in $DiskStr; do
OutStr= "$OutStr$es {\" {# DISKNAME}\ ":\" $disk\ "
Es= ","
Done
Echo-e "{\" data\ ": [$OutStr]}"
Fi
3. Create a template Template IO Trap. This is shown in figure 14-3 below.
Figure 14-3
4. Add an application named IO to the template.
5. Create a monitor item named Status, as shown in figure 14-4 below.
Figure 14-4
6. Create a trigger, as shown in figure 14-5 below.
Figure 14-5
7. Create auto-discovery rules and periodically call scripts to discover disks. Automatically generate data in JOSN format in the script, for example:
{"data":
[
{"{# DISKNAME}": "sda"}
{"{# DISKNAME}": "sdb"}
]
}
This is shown in figure 14-6 below.
Figure 14-6
8. Create a prototype of item. The monitor item created in step 5 periodically invokes the script in which the input file required by Zabbixsender is automatically generated based on the return result of the iostat command. When creating an item prototype, use the key in the input file to create a monitor item of type Zabbix trapper. The format of the input file is as follows:
-iostat.rrqm_ SDA 0.00
-iostat.wrqm_ SDA 0.02
-iostat.r_ s [SDA] 0.12
-iostat.w_ s [SDA] 5.17
-iostat.rkB_ s [SDA] 4.30
-iostat.wkB_ SDA 99.98
-iostat.avgrq-sz [sda] 39.48
-iostat.avgqu-sz [sda] 0.01
-iostat.await [sda] 1.21
-iostat.r_ Await [SDA] 2.18
-iostat.w_ Await [SDA] 1.19
-iostat.svct [sda] 0.66
-iostat.util [sda] 0.35
Create an item prototype using the key parameter in the input file, as shown in figure 14-7 below.
Figure 14-7
The list of item prototypes created is shown in figure 14-8 below.
Figure 14-8
9. Create a graph prototype, as shown in figure 14-9 below.
Figure 14-9
The list of graph prototypes is shown in figure 14-10 below.
Figure 14-10
10. Link the template Template IOTrap to the host, and then view the monitoring data in Latest data, as shown in figure 14-11 below.
Figure 14-11
The execution of Zabbix sender in the example we call the script through a query of the monitoring item. In fact, you can also run the script through cron. It is more convenient to manage by defining monitoring items. Changes in settings such as Update interval (in sec) can be completed in the front-end page without any operation on the monitoring host.
From http://ustogether.blog.51cto.com/8236854/1929788, if you need to reprint, please contact the author.
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.