Linux Learning Summary (56) Monitoring Zabbix deployment Next

Source: Internet
Author: User
Tags custom name

Zabbix Application Examples

Add a custom monitoring item

Let's take an example: monitor the number of concurrent connections on a Web server 80 port and set up a graph.
1. Write a script that can crawl the data and create a script on the client zabbix-agent

vim /usr/local/sbin/estab.sh#!/bin/bashnetstat -ant |grep ‘:80 ‘ |grep -c ESTABLISHED   

After saving, give script 777 permission
Script test:
sh /usr/local/sbin/estab.shSee if it's an error
2 Associate the script in the Zabbix client configuration file, define the key value of the monitoring item, that is, the value that the script obtains, and later define it in the Zabbix Web interface

vim /etc/zabbix/zabbix_agentd.conf  //增加两行UnsafeUserParameters=1  

The key of the custom monitoring item is My.estab.count, the following [*] inside the script parameters, if no parameters can be omitted, the script is/usr/local/sbin/estab.sh
After saving the configuration file, restart the next Zabbix-agent service
Systemctl Restart Zabbix-agent
Check that the configuration is correct and execute on the server
zabbix_get -s 192.168.226.130 -p 10050 -k ‘my.estab.count‘The IP is the client IP and the port is the client port, which means that the client gets the key value of the monitoring item from the server.
The 3 web interface adds monitoring items that can be added to the host or added to the template. Easy to manage, we add in templates.
Configuration-templates-monitoring items for custom templates-creating monitoring items
Custom name, key value write the My.estab.count defined in the above configuration file, type remains the default, (passive mode). Click the Add button below.

4 Setting up graphics
Configuration-Templates-custom templates-graphics-Create graphics
Name Customization. Monitoring items Add the above-created monitoring items, click the Select button, and then click the Add button at the back of the selection.
You can also create graphics in the host.
Final effect

Two configuration alarms

We simulate an alarm and send an email notification
1 Creating an alarm medium, specifying a script to send the message
Management-Alarm Media type-Create media type
Specific operation into

2 Creating scripts on the Zabbix server
cd/usr/lib/zabbix/alertscripts/
Vim mail.py

#!/usr/bin/env python#-*-coding:utf-8-*-import os,sysreload (SYS) sys.setdefaultencoding (' UTF8 ') import getoptimport Smtplibfrom email. Mimetext Import mimetextfrom Email. Mimemultipart Import mimemultipartfrom subprocess import *def sendqqmail (Username,password,mailfrom,mailto,subject, Content): Gserver = ' smtp.qq.com '//More practical changes Gport = Try:msg = Mimetext (Unicode (content). Encode (' U Tf-8 ') msg[' from '] = Mailfrom msg["to"] = mailto msg[' reply-to '] = mailfrom msg[' Subject '] = Subject SMTP = Smtplib. SMTP (Gserver, Gport) smtp.set_debuglevel (0) Smtp.ehlo () Smtp.login (Username,password) Smtp.sen DMail (Mailfrom, mailto, msg.as_string ()) Smtp.close () except Exception,err:print "Send Mail failed. Error:%s "% errdef Main (): To=sys.argv[1] subject=sys.argv[2] content=sys.argv[3]# #定义QQ邮箱的账号和密码, you need to change your account and password Sendqqmail (' [email protected] ', ' aaaaaaaaaa ', ' [email protected] ', to,subject,content) If __name__ = = "__main__": Main () 

Note: The script needs to modify two places, the first is the mailbox server, the above gserver = ' smtp.qq.com ', if the use of 163 mailboxes, can be changed to 163.com, the second place for Sendqqmail (' [email protected] ' , ' aaaaaaaaaa ', ' [email protected] ', to,subject,content) here specify the sender's email address, password and the recipient's email address, the password for the mailbox of the client authorization code, need to login to the mailbox to get.

Remember to give script permission
chmod 777 mail.py
3 Create a user to receive alerts
Manage-users-create users

The first user, the definition of name, group, password can be, groups can choose Zabbix Administrators
The second alarm medium

Type Select the type we created above, email here we specify the same as the sending email address.
The third power point go in and see if all group permissions are none, do the following
The user's permissions need to be assigned within the user group. Select the Zabbix Administrators group specified above, select permissions, select Read and write, select all groups and add, complete will find all group permissions from No to read and write

4 Configuring Alarm Actions
Configuration-action-Create action
Define the action name in the sub-Interface action, define the email content in the operation interface, clear the original message content, add the following content

HOST:{HOST.NAME} {HOST.IP}TIME:{EVENT.DATE}  {EVENT.TIME} LEVEL:{TRIGGER.SEVERITY} NAME:{TRIGGER.NAME}messages:{ITEM.NAME}:{ITEM.VALUE}ID:{EVENT.ID}

Click "New" to open "Operation Details" select Send to User, add the user we just defined, click on the bottom to add
The recovery interface is treated the same as the operating interface.
Now that the configuration is complete,
5 Test Alarms
Create a Trigger
Configuration-templates-Custom template triggers-create triggers

The current one-minute average load of 0, deliberately set less than 1 alarm, we see the following alarm message on the dashboard, and sent a message
Note: The trigger I created in the template, because my template is associated with the host, can of course create a trigger in the host, which means that we monitor the overall logic around the host. However, the operation can be done in the template.

Linux Learning Summary (56) Monitoring Zabbix deployment Next

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.