forked from onryo/siona
Extremely Private HUSH and HAC explorer
https://explorer.hush.is
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.6 KiB
74 lines
2.6 KiB
#!/usr/bin/env perl
|
|
use strict;
|
|
use warnings;
|
|
use 5.014;
|
|
my $STATS = {};
|
|
$|=1;
|
|
|
|
# give rpc's a chance to finish before us in cron
|
|
sleep 30;
|
|
|
|
# While Siona swims, we pave with bricks on the road she will run on...
|
|
my $domain = $ENV{DOMAIN};
|
|
my $dir = $ENV{DIR};
|
|
my $getinfo = readfile("$dir/getinfo.json");
|
|
my $mining = readfile("$dir/getmininginfo.json");
|
|
my $txstats = readfile("$dir/getchaintxstats.json");
|
|
# run the slowest last so the RPC interface isn't juggling
|
|
my $coinsupply = readfile("$dir/coinsupply.json");
|
|
my $template = readfile("/var/www/$domain/template.html");
|
|
|
|
|
|
#say $template;
|
|
#warn "<!--" . $STATS->{TLS_CONNECTIONS} . "/" . $STATS->{CONNECTIONS} . " peers connected via TLS -->";
|
|
|
|
my @symbols = qw/
|
|
BLOCKS CONNECTIONS TLS_CONNECTIONS TXCOUNT
|
|
NOTARIZED ZFUNDS SUPPLY DIFFICULTY NETWORKSOLPS
|
|
PROTOCOLVERSION LONGESTCHAIN TIPTIME NOTARIZEDHASH
|
|
NOTARIZEDHEIGHT BLOCKHASH TXRATE
|
|
/;
|
|
|
|
#if ($getinfo && $mining && $txstats && $coinsupply) {
|
|
for my $s (@symbols) {
|
|
if($s && $STATS->{$s}) { $template =~ s/#$s#/$STATS->{$s}/ge }
|
|
}
|
|
# derived stat
|
|
my $zpct = sprintf "%.3f", ($STATS->{SUPPLY} || 0) > 0 ? 100*($STATS->{ZFUNDS}/$STATS->{SUPPLY}) : "0.000";
|
|
$template =~ s/#ZFUNDS_PERCENT#/$zpct/ge;
|
|
|
|
say $template;
|
|
|
|
#}
|
|
|
|
sub readfile {
|
|
my $file = shift;
|
|
my $data = "";
|
|
open(my $fh, '<', $file) or die $!;
|
|
while(<$fh>){
|
|
$data.=$_;
|
|
# getinfo
|
|
if(m/"tls_connections": (\d+)/){ $STATS->{TLS_CONNECTIONS} ||= $1; }
|
|
if(m/"connections": (\d+)/){ $STATS->{CONNECTIONS} ||= $1; }
|
|
if(m/"blocks": (\d+)/){ $STATS->{BLOCKS} ||= $1; }
|
|
if(m/"notarized": (\d+)/){ $STATS->{NOTARIZED} ||= $1; }
|
|
if(m/"protocolversion": (\d+)/){ $STATS->{PROTOCOLVERSION} ||= $1; }
|
|
if(m/"longestchain": (\d+)/){ $STATS->{LONGESTCHAIN} ||= $1; }
|
|
if(m/"notarizedhash": "([a-z0-9]+)"/){ $STATS->{NOTARIZEDHASH} ||= $1; }
|
|
if(m/"tiptime": (\d+)/){ $STATS->{TIPTIME} ||= localtime($1) . "<!-- $1 -->"; }
|
|
# coinsupply
|
|
if(m/"zfunds": (\d+\.\d+)/){ $STATS->{ZFUNDS} ||= sprintf("%8.8f", $1); }
|
|
if(m/"total": (\d+\.\d+)/){ $STATS->{SUPPLY} ||= sprintf("%8.8f", $1); }
|
|
# getmininginfo
|
|
if(m/"difficulty": (\d+)/){ $STATS->{DIFFICULTY} ||= $1; }
|
|
if(m/"networksolps": (\d+)/){ $STATS->{NETWORKSOLPS} ||= sprintf("%.2f", $1 / 1_000_000); }
|
|
# getchaintxstats
|
|
if(m/"txcount": (\d+)/){ $STATS->{TXCOUNT} ||= $1; }
|
|
if(m/"txrate": (\d+\.\d+)/){ $STATS->{TXRATE} ||= sprintf("%.4f",$1*60); }
|
|
if(m/"window_final_block_hash": "([a-z0-9]+)"/){ $STATS->{BLOCKHASH} ||= $1; }
|
|
}
|
|
close($fh);
|
|
return $data;
|
|
}
|
|
# "connections": 48,
|
|
# "tls_connections": 28,
|