Monitor STEEM RPC Nodes with PHP Crontab Job

in #witness-category5 years ago

I have 5 API nodes for STEEM - and I have written a crontab job (in PHP) that runs every minute - sending request to these nodes to check their availability - in case of failures, I'll get email notification immediately.

See https://steemyy.com/witness-nodes.php

image.png

$nodes = array(
    "api.steemyy.com" => "https://api.steemyy.com",
    "api.justyy.com" => "https://api.justyy.com",
    "steem.justyy.workers.dev" => "https://steem.justyy.workers.dev",
    "aws.lambda-ap-northeast-1" => "https://x68bp3mesd.execute-api.ap-northeast-1.amazonaws.com/release",
    "aws.lambda-us-east-1" => "https://e51ewpb9dk.execute-api.us-east-1.amazonaws.com/release"
);

foreach ($nodes as $key=>$node) {
    $logfile = "/var/log/" . $key ."-" . date("Y-m-d-H") . ".txt";
    $report = "STEEM node check for $node..\n";
    echo "STEEM node check for $node..\n";
    $send_email = file_exists($logfile);
    for ($i = 0; $i < 10; ++ $i) {
      $code = statusCode($node);
      if ($code == 200) break;
      usleep(100000);
    }
    $ok = true;
    if ($code != 200) {
        $ok = false;
        $report .= "code = $code\n";
    } else {
        $data = file_get_contents($node);
        $json = json_decode($data, true);
        if ((!$data) || (!$json) || ($json['status'] !== 'OK') || ($json['docker_tag'] != 'latest')) {
            $report .= "Status Not OK: $data\n";
            $ok = false;
            echo "Status NO OK.\n";
        }
    }
    if (!$ok) {
        echo $report;
        if (is_file($logfile)) {       
            $x = trim(file_get_contents($logfile));
            file_put_contents($logfile, $x . "\n" .$report);
        } else {
            file_put_contents($logfile, $report);
            // first time in his hour, then send email to alarm
            sendEmail("STEEM node check for $node..", $report);
            usleep(100000);
        }       
    }  else {
        echo "OK.\n";
    }
}

@steemcurator01
@steemcurator02
@steemcurator03
@steemcurator04
@steemcurator05
@steemcurator06
@steemcurator07
@steemcurator08
@steemcurator09

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Thank you for reading ^^^^^^^^^^^^^^^

Follow me for topics of Algorithms, Blockchain and Cloud.
I am @justyy - a Steem Witness
https://steemyy.com

My contributions

Delegation Service

  1. Voting Algorithm Updated to Favor those High Delegations!
  • Delegate 1000 to justyy: Link
  • Delegate 5000 to justyy: Link
  • Delegate 10000 to justyy: Link

Support me

If you like my work, please:

  1. Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
  2. Vote @justyy as Witness: https://steemyy.com/witness-voting/?witness=justyy&action=approve
  3. Set @justyy as Proxy: https://steemyy.com/witness-voting/?witness=justyy&action=proxy
    Alternatively, you can vote witness or set proxy here: https://steemit.com/~witnesses

Sort:  

It is clear that you have a good investment in equipment to ensure the great work that you do, which allows us to do ours, by publishing, commenting and voting on the publications.
Few people know their work and how important it is in our blockchain
I wish you an excellent weekend

Thank you and wish you have a nice weekend as well.

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.084
BTC 60423.20
ETH 1583.38
USDT 1.00
SBD 0.42