# Monitor using "grep"

**URL:** <https://community.f5.com/t/monitor-using-grep/48535>\
**Category:** Technical Forums\
**Tags:** management, monitoring\
**Created:** [April 1, 2011, 8:51pm UTC](https://community.f5.com/t/monitor-using-grep/48535 "2011-04-01T20:51:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Troy\_93881](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@Troy\_93881](https://community.f5.com/u/Troy_93881)\
**Post date:** [April 1, 2011, 8:51pm UTC](https://community.f5.com/t/monitor-using-grep/48535/1 "2011-04-01T20:51:31Z")

</div>

All,

Looking for a little guidance. I would like to know if I can set up a monitor ( multiple monitors ) that would run a “grep” command and based on results -- mark a member up or down.

Appreciate and help anyone can provide,

Thanks

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [April 1, 2011, 9:42pm UTC](https://community.f5.com/t/monitor-using-grep/48535/2 "2011-04-01T21:42:43Z")

</div>

Hi Troy,

What do you want to grep for and from what and where? Which protocol of pool member are you trying to check?

Aaron

---

<div class="post-metadata">

**Author:** ![Troy\_93881](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@Troy\_93881](https://community.f5.com/u/Troy_93881)\
**Post date:** [April 4, 2011, 1:36pm UTC](https://community.f5.com/t/monitor-using-grep/48535/3 "2011-04-04T13:36:53Z")

</div>

Hello Aaron,

We are looking to design a monitor to log in to a server via CLI and perform the following commands:

ps -ef | grep arserverd and ps -ef | grep arplugin

Based on the results of those commands -- the server will be marked up or down

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [April 5, 2011, 4:52pm UTC](https://community.f5.com/t/monitor-using-grep/48535/4 "2011-04-05T16:52:35Z")

</div>

Hi Troy,

You could use SSH to connect to an IP address and performs the commands. You could then reference that SSH command in an external monitor, using this template:

[http://devcentral.f5.com/wiki/default.aspx/AdvDesignConfig/TemplateForExternalLtmMonitors.html](http://devcentral.f5.com/wiki/default.aspx/AdvDesignConfig/TemplateForExternalLtmMonitors.html)

Here’s another option which would probably require fewer resources on LTM:

Build a web app on each server which runs those commands to check for the processes and returns text in a web page indicating an up or down status. You could then use a built in HTTP monitor to check that status page.

Aaron

---

<div class="post-metadata">

**Author:** ![Troy\_93881](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@Troy\_93881](https://community.f5.com/u/Troy_93881)\
**Post date:** [April 5, 2011, 5:48pm UTC](https://community.f5.com/t/monitor-using-grep/48535/5 "2011-04-05T17:48:29Z")

</div>

Thanks Aaron

I’m not real experienced with scripting. I am working on an external monitor now that may do the trick if I can get it figured out.

Unfortunately, these boxes do not have web servers on them. A “keep alive” web page would have been my first choice due to simplicity regarding the F5 side..

Troy

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [April 5, 2011, 6:15pm UTC](https://community.f5.com/t/monitor-using-grep/48535/6 "2011-04-05T18:15:12Z")

</div>

You should probably just be able to plug in this command to the template script:

ssh $IP -p $PORT ‘ps -ef | grep arserverd | grep -v grep && ps -ef | grep arplugin | grep -v grep’ 2\>&1 \> /dev/null

in replacement of this line:

nc $IP $PORT | grep “my receive string” 2\>&1 \> /dev/null

I haven’t tested this, but I think it looks about right.

Aaron

---

<div class="post-metadata">

**Author:** ![Troy\_93881](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@Troy\_93881](https://community.f5.com/u/Troy_93881)\
**Post date:** [April 5, 2011, 8:51pm UTC](https://community.f5.com/t/monitor-using-grep/48535/7 "2011-04-05T20:51:29Z")

</div>

Hey Aaron,

It appears to marking it up regardless as long as there is any response. In this case -- I need to see a “./” in the response to both commands in order for it to be up. If the ./ is missing in either response -- the server should be marked down.

How do I change that in the script section below or do I need 2 external programs?

send request & check for expected response

ssh $IP -p $PORT ‘ps -ef | grep arserverd | grep -v grep && ps -ef | grep arplugin | grep -v grep’ 2\>&1 \> /dev/null

mark node UP if expected response was received

if [$? -eq 0]

then

echo “UP”

fi

rm -f $PIDFILE

exit

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [April 5, 2011, 9:00pm UTC](https://community.f5.com/t/monitor-using-grep/48535/8 "2011-04-05T21:00:01Z")

</div>

Can you run this from one of the hosts you want to monitor:

ps -ef | grep arserverd | grep -v grep | grep \\\. && ps -ef | grep arplugin | grep -v grep | grep \\\.

If that returns something on success and nothing on failure, can you try this in the script?

ssh $IP -p $PORT ‘ps -ef | grep arserverd | grep -v grep | grep \\\. && ps -ef | grep arplugin | grep -v grep | grep \\\. 2\>&1 \> /dev/null’

Aaron

---

<div class="post-metadata">

**Author:** ![Troy\_93881](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@Troy\_93881](https://community.f5.com/u/Troy_93881)\
**Post date:** [April 5, 2011, 9:44pm UTC](https://community.f5.com/t/monitor-using-grep/48535/9 "2011-04-05T21:44:29Z")

</div>

I will test that -- right now that command does return the 2 expected responses from the server when all is working. I will need to have the owner drop one of processes to see if it causes the server to be marked down when the other is still working and vice versa.

I’ll update here with the results

Thank you very much for the help,

Troy

---

<div class="post-metadata">

**Author:** ![Troy\_93881](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@Troy\_93881](https://community.f5.com/u/Troy_93881)\
**Post date:** [April 6, 2011, 3:03pm UTC](https://community.f5.com/t/monitor-using-grep/48535/10 "2011-04-06T15:03:05Z")

</div>

Aaron,

I tested the monitor and it is still leaving the member marked up despite no response to that command. At the server prompt ( xxxxxx/xxx/xxx/xxx/arserverd\> ) I entered the command and now it just comes back to the prompt with no output ( xxxxxx/xxx/xxx/xxx/arserverd\> ).

“arserverd” does appear in the server prompt though as you can see. “arplugin” does not.

I am getting lots of log messages now due to the debug addition -- EAV ars\_mon.bash: exceeded monitor interval, needed to kill xxx.xxx.xxx.xxx:443 with PID 32378

It does take time to log into the server -- once you ssh and enter user / password -- it takes approx 15 sec to bring up the prompt. I’m wondering if this is hanging it up. If so -- why would the member remain online? How is the F5 logging in using you template?

---

<div class="post-metadata">

**Author:** ![Troy\_93881](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@Troy\_93881](https://community.f5.com/u/Troy_93881)\
**Post date:** [April 7, 2011, 4:05pm UTC](https://community.f5.com/t/monitor-using-grep/48535/11 "2011-04-07T16:05:10Z")

</div>

Aaron,

After running several tests -- it appears that the script really isn’t looging in completely and because there is something other than a “null” response, the server is being marked up. It looks like I need to incorporate a ssh key gen or some other way to get completely into the server or get the script to answer the password prompt and then perform the command if thats possible.

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [April 7, 2011, 9:00pm UTC](https://community.f5.com/t/monitor-using-grep/48535/12 "2011-04-07T21:00:05Z")

</div>

Do you get the same delay when you SSH without the script? It’s possible that the SSH server is configured to do a reverse lookup of the client IP. If so, you can disable that on the server by setting UseDNS to no in the sshd\_config file.

If you’re using SSH from a monitor, you should do key based auth so you don’t need to hard code a user/pass somewhere:

> **[SSH/OpenSSH/Keys - Community Help Wiki](https://help.ubuntu.com/community/SSH/OpenSSH/Keys)**

Aaron
