|
|
Home > Product >
KSM >
Examples
Basic examples
Advanced example
* You are welcome to share your examples/scenarios.
Detect local web server failure
This is a simple example to show how to use KSM to detect a local web server failure.
In this example, the web server is Apache and installed in "/usr/local/apache".
It listens port 80 and has a keyword "Welcome to ABC" in '/index.html'.
KSM fetches '/index.html' and check the keyword 'Welcome to ABC'
every 30 seconds. If failure instances are counted up to 4,
a failure event occurs.
When server failure detected, KSM will try to start apache and
send Apache error log in email to webmaster.
Detect process status
Suppose that you install a UNIX daemon named "ghost", and use it to provide
authentication service. However, it sometimes disappears (terminated)
for some unknown reason, and the service is stoppped. You can use KSM to
monitor the process, and restart it when necessary. Since the task
of "authentication" is important, we restart "ghost" as soon as find
that it disappears by set MAX_RETRY to 1. The program ghost write its
messages in '/var/log/ghost.log'. We will "tail" the log file for the latest
segment and send it to root.
Detect network connection failure for backup routing
On a gateway host, the server connects to Internet through a high speed DSL.
The host also has a slow speed ADSL for backup routing, if the high speed DSL
is down. The high speed DSL is binded by network interface "eth0", while
the low speed ADSL is binded by interface "eth1". We can use KSM to detect
outgoing connection failure on "eth0", and switch default route to "eth1"
automatically. We detect network failure by pinging ISP's router IP
(ex. 187.42.0.254). Since it's normal to have network failures because
of temporary "traffic jam", we should not conclude a "failure" event
when a single 'ping' fails.
In this example, if failure instances (ping fails) are counted up to 4,
then a failure event occurs.
Note: the KAAS_START_CMD in this example uses "route" to
switch default route from "eth0" to "eth1", however, the syntax may be
different to different OS.
Detect core dump and mail the core file
You develop a program named "ultraman". The program is designed for providing
network service, but it sometimes "core dumps" due to unknown reason.
The "core dump" will happen when the program runs several days.
By using KSM, you can restart "ultraman" when it core dumps as soon as possible,
and save dumpped core file for debugging. In this example, we use
MPACK,
the utility for encoding binary files in MIME format mail messages to
send the core file as mail attatchment. Because the "ultraman" is not a
daemon program, KSM fork a child progcess to start it, so KSM can back to
the monitoring loop again.
Detect abnormal memory usage
Very often, a buggy program has the symptom of memory leak. It uses little
memory but consumes huge amount of memory gradually, and finally
it gets core dumped. Sometimes, the symptom may surface after
runing several days or several weeks.
In this example, the program is named "monster" and installed in /usr/local/monster.
The program can flush run-time data into disk and stoped by sending SIGHUP signal.
You can use KSM to detect the situation and take necessary actions before
it gets core dumped. We use "top" (1) to detect program's memory usage,
and stop the program gracefully before too late.
|