| 1 |
Monitoring web applications with the Apache RA |
| 2 |
|
| 3 |
One of typical uses of apache is as an interface to the one or |
| 4 |
the other kind of web application. It could be expressed thus in |
| 5 |
terms of a resource group: |
| 6 |
|
| 7 |
IP address |
| 8 |
apache |
| 9 |
web_app |
| 10 |
|
| 11 |
where web_app is a JSP application (tomcat,jeronimo) or similar. |
| 12 |
|
| 13 |
Rumour has it that the web applications suffer from occasional |
| 14 |
instability which may make them an administration nightmare. But, |
| 15 |
typical remedy is simply an application restart. |
| 16 |
|
| 17 |
How do we increase availability in this situation? |
| 18 |
|
| 19 |
The web applications are most commonly represented as one or more |
| 20 |
processes in a UNIX environment. The afore mentioned instability |
| 21 |
is most commonly not reflected in the process state. Hence, |
| 22 |
checking the process status makes us no wiser. What could help, |
| 23 |
though, is probing the application just as our unhappy user |
| 24 |
does---through the web interface. We can ask the application |
| 25 |
developers to provide a URL which should exercise the application |
| 26 |
and then provide predictable output. |
| 27 |
|
| 28 |
Now, given our generic resource group and the failed web |
| 29 |
application, which we established using a http client, we have |
| 30 |
the following situation: |
| 31 |
|
| 32 |
IP address |
| 33 |
apache FAILED |
| 34 |
web_app |
| 35 |
|
| 36 |
Some might argue that it's not apache that is the culprit or has |
| 37 |
failed, but this nevertheless should serve our purpose well. The |
| 38 |
cluster will stop web_app and apache and then start them, either |
| 39 |
on the some node or elsewhere. There's an extra apache restart |
| 40 |
which was not needed, but then again it cannot really hurt. |
| 41 |
|
| 42 |
What to monitor? |
| 43 |
|
| 44 |
Choose carefully the URL to monitor. It should probe exactly what |
| 45 |
is further up in the resource group, no more and no less. In |
| 46 |
other words, if you have a database backend running elsewhere, it |
| 47 |
would be of no use to specify a URL which depends on the |
| 48 |
database. You should monitor only what is within reach. |
| 49 |
|
| 50 |
Configuration and usage |
| 51 |
|
| 52 |
It is possible to configure the monitoring either through CIB or |
| 53 |
using an extra configuration file. If your monitoring spec |
| 54 |
consists only of a URL and a regular expression to be matched in |
| 55 |
the output, then something like this should suffice: |
| 56 |
|
| 57 |
primitive apache_a1 ocf:heartbeat:apache \ |
| 58 |
params configfile="/apps/a1.conf" \ |
| 59 |
op monitor interval=120s timeout=60s start-delay=120s \ |
| 60 |
OCF_CHECK_LEVEL=10 testurl="/webapp1_mon" testregex="This application is alive" |
| 61 |
|
| 62 |
The testurl parameter is where we connect and the testregex is |
| 63 |
what we should look for. The OCF_CHECK_LEVEL must be set to "10". |
| 64 |
Note that testurl specifies a URL which is relative to where the |
| 65 |
apache listens for connections. Obviously, this should be |
| 66 |
preferred to specifying the full URL. |
| 67 |
|
| 68 |
It is important to set start-delay to a value larger than the |
| 69 |
time needed to start the web application (the next resource). If |
| 70 |
we don't, then the first monitor operation is likely to fail. |
| 71 |
|
| 72 |
In case you need more complex configuration, it can be set |
| 73 |
in an extra configuration file: |
| 74 |
|
| 75 |
primitive apache_a1 ocf:heartbeat:apache \ |
| 76 |
params configfile="/apps/a1.conf" testconffile="/apps/webmon.cf" \ |
| 77 |
op monitor ... OCF_CHECK_LEVEL=10 |
| 78 |
|
| 79 |
/etc/apache2/webmon.cf: |
| 80 |
|
| 81 |
test webapp1 |
| 82 |
url /webapp1_mon |
| 83 |
match This application is alive |
| 84 |
client curl |
| 85 |
end |
| 86 |
|
| 87 |
This test configuration is equivalent to the first one, it's just |
| 88 |
that in the latter we want to use curl(1) as an http client |
| 89 |
instead of wget(1). |
| 90 |
|
| 91 |
Another example: |
| 92 |
|
| 93 |
test webapp1 |
| 94 |
url /webapp1_mon |
| 95 |
match This application is alive |
| 96 |
client curl |
| 97 |
client_opts --header 'Host: www.webapp1.megacorp.com' |
| 98 |
end |
| 99 |
|
| 100 |
Here we use the curl's --header option to specify the virtual |
| 101 |
host we want to talk to. |
| 102 |
|
| 103 |
It is also possible to set the credentials using the "user" and |
| 104 |
"password" keywords. |
| 105 |
|
| 106 |
The configuration file may contain more than one test definition |
| 107 |
which is handy in case one should monitor more than one web |
| 108 |
application. In that case you should specify the test name in the |
| 109 |
CIB: |
| 110 |
|
| 111 |
primitive apache_common ocf:heartbeat:apache \ |
| 112 |
params configfile="/apps/httpd.conf" testconffile="/apps/webmon.cf" \ |
| 113 |
op monitor ... OCF_CHECK_LEVEL=10 testname="a1" \ |
| 114 |
op monitor ... OCF_CHECK_LEVEL=10 testname="b1" |
| 115 |
|
| 116 |
The apache OCF RA supports wget(1) (the default) and curl(1) http |
| 117 |
clients. If neither will do, then you can specify your own using |
| 118 |
the client and client_opts keywords. Your client must allow URL |
| 119 |
as the last parameter and it must dump output from the web server |
| 120 |
to stdout. |
| 121 |
|
| 122 |
All configuration file keywords: |
| 123 |
|
| 124 |
test The name of the text. |
| 125 |
url The url to test. If it doesn't start with http, it's |
| 126 |
considered to be relative to the apache Listen directive. |
| 127 |
match The regular expression to match. |
| 128 |
user Username to authenticate with. |
| 129 |
password Password to authenticate with. |
| 130 |
client The http client. |
| 131 |
client_opts Options for the http client. |
| 132 |
end Marks the end of the test definition. |
| 133 |
# Comment. May be used only at the start of line. |
| 134 |
|
| 135 |
Notes |
| 136 |
|
| 137 |
We could support more depth levels, but it is not clear if |
| 138 |
anybody really needs that. Different check levels could be |
| 139 |
defined as different monitor operations. |
| 140 |
|
| 141 |
In case you are using the external configuration file, don't |
| 142 |
forget to replicate it to all cluster members and to keep it |
| 143 |
synchronized. |