1. Example using monit to monitor sshd service
This example demonstrates configuring monit to monitor SSH service running on Debian 6 system, assuming monit is up and running well.
As mentioned in previous post, monitrc file is parted into 2 sections. One is global section with values globally applied to functions of monit. Another is spent for definitions of monitored object called service entries. Below illustration only shows the part of service:
(1)check process sshd with pidfile "/var/run/sshd.pid"
(2) start = "/etc/init.d/ssh start"
(3) stop = "/etc/init.d/ssh stop"
(4) if failed port 22 protocol ssh then restartOK, I've just showed you about definitions of monitored service: SSH. When you're done putting these into monitrc file and restart monit, something like this will show up
(5) if 5 restarts within 5 cycles then timeout
(6) alert admin@domain.foo
2. Explanation
OK, show time is up, now it's time to explain what actually happened.
Line (1) tells monit about service to monitor, in this case is SSH. The syntax:
check process [process name] with pid [path/to/pidfile]-check: keyword to monitor service.
-process: keyword tells monit to monitor a service.
-[process name]: unique name of process, in my example is sshd
-with pid: key word specifies the pid file.
-[path/to/pidfile]: fully path to process id of service, in my example is /var/run/sshd.pid
Line (2) (3) are defined in case you want to start or stop service by defining start and stop program.
Line (4)
if failed port 22 protocol ssh then restarttells monit to take a test by making a connection to port 22 with ssh protocol running. And if the test statement is true (failed to connect), monit will make the action after the "then". Restart action actually executes stop first, wait up 30s for it to stop, then take start action in wait 30s for it to start. You can also specify the uid/gid runs the service.
Line (5)
if 5 restarts within 5 cycles then timeoutis another test action. The 1st 5 is the number of times restart service. Cycle is the time set in global section. If the "if" statement is true, "then" will set a timeout for service.
Line (6)
alert admin@domain.foowill send an alert message to specified address. The definition of email server in global section will be covered later.
OK, now you can have an overview of definition for a monitored service.
3. What to monitor?
After having an overview about creating an object (process) to monitor by monit, it's time to come back to the question: which object(s) can monit monitor?
There are several objects (services) can take a "check" by monit:
-Process:
check process [process name] with pid [path/to/pidfile]
-File:
check file [filename] with path [path/to/file]
ex: check file httpd.conf with path /usr/local/apache/conf/httpd.conf
-Directory:
check directory [dir_name] with path [path/to/dir]
ex: check directory sbin with path /sbin
-Device:
check device [device_name] with path [path/to/device]
ex: check device CDROM with path /dev/cdrom-Remote host:
check host [name_of_hsost] with address [ip_addr_or_name]
ex: check host abc.domain.foo with address 10.1.1.1It's possible to check the service running on remote host.
-System:
check system [system_name]
ex: check system my_host
No comments:
Post a Comment