Nurse is a multithread health check/port detect tool for small/medium cluster using tcp syn-scan(syn, syn-ack, rst), for those unstable ports, it can send Alert message via DingTalk Robot Api.
Health check is common in many tools, like Load Balancing or Service Discovery, even some Monitor Systems. But most of them are too heavy to use, sometimes we(OP/Devops) just want a simple monitor tool which can alert us when the server crashed and when it recoverd, to help us decide whether further operations needed, especially for small teams with no well-established monitor systems. That's why Nurse is introduced here.
It's simple, only one main file with three header files, no complex dependency.
It's easy, combined with naming service and crontab it can adjust targets automatically.
It's rapid, only few milliseconds needed for hundreds targets, and alert immediately
Linux env, gcc version > 4.8, curl-devel
cd nusrse && make
, if no error, nurse will be generated in the same directory.
./nurse -h
Usage: ./nurse -[frh]
-f file contains detect target with format:[ip:port\tserv_name], ie.: 192.168.0.1:80 test
-r dingding robot url
-h print this help message
For any questions pls feel free to contact frostmourn716@gmail.com
NOTICE: It requires root privilege to run because using raw socket. For how does Nurse work, you can refer Using raw socket to do port scan(1) and Using raw socket to do port scan(2)
To get a DingTalk Robot url you can refer DingTalk Open Api. After adding a robot you can get an url, using https://oapi.dingtalk.com/robot/send?access_token=123
as an example.
Detecting targets are organized in a text file, for example:
cat detect_host.txt
172.30.4.33:8725 classify
172.30.4.33:8727 rnncn
To run nurse, using:
./nurse -f ./detect_host.txt -r https://oapi.dingtalk.com/robot/send?access_token=123 > log.txt 2>&1 &
If every thing is ok, it will log like this:
If some ports are unstable, nurse will send alert message like this:
Now Nurse is just a simple health monitor tool on single server with little configuration for hundreds targets, if needed, it can be extended for larger cluster and support more alert methods.