Recent Posts

Sponsors
![]() |
Monitoring services with xinetdMike Peters, 08-31-2014 |
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/cassandra_status.sh
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.
#!/usr/local/bin/bash
#
# Check if swap is over 20%
SWAP=`top -n | grep Swap | awk '{print $8 + 0}'`
if [ $SWAP -ge 20 ]
then
# error occured, return http 503
/bin/echo "HTTP/1.1 503 Service Unavailable\r\n"
/bin/echo "\r\n"
exit
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 cassandra_status.sh | wc -l`
if [ $ALREADY_RUNNING -ge 10 ]
then
# error occured, return http 503
/bin/echo "HTTP/1.1 503 Service Unavailable\r\n"
/bin/echo "\r\n"
exit
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" != "" ]
then
# all is fine, return http 200
/bin/echo "HTTP/1.1 200 OK\r\n"
/bin/echo "\r\n"
else
# error occured, return http 503
/bin/echo "HTTP/1.1 503 Service Unavailable\r\n"
/bin/echo "\r\n"
fi
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/cassandra_status.sh
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.
#!/usr/local/bin/bash
#
# Check if swap is over 20%
SWAP=`top -n | grep Swap | awk '{print $8 + 0}'`
if [ $SWAP -ge 20 ]
then
# error occured, return http 503
/bin/echo "HTTP/1.1 503 Service Unavailable\r\n"
/bin/echo "\r\n"
exit
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 cassandra_status.sh | wc -l`
if [ $ALREADY_RUNNING -ge 10 ]
then
# error occured, return http 503
/bin/echo "HTTP/1.1 503 Service Unavailable\r\n"
/bin/echo "\r\n"
exit
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" != "" ]
then
# all is fine, return http 200
/bin/echo "HTTP/1.1 200 OK\r\n"
/bin/echo "\r\n"
else
# error occured, return http 503
/bin/echo "HTTP/1.1 503 Service Unavailable\r\n"
/bin/echo "\r\n"
fi
|

Subscribe Now to receive new posts via Email as soon as they come out.
Comments
Post your comments