DevWork Update: BitShares Witness Monitor

in bitshares •  6 years ago 

Hello everyone,

I have decided to do little steem updates for the various bits of dev work I do.

I just completed work on the first version of a BitShares witness monitoring script with telegram integration.

You can find it here: https://github.com/clockworkgr/bitshares-witness-monitor

First of all, I would like to acknowledge @roelandp 's work (https://github.com/roelandp/Bitshares-Witness-Monitor) for the inspiration.

My monitoring script only checks witness health in its current iteration but price-feed health and seed node might be added in future versions.

I've decided to allow almost full control of the monitoring parameters through access controlled telegram commands so in theory you'd almost never have to restart the monitoring script. You can pause it, update backup keys, resume, change API node used as well as update all of the monitoring parameters.

For example, if you want very "tight" monitoring, you can set the checking interval to 3 seconds (essentially per block), the missed block threshold to 1 missed block before switching and a very large reset time window. Thus ensuring that your signing key is updated to that of your backup witness as soon as a single block is missed.

A "looser" monitoring strategy would be to look for more than 3 missed blocks in quite rapid succession before switching. So missed block threshold at 3, a reset window of 5 minutes (so every 5 minutes the missed block counter gets reset) and checking every 30 secs or so.

You can also force a switch to the backup witness on demand in case you need to undertake some work on one of your witness servers etc.

If any witnesses try it out please take some time to provide feedback, feature requests or bugs you come across by leaving an issue on GitHub.

The following (essentially the repo README file) explains the features better:

To use, clone the repo (or download the zip).

git clone https://github.com/clockworkgr/bitshares-witness-monitor
cd bitshares-witness-monitor
npm install

Open config-sample.json in your favourite text editor and edit with your own settings:

{
    "witness_id": "1.6.XXX",
    "api_node": "wss://<your_preferred_api_node>",
    "private_key": "5kTSOMEPRIVATEKEY111111111111",
    "missed_block_threshold": 3,
    "checking_interval": 10,
    "backup_key": "BTSXXXXXXXXXXXXXXXXXX",
    "reset_period": 300
    "debug_level": 3,
    "telegram_token": "<telegram_access_token>",
    "telegram_password": "<chosen_access_password>",
    "retries_threshold": 3
}

and then save as config.json

private_key
The active key of your normal witness-owning account used to sign the witness_update operation.

missed_block_threshold
How many blocks must be missed within a reset_period sec window before the script switches your signing key. Recommend to set at 2 or higher since 1 will possibly trigger updates on maintenance intervals (see: https://github.com/bitshares/bitshares-core/issues/504)

checking_interval
How often should the script check for new missed blocks in seconds.

backup_key
The public signing key of your backup witness to be used when switching.

reset_period
The time after which the missed blocks counter is reset for the session in seconds.

debug_level
Logging level. Can be:
0: Minimum - Explicit logging & Errors
1: Info - 0 + Basic logging
2: Verbose - 1 + Verbose logging
3: Transient - 2 + Transient messages
but not currently used.

telegram_token
The telegram access token for your notifications bot. You can get one here: https://telegram.me/BotFather

telegram_password
Your chosen access password through telegram.

retries_threshold
Number of failed connections to API node before the bot notifies you on telegram.

Running

Simply use:

node index.js

inside a screen (or similar) session.

For peace of mind I recommend you also install the forever tool:

sudo npm install forever -g

and run as:

forever index.js

instead.

NOTE: In case forever restarts the process, it will start with the DEFAULT config.json you have provided and not with the session-only changes you might have made using the telegram commands below.

Telegram commands

Open a chat to your bot and use the following:

/pass <your_configured_telegram_pass>

This is required to authenticate. Otherwise none of the following commands will work.

/changepass <new_password>

This will update your telegram access password and will require you to authenticate again using /pass

/stats

This will return the current configuration and statistics of the monitoring session.

/switch

This will IMMEDIATELY update your signing key to the currently configured backup key.

/new_key <BTS_public_signing_key>

This will set a new backup key in place of the configured one.

/new_node wss://<api_node_url>

This will set a new API node to connect to.

/threshold X

This will set the missed block threshold before updating signing key to X blocks.

/interval Y

This will set the checking interval to every Y seconds.

/window Z

This will set the time until missed blocks counter is reset to Z seconds.

/retries N

This will set the threshold for failed API node connection attempts to N times before notifying you in telegram.

/reset

This will reset the missed blocks counter in the current time-window.

/pause

This will pause monitoring.

/resume

This will resume monitoring.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Anything that can help the stability of witness nodes should and will be very popular. Thank you for this!

Have never actually looked into steem witnesses but this should probably work there as well with very few (if any) changes...

I think you are very right!

well, if you can, let me know if there is anything special about it / anything that needs to be done or changed so I can provide a Steem version

Wow...wow

And then some... amazing. This is a shining example of witness work on the bitshares blockchain, and probably every witness will be having this available on their mobile phone in no time at all, keeping safe the BitShares decentralized network wherever they may be :)

Outstanding work @clockwork, along with all of us thanks for your amazing efforts lately towards BitShares Blockchain.

Thanks for your amazing work. Bitshares exchange bot also can follow this .It is funny to welcome telegram bot when they are in exchange.

Congratulations @clockwork! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the total payout received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard!


Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @lukestokes


Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

This story is so nice, hope that you will write again. This post will be helpful to us in many ways. Thank you very much for your sweet post dear.

Very helpful your info for us ...thank you sir

Very helpful your info for us ...thank you sir