Introduction to the use of monit monitoring tools

Source: Internet
Author: User
Tags set up email



Function

You can use Monit to monitor processes, especially useful for monitoring daemons, such as/ETC/INIT.D that start at system startup time, such as: Sendmail,ssh,apache,mysql, etc.

1) You can use Monit to monitor the files,directories, file system, Monit can monitor the changes of these items, such as: timestamp, checksum changes, file size changes, it is more secure, such as: you changed the contents of the file, Then its MD5 or SHA1 check code will change.

2) Monit can monitor network links to various servers, local or remote, TCP or Udp,unix domainsockets support

3) Monit can be used to test the program or script at some point, you can test the program's return value, and based on this, do some necessary actions, such as: Perform an action or send an alert

4) Monit can be used to monitor general system resources such as CPU usage, memory, and load average (load acerage)

{

Loadaverage is the load of the CPU, which contains information that is not CPU usage, but rather a statistic of the sum of the number of processes that the CPU is processing and waiting for the CPU to process over a period of time, that is, statistics on the length of the CPU usage queue}


Configuration

Monit default 2 minutes (120 seconds) to check the service and write the results into the log file, the log file is placed by default in/var/log/monit.log, which can be modified in the configuration file.

Add information such as processes that need to be monitored to the monit configuration file, Monit configuration can refer to the sample file Monitrc below.

###############################################################################

# # Monit Control file

###############################################################################

#

# Check the cycle, the default is 2 minutes, you can adjust according to the need, here to change it to 30 seconds.

Set Daemon 30

# log file

Set Logfile/var/log/monit.log

#

# Mail Notification Server

#set mailserver mail.example.com

Set mailserver localhost

# notification message formatting, below is the default format for reference

Set Mail-format {From:[email protected]}

# Set up email notification recipients. Recommended to Gmail for easy mail filtering.

Set alert [email protected]

Set httpd port 2812 and # Setting HTTP monitoring page ports

Use address www.example.com #http监控页面的IP或域名

Allow localhost # allows local access

Allow 58.68.78.0/24 # allows this IP segment access

# #allow 0.0.0.0/0.0.0.0 # Allow any IP segment, do not recommend this dry

Allow Userxxx:passwordxxx # Access user name password

# Overall system health monitoring, the default can be, you can fine-tune

#

# system name, can be IP or domain name

Check System www.example.com

If Loadavg (1min) > 4 then alert

If Loadavg (5min) > 2 then alert

If memory usage > 75% then alert

If CPU usage (user) > 70% then alert

If CPU usage (System) > 30% then alert

If CPU usage (wait) > 20% then alert

#

# Monitor Nginx

#

# need to provide process PID file information

Check process Nginx with Pidfile/var/run/nginx.pid

#进程启动命令行, note: must be the command full path

Start program = "/etc/init.d/nginx start"

#进程关闭命令行

Stop program = "/etc/init.d/nginx Stop"

#nginx进程状态测试, monitoring the nginx is not connected, the automatic restart

If failed host www.example.com Port protocol HTTP then restart

#多次重启失败将不再尝试重启, this is the case of a serious system error.

If 3 Restartswithin 5 cycles then timeout

# If the program uses CPU and memory more powerful, add some additional monitoring settings in this area

If CPU > 50% for 2 cycles then alert

If CPU > 70% for 5 cycles then restart

If Totalmem > MB for ten cycles Thenrestart

If children > then restart

If Loadavg (5min) greater than for 20cycles then stop

If failed host www.example.com Port 8080protocol http then restart

If 3 restarts within 5 cycles then timeout

#可选, set up grouping information

Group Server

include/etc/monit.d/* # Other configurations can be placed in this directory to include

Note: Official Configuration example URL Http://mmonit.com/wiki/Monit/ConfigurationExamples

After modifying the MONITRC configuration file, we need to perform the following command to check whether the MONITRC syntax is correct:

# monit-t-C/ETC/MONITRC

Control file Syntax OK

Precautions:

1) The command in the start and stop program parameters must be the full path, otherwise monit will not start normally, such as killall should be/usr/bin/killall.

2) for spawn-fcgi, many people will use it to manage the PHP fast-cgi process, but spawn-fcgi itself is likely to hang out, so still need to use Monit to monitor spawn-fcgi. SPAWN-FCGI must be with the-p parameter to have PID files, and fast-cgi Go is not the HTTP protocol, monit protocol parameters do not have CGI corresponding settings, be sure to remove the protocol HTTP this setting will work.

3) process Multiple restart failure Monit will no longer attempt to restart, received such notification message indicates that the system has a serious problem, to cause enough attention, need to quickly manual processing.



Use

Start Monit Monitor to execute the following command:

# monit-c/ETC/MONITRC

Where:-C option can also not add monit default will be from ~/MONITRC,/etc/monitrc two locations to find the configuration file. Other relevant parameters can be viewed through monit-h. Once the boot is complete, you can view the specific monitoring information by http://IP:2812 (the port can be changed in the configuration file) (the default user name and password are admin/monit).

Note: If using a firewall, remember to add Port 2812 to the firewall configuration.

Monit is used as follows:

# monit-h

Usage:monit [options] {arguments}

Options are as follows:

-cfile Use this control file

-dn Run as a daemon once per nseconds

-gname Set group name for Start,stop, restart, monitor and Unmonitor

-llogfile Print log information to Thisfile

-ppidfile Use this lock file in Daemonmode

-sstatefile Set The file Monit shouldwrite state information to

-I do not run in background (needed for run from Init)

-T Run syntax check for the control file

-V Verbose mode, work noisy (diagnostic output)

-h[filename] Print SHA1 and MD5 hashes of the file or of stdin if the

FileName is omited; Monit Willexit afterwards

-V Print version number and Patchlevel

-H Print This text

Optional action Arguments for Non-daemonmode is as follows:

Start All-start All services

Start name-only start the named service

Stopall-stop All Services

Stopname-only Stop the named service

Restart All-stop and start all services

Restart name-only Restart the named service

Monitorall-enable Monitoring of Allservices

Monitor name-only enable monitoring of the named service

Unmonitor all-disable monitoring of all services

Unmonitor name-only Disable monitoring ofthe named service

Reload-reinitialize Monit

Status-print Full status information for each service

Summary-print Short status information for each service

Quit-kill monit Daemon Process

Validate-check all services and start if not running

(Action arguments operate on servicesdefined in the control file)

Note: Detailed Help files can be viewed in the man manual via less monit-5.5/man/man1/monit.1. You can also check the Help documentation on the official wiki page.


Summarize

Monit in C language, processing efficiency is very high, very few resources (almost no resources), configuration parameters are very simple, using only a few if ... then ... Statement to complete the monitoring task. This is especially useful for guarding certain processes. For example, if the HTTP service is detected to be unhealthy, automatically restart Apache or Nginx. But the monitoring function is slightly simpler than Nagios.


Introduction to the use of monit monitoring tools

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.