Status Online is it from api/sno

Hi

I’m writing my node monitoring. How can I check status Online or Offline from API?

image

Thanks

You can call the API endpoint;

http://yournodedashboard:14002/api/sno

Extract the value of lastpinged into variable, then do a time comparison on it against current time.

Syntax not correct it’s late, but extracted from browser Javascript, but something like;

function difference (a,b) {return Math.floor(a.getTime() - b.getTime();}

var drift = difference(new Date, new Date(lastPinged)) / 1000 / 60, status = drift < 120 ? "Online" : "Offline";

There’s probably more to it than that :stuck_out_tongue: I’m not a Javascript expert by any means

2 Likes

How often nodes are pinged?

You can check your audits history, the interval is not hardcoded
See

PowerShell

foreach ($item in ((Invoke-WebRequest http://localhost:14002/api/sno).Content | ConvertFrom-Json).satellites.id) {
    $item;
    ((Invoke-WebRequest http://localhost:14002/api/sno/satellite/$item).Content | ConvertFrom-Json).auditHistory.windows}
}

bash

for item in `curl -sL http://localhost:14002/api/sno | jq '.satellites[].id' -r`; do
    curl -s http://localhost:14002/api/sno/satellite/$item | \
    jq '{id: .id, auditHistory: .auditHistory.windows}'
done

Thank you very much, Alexey.
I was wondering if I can use this information to check if my NODE is online.
For example:
Check “lastPinged” every 60 seconds and if the value changed then it is Online.