Skip to main content

Reboot and MetaTrader Monitoring

The second step to monitor that your Windows Server (VPS) is working correctly is to ensure that you get alerted when it restarts, and you get alerted if one or more MetaTrader program stops running (crashes or is closed).

To do that, we will use a PowerShell Script running in the Task Scheduler of your VPS.

The PowerShell Script will send alerts using Telegram, so you will need a Telegram Bot to receive the alerts.

If you don't already have a Telegram bot, this documentation will show you how to create one.

Unzip the ZIP archive to obtain the scripts (if not done already)

Extract archive - Image 1

  1. On your VPS, on the C:\ drive, create a folder named Tools if not already present
  2. In this folder, extract the metatrader_monitor.zip archive
  3. You should obtain a folder named metatrader_monitor.

Uncompressed folder - Image 1

  1. Make sure that the path of the folder is exactly C:\Tools\metatrader_monitor
  2. And that you have those files in it

Create a Telegram Bot to receive alerts

Telegram bot - Image 1

  1. On Telegram, search for the user BotFather and open the conversation

Telegram bot - Image 2

  1. Type the command /newbot
  2. Then provide the Name of your bot
  3. And provide the Username of your bot

Telegram bot - Image 3

  1. You will receive a message saying that your bot has been created successfully.

Telegram bot - Image 4

  1. Click on the link to start the conversation with your bot

Telegram bot - Image 5

  1. By default your bot does not have the right to initiate a conversation, so you will have to be the one sending the first message to your bot to initiate the conversation.

Telegram bot - Image 6

  1. Also make a note of the Bot Token, we will use it later

Obtain your Telegram Chat ID

Telegram Get User ID - Image 1

  1. On Telegram, search for the user https://t.me/userinfobot, and open the conversation

Telegram Get User ID - Image 2

  1. Send a random message, you will receive a response with your User ID. Make a note of this number, we will use it later.

Configure the PowerShell script to receive Telegram alerts

PowerShell - Image 1

  1. On the VPS, open the folder C:\Tools\metatrader_monitor
  2. And locate the file config.ini

PowerShell - Image 2

  1. Open the file, and define the Telegram Bot Token and the Telegram Chat ID that you have obtained earlier, and save the changes.

PowerShell - Image 3

  1. To schedule the PowerShell script automatically, go in the install folder
  2. Do a right click on Install - Task Scheduler - Add metatrader_monitor.ps1
  3. And select Run with PowerShell.

PowerShell - Image 4

  1. It's possible that you will see a warning message, you will have to confirm by typing "Y".

PowerShell - Image 5

  1. Wait 2 minutes, the script should automatically be executed by the Task Scheduler, and you should see 3 text files created.

  2. The file last_boot_time.txt contains the date and time of the last restart of the computer

  3. The file last_metatrader_count.txt contains how many MetaTrader process were seen during the last execution of the script

  4. The file events_journal.txt is simply a journal, and is keeping track of what the script is doing

PowerShell - Image 6

  1. You should also receive a Telegram message to tell you that the script has been initialized correctly.

PowerShell - Image 7

  1. When the server restarts, you should receive a Telegram message

PowerShell - Image 8

  1. When a MetaTrader program is closed, you should receive a Telegram message

PowerShell - Image 9

  1. And if there is no MetaTrader program running anymore, you should receive a Telegram message

Troubleshooting problems

If you have a problem with the Telegram messages not arriving, you can re-read this documentation to make sure you did everything correctly.

PowerShell TroubleShoot - Image 1

  1. If everything was done correctly and you are still not receiving Telegram messages, open the script metatrader_monitor.ps1 with a text editor, and on line 6, change the value of $false to $true. This will show more messages on the screen and it should help you to understand what is the problem.

PowerShell TroubleShoot - Image 2

  1. Delete the text files last_boot_time.txt and last_metatrader_count.txt that have been created, they will be re-created

PowerShell TroubleShoot - Image 3

  1. Execute the script manually, by doing right click, and selecting Run with PowerShell

PowerShell TroubleShoot - Image 4

  1. Look if there's an error message in the script