mikehw / chiadog

A watch dog providing a piece in mind that your Chia farm is running smoothly 24/7.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Photo by Zoltan Tukacs on Unsplash


Watchdog for your Chia farm

So you've become a Chia farmer and want to maximize the probability of getting a reward? Chiadog helps with automated monitoring and sends you a mobile notification in case something appears to malfunction.

Supported Notifications

Subsystem Notification (example values) Priority
Harvester Your harvester appears to be offline! No events for the past 400 seconds. HIGH
Harvester Disconnected HDD? The total plot count decreased from 100 to 40. HIGH
Harvester Experiencing networking issues? Harvester did not participate in any challenge for 120 seconds. It's now working again. NORMAL
Harvester Seeking plots took too long: 40 seconds! NORMAL
Harvester Found 1 proof(s)! LOW
Full Node Experiencing networking issues? Skipped some signage points! Last 12/64, current 43/64. NORMAL

How it works?

It parses the debug.log generated by the chia process and runs various checks to determine the health of your farmer. Among others, it can detect if your node has lost sync and the farmer is no longer participating in challenges, or if one of your external HDDs disconnected and your harvester doesn't have access to the full amount of plots you have.

Supported Integrations for Notifications

The following integrations are optional - chiadog is not dependent on any of them and can also run standalone. That being said, you'll get the most value out of it, when you connect with one of the services below to receive real-time notifications about important events. You can also enable more than one at the same time - please refer to the config-example.yaml.

Pushover

Pushover is available for both Android and iOS. High priority notifications can be configured from the Pushover app to overwrite any Silence or Do-Not-Disturb modes on your phone and sound a loud alarm at any time of the day to make you aware of any issues in a timely manner.

  • Costs: ~$5 one time payment for mobile app after 30 day trial.
  • Advantages: Easy setup, high priority notifications can override your phone's silent mode.

You can test if your the setup works correctly with:

PUSHOVER_API_TOKEN=<api_token> PUSHOVER_USER_KEY=<user_key> python3 -m unittest tests.notifier.test_pushover_notifier

Telegram

This integration uses the Telegram's Bot API. You can create a new bot for yourself by sending a message to BotFather.

For chat_id you need to enter your Telegram username or ID. For me only ID worked, you can find out your Telegram ID by messaging the IDBot. You need to also first message your bot to make sure it knows about you and can send you notifications.

  • Costs: $0
  • Advantages: It's free and not additional apps are required.

You can test if your bot works correctly with:

TELEGRAM_BOT_TOKEN=<bot_token> TELEGRAM_CHAT_ID=<your_id> python3 -m unittest tests.notifier.test_telegram_notifier

Custom Script (beta)

Beware: This feature is in beta stage and future versions might not maintain backward compatibility! Currently, you need to parse out information from the message text which might change. In the future there'll be a different mechanism for identifying message type and payload.

Test your script is called correctly with:

python3 -m unittest tests.notifier.test_script_notifier

Slack, WhatsApp, E-Mail, ...?

These integrations can be easily added. Contributions are welcome!

Getting started

Pre-requisites

  • UNIX-based OS (Linux/Mac) - contributions to support Windows are welcome!
  • Python 3.7+
  • Enabled INFO logs on your chia farmer

How to enable INFO logs on chia farmer?

First configure the log level to INFO. This ensures that all logs necessary for chiadog to operate are available under ~/.chia/mainnet/log/debug.log.

chia configure -log-level=INFO

Then restart your farmer to apply the changes:

chia start --restart farmer

Check that logs are coming in:

cat ~/.chia/mainnet/log/debug.log

Installation

For updating from previous version, see section below.

  1. Clone the repository
git clone https://github.com/martomi/chiadog.git
cd chiadog
  1. Create virtual env (Recommended)
python3 -m venv venv
. ./venv/bin/activate
  1. Install the dependencies:
pip3 install wheel && pip3 install -r requirements.txt
  1. Copy the example config file
cp config-example.yaml config.yaml
  1. Open up config.yaml in your editor and configure Pushover.
    • Enable Pushover Notifier
    • Set your Pushover API token
    • Set your Pushover user key

Updating to the latest release

Skip this if you followed above section.

cd chiadog
. ./venv/bin/activate

git fetch
git checkout main
git pull

pip3 install -r requirements.txt

Important: Automated migration of config is not supported. Please check that your config.yaml has all new fields introduced in config-example.yaml and add anything missing.

Monitoring a local harvester / farmer

  1. Open config.yaml and configure file_log_consumer:

    • You need to enable the file log consumer to read local chia log files
    • Double-check that the path to your chia logs is correct
  2. Start the watchdog

python3 main.py --config config.yaml
  1. Verify that your plots are detected. Within a few seconds you should see INFO log:
Detected new plots. Farming with 42 plots.

Remote monitoring of multiple harvesters

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.

Setting up SSH keys

This step only takes a minute, follow Github's guide on Generating a new SSH key . If you specify 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 ssh-agent should remember and manage your password because chiadog doesn't know it.

Copy SSH key to all machines running a harvester

On Linux you can use ssh-copy-id:

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

which will take your default SSH key, or specify it explicitly:

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

Prepare configs for each harvester

  1. Open config.yaml in your editor and enablenetwork_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
  1. 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.
  2. Start chiadog for each harvester in a separate terminal. I recommend tmux as it allows you to split your terminal in multiple windows and have a cockpit-like overview.

python3 main.py --config config-harvester-1.yaml
python3 main.py --config config-harvester-2.yaml
python3 main.py --config config-harvester-3.yaml

Troubleshooting

The best way to check that everything works on your system is to run the unit tests:

python3 -m unittest

All tests are expected to complete with an OK status. It's highly recommended to also run the notification specific tests described in the notification section above.

You can enable more verbose logging from config.yaml by changing INFO to DEBUG. You should see logs for every keep-alive event from the harvester.

Advanced Stuff

Running chiadog in the background

nohup python3 -u main.py --config config.yaml > output.log &

To stop chiadog, you can find the Process ID (PID) via ps aux | grep main.py and then softly interrupt the process with kill -SIGINT <pid_here>.

I'm getting spammed by skipped signage point notifications!

You might be plotting too hard or your computer cannot keep up for some other reason. You shouldn't be getting more than 10 of these notifications per day. In a future version there'll be configuration to adjust the threshold or to only send a daily summary on skipped signage points.

For now, if you don't want to get bothered by them, I recommend to replace this line with return None. This will only stop the signage point notifications. You still will get notified about more critical issues.

Running chiadog in sandboxed environment

We're in the early stages of exploring the best way to provide easy to setup sandboxed environment where the chiadog process is completely isolated from potentially accessing your private keys. Contributions in that direction are very welcome. Meanwhile you can check out @ajacobson repository for chiadog-docker.

Contributing

Contributions are always welcome! Please refer to CONTRIBUTING documentation.

About

A watch dog providing a piece in mind that your Chia farm is running smoothly 24/7.

License:MIT License


Languages

Language:Python 99.8%Language:Shell 0.2%