Zabbix zabbix turn automatic discovery and custom user key parameters User parameters

########31

https://www.cnblogs.com/yjt1993/p/10883345.html

1, the concept of

  In the process of configuring Iterms in, sometimes need to add a similar Iterms, these Iterms have common characteristics, the performance of certain parameters is variable, and other settings are the same, for example: a program has multiple ports , but you need to configure Iterms port. Again, disk partitions, network card's name and so on, because of the uncertainty, the ancient Configuration Fixed Items will not be a common problem.

  Low level discovery of Key card can, and file systems for automatic discovery, of course, also supports custom.

  Low level discovery process is divided into two steps as follows using:

    (1) automatically discover the name of a particular variable.

    (2) Add Items to variables.

  Low level discovery Zabbix in the return value is a Key JSON format. View Low level discovery Key returned the following format:

2, case columns

  Zabbix monitoring process using Hadoop cluster. The process started each machine is not the same, but this time you want to monitor each machine hadoop process, you need to automatically discover the rules, if the generic template configuration, to each monitored item (a monitoring process hadoop each) are configuration, you will find each host to some monitoring items are not supported.

zabbix client configuration as follows:

EnableRemoteCommands = 1 turn on remote command execution, the default is 0, when the monitoring process to hadoop out after the start automatically.

Timeout = 30 Timeout

StartAgents = 8 processing threads open 

Auto discovery script written as follows:

Copy the code
[root@manager1 script_py 19:20:09]#cat hadoopDiscovery.py 
#!/usr/bin/env python3
import os
import json

with open("/data1/zabbix_sh/jps.txt", "r") as f:
    text_lst = [i.split("\n")[0] for i in f.readlines()]

hadoopProcess = []

for i in text_lst:
    hadoopProcess += [{'{#hadoopProcessName}':i}]
print(json.dumps({'data':hadoopProcess},sort_keys=True,indent=7,separators=(',',':')))
Copy the code
[root @ manager1 script_py 19:20:12] #cat /data1/zabbix_sh/jps.txt which is stored inside the current node should start the process 
DataNode 
Master

Implementation of the results is as follows:

  (1) Custom Key, as follows:

# cat /etc/zabbix/zabbix_agentd.d/hadoop_process.conf 
UserParameter=hadoop_process[*],sudo /data1/zabbix_sh/hadoopProcess.py $1
UserParameter=hadoop_state,sudo  /data1/zabbix_sh/hadoopState.py
UserParameter=hadoop.process.discovery,sudo /data1/zabbix_sh/hadoopDiscovery.py
hadoopProcess.py script as follows:
Copy the code
# cat hadoopProcess.py 
#!/usr/bin/env python3
'this is a system monitor scripts'
__author__="yjt"

import os
import sys
def hadoop_program():
    with open("/data1/zabbix_sh/jps.txt", "r") as f:
        list_jps = [i.split("\n")[0] for i in f.readlines()]

    job_value = []
#    hadoop_process = ['JournalNode','ResourceManager','HMaster','DataNode','DFSZKFailoverController','QuorumPeerMain','HQuorumPeerMain','JobHistory','Kfaka','NodeManager','Worker','Master','HRegionServer','NameNode','PrestoServer','RunJar']
    job_lst = os.popen('/data1/jdk/bin/jps').readlines()
    for i in job_lst:
        value = i.split()[1]
        if value != 'Jps':
            job_value.append(value)
    if sys.argv[1] in job_value:
        print(1 )
    elif sys.argv[1] in list_jps:
        print(0)
#    else:
#        print(2)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        hadoop_program()
Copy the code

After you configure client restart zabbix

Test whether you can obtain data from the server to the end:

 

(2) web interface configuration:

   1) Create a template: Configuration ---> Templates ---> Create Template

 

   2) create automatic discovery rule on the change templates:

 

   3) automatic discovery rule configuration

 

 

 

  4) Create a prototype monitoring template for this item

 

 

 

 

  5) to create a trigger:

  6) Creating Graphics:

 

 

 

Here this template has been created. This time when creating a host of associated template to see results, we need to wait for some time. Results are as follows:

The first machine:

 

 Second machine:

 

 OK

 

##########32

http://www.ttlsa.com/zabbix/zabbix-user-parameters/

Why Customize KEY

Sometimes we want to execute a monitored end zabbix no predefined detection, zabbix user-defined parameter function provides this method. We can zabbix_angentd.conf configuration inside UserParameter in the client configuration file
syntax is as follows:

User-defined parameter contains a command and a key, key must be unique throughout the system, and then configured, restart the client.

Then configure the item, we can fill our custom key position in the key.

User-defined parameter in the script specified performed by zabbix agent, the maximum possible return 512KB of data.

Examples of user-defined key

Simply command example:
UserParameter = ping, echo 1
if the call ping this key, you will receive the return value of 1.
A more complicated example:
UserParameter = mysql.ping, mysqladmin-uroot-ping | grep -c Alive
if it returns 1 MySQL represents the operation, MySQL returns 0 if hung up

Flexible custom key:

As for the flexible user-defined parameters

 

parameter description
Key Unique. [*] Represents a plurality of parameters which can pass
Command Script needs to be executed, key of [] inside the parameters of one-$ 1 to $ 9, a total of nine parameters. $ 0 for script commands.

Precautions

1. If you need to use the command line which appeared in this $ 2 variable, then you want to use two $$ 2, for example, awk '{print $$ 2}' , before you encountered this problem, stop the script to test their normal output, but zabbix but can not get the data, turned out to be out here. In order to prevent conflicts and arguments, so zabbix we made this provision.
2. zabbix prohibit the use of some unsafe parameters, as follows:
\ ' "` * [] {} ~ $ &; () <> | # @?!
3. zabbix 2.0 from the beginning, zabbix return text data can be spaces.

Example 1

Of ping = UserParameter [*],. 1 $ echo
of ping [0] - will always return to 0
of ping [AAA] - will always return 'aaa'

Example 2

UserParameter = mysql.ping [*], mysqladmin -u $ 1 -p $ 2 ping | grep -c alive
following parameters for monitoring MYSQL, and passing the user name and password.
mysql.ping [zabbix, our_password]

Example 3

Statistics in a file of how many rows match?
UserParameter = WC [*], grep -c "$ 2" $ 1
the following method will return the number of rows specified character appears in the file
WC [/ etc / passwd, root]
WC [/ etc / services, zabbix]

 

Guess you like

Origin www.cnblogs.com/feiyun8616/p/11856679.html