Monitoring services with xinetd


About xinetd

xinetd (extended Internet services daemon) performs the same function as inetd: it starts programs that provide Internet services.

Instead of having such servers started at system initialization time, and be dormant until a connection request arrives, xinetd is the only daemon process started and it listens on all service ports for the services listed in its configuration file.

When a request comes in, xinetd starts the appropriate script.

Sample xinetd configuration file

Listen for connections on port 9001. Run cassandra_status shell script per each thread and return the result.
service cassandra_monitor
flags    = REUSE
socket_type  = stream
port      = 9001
wait      = no
user      = nobody
server    = /home/xinetd/
log_on_failure += USERID
disable    = no

Installing xinetd

On FreeBSD:
cd /usr/ports/security/xinetd
make all
make install

On CentOS:
yum install xinetd

Configuring Monitoring scripts

xinetd light weight server makes it easy to test several conditions, before returning a response of “All good” to a third party monitoring script like Pingdom.

Here’s a sample xinetd shell monitoring script that we use to detect if a Cassandra node is running properly.

## Check if swap is over 20%


SWAP=`top -n | grep Swap | awk ‘{print $ 8 + 0}’`
if [ $ SWAP -ge 20 ]
# error occured, return http 503
/bin/echo “HTTP/1.1 503 Service Unavailablern”
/bin/echo “rn”
fi # Check if other instances of this script are already running, allowing a maximum of 10 to run at the same time
ALREADY_RUNNING=`ps auxww | grep bash | grep | wc -l`
if [ $ ALREADY_RUNNING -ge 10 ]
# error occured, return http 503
/bin/echo “HTTP/1.1 503 Service Unavailablern”
/bin/echo “rn”
fi # Get my ip
MYIP=`dig +noall +answer cassandra-local | awk ‘{print $ 5; nextfile;}’` # Get ring information (to verify we can see the whole ring)
# then extract our node status and verify it is Up
ERROR_MSG=`/home/cassandra/bin/nodetool ring | grep “$ MYIP” | grep Up`if [


“$ ERROR_MSG” != “” ]
# all is fine, return http 200
/bin/echo “HTTP/1.1 200 OKrn”
/bin/echo “rn”
# error occured, return http 503
/bin/echo “HTTP/1.1 503 Service Unavailablern”
/bin/echo “rn”


You might also like More from author