Howto: Monitoring UNICORN Binance WebSocket API Manager with ICINGA2
by Oliver Zehentleitner
Documentation: UNICORN Binance WebSocket API
Icinga Plugin: https://exchange.icinga.com/bithon/check_binance_websocket_api_manager
You have two possibilities to provide ICINGA2 the needed data, the first is, you connect it with the check_command through
start_monitoring_api(). This creates a restful api on http://127.0.0.1:64201 and with the icinga plugin 'check_binance_websocket_api_manager' you can report the current status to ICINGA2.
The second possibility is, to get the plain status data via '
get_monitoring_status_plain()' and to build a specific check for your application. If you are planing to build a new plugin for an other monitoring software, please fork our project on github and build a method on top of 'get_monitoring_status_plain()' like 'get_monitoring_status_icinga()' in './unicorn_binance_websocket_api/unicorn_binance_websocket_api_manager.py' and create a pull request. We would appreciate it! ;)
In this "howto" we are going to handle the first method, which is quiet easy :)
We assume you have a ready script with one or more running websockets, than you just have to add this to your code:
If you dont have a ready script, download "example_monitoring.py".
That was the coding part :)
The next step is to learn ICINGA2 to connect with the monitoring API of the UNICORN Binance WebSocket API Manager instance.
start_monitoring_api()' without any parameter starts a restful api server on http://127.0.0.1:64201 and on http://127.0.0.1:64201/status/icinga is the ressource for the check_command. So the check_command needs to be on the same host. If you want to use the check_command from a remote host you have 2 possibilities. One is to start the monitoring API server this way:
But then the service is also available over the network!
The second and in general more secure way is, to use the ICINGA2 agent! To do this, connect the ICINGA2 server and the "websocket server" with the command 'icinga2 node wizard'. There are several blogs handling this topic ask google or use https://www.techrepublic.com/article/how-to-set-up-icinga2-agent-monitoring/.
Download 'check_binance_websocket_api_manager' from https://exchange.icinga.com/bithon/check_binance_websocket_api_manager/releases or https://github.com/unicorn-data-analysis/unicorn-binance-websocket-api/tree/master/tools/icinga to the system of your choice and put it to the plugin direcotory. On debian/ubuntu it should be '/usr/lib/nagios/plugins' and make it execute able with 'sudo chmod +x ./check_binance_websocket_api_manager' and make a test run. If the check_command and the binance websocket app are on the same server the check_command can use the default value (127.0.0.1) so the command is simple './check_binance_websocket_api_manager' and should return someting like:
BINANCE WEBSOCKETS - WARNING: O:18/R:0/C:0/S:0 - Update 1.3.3 available! | receives_per_second=713;;;0 kb_per_second=513;;;0 received_mb=6385;;;0 stream_buffer_mb=0;;;0 stream_buffer_items=3;;;0 reconnects=0;;;0
If this works fine, then you can go ahead and configure ICINGA2.
It doesnt matter if you use files or the Icinga2 Director Module to configure ICINGA2 objects, the first step is creating a new command template (director -> commands -> command templates). The command type is "Plugin Check Command", name it how you like it, but common would be something like "check_binance_websocket_api_manager" and the command has to be './check_binance_websocket_api_manager', then save it.
Then create a "command" in (director -> commands -> command). Command type is "Plugin Check Command", command name is your choice and imports should be the template you created before.
Then create a service template in (director -> services -> templates)... now it depends very on your general structure and you should be able to overtake further confguration from here.
Good luck and have fun!