Simple Smartnode/Masternode Monitoring For The Command Line

in #smartcash6 years ago (edited)

In this article, I present to you an easy but powerful way to keep track of your Masternode stats in the command line.

Leave Things BETTER than you found them.
~ Robert Baden Powell

This is what I thought when I recently logged into my Smartnode (Smartcash Masternode) in order to upgrade it to the latest version. Afer upgrading, it takes some time for the smartnode to catch up with loading and processing the latest blocks. Fortunately, there is the handy smartcash-cli that supports us with the means to get the latest info about the node.

Of course, you can apply these ideas also to other masternodes respectively!

I had two wishes to optimize the information output for my smartnode:

  1. Compile the results of smartcash-cli smartnode status and smartcash-cli getinfo into one nice output
  2. Create a handy command to display this output every second, so I can see almost in realtime, when my smartnode server is ready

Let's develop!

To cope with the first wish, we can create a very basic bash script which we're gonna call checknode.sh. Here's the code:

#!/bin/bash
echo "--------------------------------------------------"
echo "-- smartcash-cli smartnode status               --"
echo "--------------------------------------------------"
smartcash-cli smartnode status
echo ""
echo "--------------------------------------------------"
echo "-- smartcash-cli getinfo                        --"
echo "--------------------------------------------------"
smartcash-cli getinfo

As you can see, the script just displays the results of both commands one after the other.

In order to make the script actually executable, it needs to be chmodded to add execution rights for the owner:

chmod u+x ./checknode.sh

Refresh the status information every second

Now there is a fine little program called watch, which is most likely alreeady installed on your machine. Watch executes a command and displays its output every X seconds, where X is a command line argument. So I used this command to let watch print my server status every second:

watch -n 1 ~/checknode.sh

That gives the following output:

Pretty nice!

Create an alias for your convenience!

In order to make it even more convenient, we create an alias, and we also add that alias to .bashrc (so it is being created every time we log into the server):

alias checknode='watch -n 1 ~/checknode.sh'
echo "alias checknode='watch -n 1 ~/checknode.sh'" >> ~/.bashrc

Now, we can track the node's information by simply typing checknode into the terminal.

A Bonus

One last thing: It might be a nice idea to display the node's information once right after logging in. To do this, we simply let bash execute our checknode.sh script after loggin in. Again, we just need to append the respective command to the .bashrc file:

echo "~/checknode.sh'" >> ~/.bashrc

That's it - with some simple commands we created a nice-looking status monitoring command for our terminal.

Have fun!

Coin Marketplace

STEEM 0.28
TRX 0.13
JST 0.032
BTC 66304.34
ETH 2983.64
USDT 1.00
SBD 3.68