Get Real-Time Alerts from the Avalanche Network

Avalanche Português
8 min readJan 10, 2021

Keep an eye on the operational status of your Avalanche node every minute.

The Avalanche mainnet was launched on September 21, 2020.

Currently, there are more than 1,000 validators that maintain their Avalanche network node.

Faced with the need to keep knots healthy continuously, the following question arises:

How can we know instantly if our Avalanchego process has been interrupted, if not healthy or if there is a high CPU consumption, which is a sign that something is wrong with your Avalanche network node.

Given the importance of monitoring ontim and the health of your Avalanche network node, we will create our bot, via Telegram, integrated with a script with commands that will be configured to enable you to monitor Avalanchego that includes the real-time alert system of your node Avalanche network. To do this, we will create a customized bot and install a script on the Ubuntu operating system of our virtual machine that supports its Avalanche network node, in order to obtain a real-time alert if the Avalanchego process is inactive, with problems or if the consumption of The virtual machine’s CPU is high.

If you have not yet created your Avalanche network node, then click on the image below:

Why Telegram?

Telegram is one of the most used programs for instant messaging and is known for the possibility of having bots that interact with the user privately or within groups. We will use Telegram BotFather which is the only bot that controls them all — creates a new bot account and manages your bots.

Creating the Telegram Bot

  1. After accessing Telegram, in the search tab type Botfather . Note that the official Telegram bots have a blue check mark next to their names. Click on BotFather.

Then click “Start” to activate the BotFather bot.

2. Choose the command /newbotand click.

3. Choose a name for your bot. In this example we choose “testavalanchego”.

4. Now choose a username for your bot — the bot can be found by your username in searches. The username must be unique and end with the word “bot”. Therefore, you must provide a unique username that ends with the word ‘bot’. In this example we choose “testavalanchego_bot”.

After choosing a suitable name for your bot — the bot is created.

You will receive a message with a link to your bot t.me/name_your_bot, recommendations for setting up a profile image, description and a list of commands to manage your new bot.

5. After giving your bot username, your TOKEN will be available as noted below:

Note : Copy the alphanumeric code of your TOKEN , as we will use it later! Note that TOKEN is the code right after “HTTP API:”.

6. Let’s start communicating with our bot.

6.1. Enter the name of your bot in the search tab and choose it (in our example it is testavalanchego).

6.2. Click on the “Start” button and you will be subscribed to your bot.

6.3. Type “/ start”.

We must remember that we already have a TOKEN.

7. The next step is to obtain the CHAT ID (chat ID of the bot).

These two parameters — TOKEN and CHAT ID — are mandatory for creating the script for the real-time alert system of your Avalanche Network node.

Access the virtual machine that supports your Avalanche network node.

First install the “jq” utility, set your TOKEN variable and, using the curl command, obtain your chat ID as shown below:

From this moment on we will introduce — copy and paste — each line of code and “enter”, successively, line by line, until the last command line, in the SSH Web session (black window) of Elastic VPS, in the following order:

sudo apt-get install jq -yTOKEN=inserir_aqui_o_código_do_seu_tokencurl -s https://api.telegram.org/bot$TOKEN/getUpdates | jq .result[0].message.chat.id

Note-1 : After entering the command line curl -s https://api.telegram.org/bot$TOKEN/getUpdates | jq .result [0] .message.chat.id, if CHAT_ID is not available , access your Telegram and type “/ start” in your bot and run the command curl -s https://api.telegram.org/ bot $ TOKEN / getUpdates | jq .result [0] .message.chat.id again. It is okay to type “/ start” 3 to 4 times, in the same way, re-enter the command line curl -s https://api.telegram.org/bot$TOKEN/getUpdates | jq .result [0] .message.chat.id until the CHAT_ID code appears.

Avalanchego Monitoring Script

The Avalanchego monitoring script, which includes the real-time alert system of your Avalanche network node, performs three fundamental checks every minute, as shown below:

  • if the avalanche process is working;
  • if the avalanche process is healthy; and
  • CPU usage (the default limit is 40%).

Our Avalanchego monitoring script has 2 mandatory and 2 optional parameters, which are:

  • Mandatory are TOKEN and CHAT ID; and
  • Optional are CPU and IP limit. Many validators have IP 127.0.0.1 to obtain their API calls. If you do the same, to avoid having to change the IP parameter, the default is 127.0.0.1. The default limit value for the CPU is 40%. If you want you can change it to any value you want. Do not forget to use 2 digits after the period, such as 50.00, 75.90, etc.

Avalanchego Monitoring Script Installation

  1. After accessing the Ubuntu operating system of the virtual machine that supports your Avalanche network node, in the “home directory” enter — copy and paste — each line of code and hit “enter”, successively, line by line, until the last command line , in the following order:
cdapt-get install gitgit clone https://github.com/burcusan/telegram-monitor-scripts.gitcd telegram-monitor-scripts./install_avax_monitor.sh -t insert_here_the_code_of_your_token -c insert_here_the_code_of_your_token_CHAT_IDsed -i 's/health.getLiveness/health.health/g' check_avalanchego_status.sh

In this script we are using the default parameters for a 40% CPU limit and API call IP is 127.0.0.1.

Now do the test to verify that your script is working correctly. To do this, enter — copy and paste —the block of code and hit “enter”, below:

./check_avalanchego_status.sh > check_avalanchego_status.logcat check_avalanchego_status.log

Finally, take the test to verify that the script installation is working as scheduled. To do this, enter — copy and paste — the line of code and hit “enter”, below:

./check_avalanchego_status.sh test

If the script has been installed correctly, the test message will be sent to your Telegram bot as noted below:

Fri Oct 2 16:25:53 +03 2020 — [TEST] [TEST] Avalanchego node TEST message !!!..

Check the test message received by your Telegram bot.

If the limit of any of the three parameters of the script has been violated, check the alert message received by your Telegram bot.

Below we see a series of alert messages received by your Telegram bot.

Note that after the violation of any of the three parameters has been remedied, the resolved alert message will be received by your Telegram bot.

Conclusion

Our script will alert you, via your Telegram bot, if your Avalanche network node is not active, is not healthy or the CPU is over 40% in use, in addition to alerting you when any of the three problems is corrected. The script checks your node every minute, but does not generate or send an alert every minute. The scritp sends the alert message with the [ALERT FIRING] tag to your Telegram bot if the problem persists for:

1 minute, 5 minutes, 15 minutes, 30 minutes, 1 hour, 2 hours, 6 hours, 12 hours and 24 hours.

Therefore, the maximum number of alerts you will receive is 8 every 24 hours, if the problem persists. After sending 8 messages, the script stops sending alert messages with the tag [ALERT FIRING]. It should be noted that it is the responsibility of the node maintainer to correct the problem. But as the script continuously checks every minute, if the problem is resolved, the script will immediately send the alert message with the [ALERT RESOLVED] tag to the user without any time limit.

Canceling Alert Messages

If you no longer want to receive alerts via your Telegram bot, just remove a line from the script in your crontab file. Edit it via crontab -e and remove or comment (put # at the beginning of the line) the related line as shown below:

#* * * * * /home/username/telegram-monitor-scripts/check_avalanchego_status.sh > /home/username/telegram-monitor-scripts/check_avalanchego_status.log 2>&1

Source: https://medium.com/ava-hub/how-to-get-real-time-alerts-from-your-avalanchego-validator-node-8bb883144152

About Avalanche

Avalanche is an open-source platform for launching decentralized applications and enterprise blockchain deployments in one interoperable, highly scalable ecosystem. Avalanche is able to process 4,500+ transactions/second and instantly confirm transactions. Ethereum developers can quickly build on Avalanche as Solidity works out-of-the-box.

Website | Whitepapers | Twitter | Discord | GitHub | Documentation | Explorer | Avalanche-X | Telegram | Facebook | LinkedIn | Reddit | YouTube

Aviso Legal

“Esse artigo é meramente informativo e não é uma recomendação de investimento, o mercado de criptomoedas é bastante volátil e você deve pesquisar e decidir por si mesmo em que investir, especialmente em mercados de alto risco”.

--

--

Avalanche Português

Aviso Legal: Todos os artigos são meramente informativos e não são recomendações de investimento. Você deve pesquisar e decidir por si mesmo em que investir.