Skip to content

Monitoring Multiple Harvesters

pieterhelsen edited this page Apr 28, 2021 · 3 revisions

Setting up your local machine

You can run multiple instances of chiadog on a single machine and monitor all your harvesters remotely. The logs on remote machines are accessed through SSH, so you'll have to setup ssh-key based authentication with your harvesters.

chiadog is compatible with all major operating systems and the basic steps for setting up remote harvesting from your local machine are the same on each platform (the implementation is a little more involved on Windows):

  1. Set up an SSH key pair on the local machine
  2. Copy the public SSH key to all remote harvesters
  3. Test the SSH connection and add the fingerprint
  4. On the local machine, prepare a config file for each harvester
  5. Start separate chiadog instances for each harvester

Before you get started with remote monitoring, you will have to set up an SSH key pair on your local machine (the one that will run Chiadog).

1. Setting up SSH keys

This step only takes a minute, follow Github's guide on Generating a new SSH key . It provides detailed information for Linux, Windows and MacOS. If you specify a password for your key, you'll also need to follow the second step in the guide and add your SSH key to the ssh-agent. The agent should remember and manage your password because chiadog doesn't know it.

2. Copy SSH key to all machines running a harvester

Before Chiadog can connect to your remote harvesters, you will need to copy your local machine's public SSH key to each remote harvester. There are three possible scenarios:

  • Both your local and remote machines run Linux or MacOS
  • Your local machine is Windows-based
  • Your remote harvester is Windows-based

Linux / MacOS

If both your local and remote machines run on Linux or MacOS you can use ssh-copy-id as described below. If you're running a remote harvester on Windows, make sure to follow the steps detailed in Remote Windows Harvester first before continuing with the steps below.

ssh-copy-id <user>@<ip_address>

which will take your default SSH key, or specify it explicitly when you have multiple SSH key pairs:

ssh-copy-id -i "~/.ssh/id_ed25519" <user>@<ip_address>

Local Windows

The OpenSSH Client on Windows/PowerShell does not support ssh-copy-id. Two methods are available to you:

  • Manually copy/paste the public key into the authorized_keys file on the remote machine
  • Use the below PowerShell command to copy your public key to the remote machine (only works if the harvester is Linux or MacOS-based)

type $env:USERPROFILE\.ssh\id_rsa.pub | ssh <user>@<ip_address> "cat >> .ssh/authorized_keys"

Remote Windows Harvester

Setting up remote monitoring for a Windows-based harvester is a little more involved and requires you to install OpenSSH Server. Follow these steps to enable OpenSSH Server on Windows 10:

  1. Open the Start Menu
  2. Open the 'Settings' app (type 'settings' or locate it at the bottom-left side of the Start Menu)
  3. Click on 'Apps' > 'Optional Features' > 'Add a feature'
  4. Select OpenSSH Server and click 'Install' (if it does not appear, look through the list of already Installed Features.)

Next, you need to start the service and ensure that it is started automatically when the system restarts.

  1. Open the Start Menu
  2. Open an elevated 'PowerShell' command prompt (right-click PowerShell and click 'Run as Administrator')
  3. Run Start-Service sshd to start the service
  4. Run Get-Service sshd to verify that the service was started successfully
  5. Run Set-Service -Name sshd -StartupType 'Automatic' to ensure the service starts at boot.

Finally, you'll need to set up an authorized_keys file that allows access for your key.

  1. Open Explorer and navigate to C:\Users\YOUR-USER\.ssh\
  2. Create a blank text file and paste in the client's Public SSH Key.
  3. Save the file as authorized_keys (note: make sure to remove the .txt extension)

IMPORTANT

If the user is in the local Administrators group, you will need to place the key in the following file instead: C:\ProgramData\ssh\administrators_authorized_keys.

You will also need to set the proper Access-Control List (ACL) permissions for the file. Open another elevated PowerShell and run the following script:

$acl = Get-Acl C:\ProgramData\ssh\administrators_authorized_keys
$acl.SetAccessRuleProtection($true, $false)
$administratorsRule = New-Object system.security.accesscontrol.filesystemaccessrule("Administrators","FullControl","Allow")
$systemRule = New-Object system.security.accesscontrol.filesystemaccessrule("SYSTEM","FullControl","Allow")
$acl.SetAccessRule($administratorsRule)
$acl.SetAccessRule($systemRule)
$acl | Set-Acl

3. Test the SSH connection

Once you've set up both the local and the remote(s), try to SSH into the remote machine with the key to make sure it works. You'll also be prompted to add the remote machine's fingerprint to your known_hosts file which is a pre-requisite to establish a connection from chiadog.

Run this command from your local machine where you will be running chiadog:

ssh -i "~/.ssh/id_ed25519" <user>@<ip_address>

4. Prepare configs for each harvester

  1. On your local machine, open config.yaml in your editor and enable network_log_consumer.

    • Make sure that file_log_consumer is disabled (or delete that section)
    • Configure remote_user for your remote harvester machine
    • Configure remote_host for your remote harvester machine
    • Double check that remote_file_path exists on the remote machine
  2. Copy config.yaml into multiple configs for each remote harvester, e.g.:

    • cp config.yaml config-harvester-1.yaml
    • cp config.yaml config-harvester-2.yaml
    • cp config.yaml config-harvester-3.yaml
  3. Adjust the remote_user and remote_host for each machine.

    • You can also specify different notification_title_prefix so that you can more easily distinguish between notification from each of your harvesters.
  4. Adjust the remote_file_path for each machine.

    • On Linux-based machines, you can use the tilde (~) to expand to the user directory. E.g. ~/.chia/mainnet/log/debug.log
    • On Windows machines, you need to specify the absolute path to the log file. E.g. C:\Users\MY-USER\.chia\mainnet\log\debug.log

5. Start a chiadog instance for each harvester

Start chiadog for each harvester in a separate terminal.

  • On Linux or MacOS, I recommend tmux as it allows you to split your terminal in multiple windows and have a cockpit-like overview.
  • On Windows, there unfortunately isn't a worthy substitute and you are left running multiple command line prompts or PowerShell sessions.
. ./venv/bin/activate
python3 main.py --config config-harvester-1.yaml
. ./venv/bin/activate
python3 main.py --config config-harvester-2.yaml
. ./venv/bin/activate
python3 main.py --config config-harvester-3.yaml