User avatar
ViperTKD
Lisker
Posts: 66
Joined: Mon Apr 04, 2016 11:06 pm
Location: Quebec, Canada
Contact: Facebook Twitter

How to monitor block sync status and forging status with PRTG

Sun May 08, 2016 1:13 am

This guide describes how to create custom PowerShell scripts in PRTG (Paessler Network Monitoring Tool) to monitor your node block sync status as well as your forging status.

First, you will need PRTG installed and running on your computer. You can get it here and it's free for up to 100 sensors which is more than enough for what we need:
https://www.paessler.com/

Once you've got PRTG installed and running, you can create your sensor.

First, you need to create a device for your node:
  1. In the Devices menu, click on Add Device
  2. Then select a group (You might have to create one if you don't have one yet. You can call it Lisk)
  3. Name your device. For example: Node-1
  4. Then enter the IP address of your node or the DNS name (for example yournode.yourdomain.com)
  5. Click Continue

Now, copy the two following scripts in this folder: C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML

Lisk-BlockHeightStatus.ps1

Code: Select all

#
# Lisk-BlockHeightStatus.ps1
# Return the last block age and height in a PRTG ready format
# v0.5
# by ViperTKD
#
# Usage: .\Lisk-BlockHeightStatus.ps1 [hostname]
#
# [hostname] = hostname or IP address (i.e. lisk.mydomain.com)
#
Param(
  [Parameter(Mandatory=$True,Position=1)]
   [string]$hostname
)

$r = Invoke-WebRequest -UseBasicParsing -Uri https://$hostname/api/loader/status/sync
$height = ($r.content | convertfrom-json).height

$r2 = Invoke-WebRequest -UseBasicParsing -Uri https://$hostname/api/blocks?height=$height
$blocktimestamp = ($r2.content | convertfrom-json).blocks.timestamp
$age = ((Get-date)-([timezone]::CurrentTimeZone.ToLocalTime(([datetime]'4/9/2015').Addseconds($blocktimestamp)))).TotalSeconds

$out = "<prtg>`r`n"
$out += "<result>`r`n"
$out += "<channel>Block Age</channel>`r`n"
$out += "<Float>1</Float>`r`n"
$out += "<Unit>sec</Unit>`r`n"
$out += "<value>$age</value>`r`n"
$out += "</result>`r`n"
$out += "<result>`r`n"
$out += "<channel>Block Height</channel>`r`n"
$out += "<Unit>Count</Unit>`r`n"
$out += "<Float>0</Float>`r`n" 
$out += "<value>$height</value>`r`n"
$out += "</result>`r`n"   
$out += "</prtg>`r`n"
Write-Output $out


Lisk-ForgingStatus.ps1

Code: Select all

#
# Lisk-ForgingStatus.ps1
# Return the last forged block age and height as well as the forging status in a PRTG ready format
# v0.5
# by ViperTKD
#
# Usage: .\Lisk-ForgingStatus.ps1 [hostname] [account]
#
# [hostname] = hostname or IP address (i.e. lisk.mydomain.com)
# [account] = Your Lisk Delegate account number (i.e. 1234567890123456789L)
#
Param(
  [Parameter(Mandatory=$True,Position=1)]
   [string]$hostname,
  [Parameter(Mandatory=$True,Position=2)]
   [string]$account
)

$r = Invoke-WebRequest -UseBasicParsing -Uri https://$hostname/api/accounts?address=$account
$publickey = ($r.content | convertfrom-json).account.publicKey

$r2 = Invoke-WebRequest -UseBasicParsing -Uri "https://$hostname/api/blocks?generatorPublicKey=$($publickey)&limit=1&orderBy=height:desc"
$blocktimestamp = ($r2.content | convertfrom-json).blocks.timestamp
$height = ($r2.content | convertfrom-json).blocks.height
$age = ((Get-date)-([timezone]::CurrentTimeZone.ToLocalTime(([datetime]'4/9/2015').Addseconds($blocktimestamp)))).TotalMinutes

$r3 = Invoke-WebRequest -UseBasicParsing -Uri "https://$hostname/api/delegates/forging/status?publicKey=$publickey"
$forgingstatus = ($r3.content | convertfrom-json).enabled

$out = "<prtg>`r`n"
$out += "<result>`r`n"
$out += "<channel>Forging BlockAge</channel>`r`n"
$out += "<Float>1</Float>`r`n"
$out += "<Unit>Custom</Unit>`r`n"
$out += "<CustomUnit>min</CustomUnit>`r`n"
$out += "<value>$age</value>`r`n"
$out += "</result>`r`n"
$out += "<result>`r`n"
$out += "<channel>Last forged block height</channel>`r`n"
$out += "<value>$height</value>`r`n"
$out += "</result>`r`n"   
$out += "<result>`r`n"
$out += "<channel>Forging Status</channel>`r`n"

if ($forgingstatus) {
     $out += "<value>1</value>`r`n"
    $out += "</result>`r`n"   
    $out += "<Text>Forging Status On</Text>`r`n"
} else {
     $out += "<value>0</value>`r`n"
    $out += "</result>`r`n"   
     $out += "<error>1</error>`r`n"
    $out += "<Text>Forging Status Off</Text>`r`n"
}
$out += "</prtg>`r`n"
Write-Output $out


We are now ready to create the sensors:
  1. In the Sensors menu, click on Add Sensor
  2. Select Custom Sensors under Monitor What?
  3. Select EXE/Script Advanced
  4. Give your new sensor a new (i.e. Block Sync Status)
  5. Under EXE/Script, select Lisk-BlockHeightStatus.ps1
  6. Under Parameters, type '%host'
  7. Uncheck Inherit from ... Node-1 under Scanning Interval
  8. Select 30 seconds under Scanning Interval
  9. Click on Continue

You can repeat the same operation and create a new sensor for Lisk-ForgingStatus.ps1

Now you can go and configure the channel in the sensor:
  1. Click on the sensor
  2. Now, in the middle on the screen where you can see the Block Age and Block Height channel, click on the Settings icon for Block Age
  3. Set the Vertical Axis Scaling to Manual Scaling with a minimum of 0 and maximum of 60
  4. Set the Limits to Enable Limits with Upper Error at 30 and Upper Warning at 20
  5. Click on Ok

You can repeat the same steps for the other sensor.

Here you go you're now setup! Now you can customize your Notifications settings to your likings.

Enjoy!!
Check my Delegate Candidacy : https://forum.lisk.io/viewtopic.php?f=6&t=246

Return to “Guides”

Who is online

Users browsing this forum: No registered users and 1 guest