If you visit ethstats you see two cards named AVG NETWORK HASHRATE and AVG BLOCK TIME, How can i get them in geth?
[Ethereum] calculate average network hashrate and block time in geth
go-ethereumhashrate
Related Solutions
Make sure your use the latest ethminer and pass a high verbosity flag. I'm using -v 9
. This allows you to follow the hashrate.
ethminer -v 9 -G -F http://ethpool.org/miner/0x00000000000000...
I'm using the version from the Ubuntu repositories:
~ $ ethminer --version
ethminer version 1.1.4
Build: Linux/g++/int/Release
Here is the result with hashrate:
miner 03:51:04.874|ethminer Got work package:
miner 03:51:04.874|ethminer Header-hash: a81696b15e04153806d383e37ab7a21ecaa15455c6d5baa4f6d0f0ae057172ee
miner 03:51:04.874|ethminer Seedhash: 1250db2965df18ca201a546442dab4fdea6f6ed1a13e86ed691dc897dcb9799c
miner 03:51:04.874|ethminer Target: 00000000dbe6fecebdedd5beb573440e5a884d1b2fbf06fcce912adcb8d8422e
ℹ 03:51:04.904|gpuminer0 workLoop 1 #1250db29… #1250db29…
ℹ 03:51:04.933|gpuminer1 workLoop 1 #1250db29… #1250db29…
miner 03:51:05.434|ethminer Mining on PoWhash #a81696b1… : 50855936 H/s = 25427968 hashes / 0.5 s
miner 03:51:06.406|ethminer Mining on PoWhash #a81696b1… : 52051226 H/s = 50593792 hashes / 0.972 s
Here is a Perl script that will calculate your average hashrate and display the important lines in your ethminer
log files:
ℹ 21:19:58.840|ethminer B-) Submitted and accepted.
✘ 20:23:53.048|ethminer FAILURE: GPU gave incorrect result!`
This script works on Linux and Mac OS X as the Perl interpreter is available on these platforms by default. For Windows, you may have to try Perl from perl.org.
Note that this hashrate is calculated when ethminer
is calculating it's hashes, and does not include the time that ethminer
is getting a new work package from geth
(or the pool) or when it is submitting the results to geth
/pool.
Copy the following lines into $HOME/bin/calcHashrate
, and set the executable bit for this file by running the command chmod 700 $HOME/bin/calcHashrate
.
calcHashrate
#!/usr/bin/perl -W
use Getopt::Long;
my $DEFAULTHASHLINES = 1000;
my $DEFAULTACCEPTLINES = 4;
my $DEFAULTFAILURELINES = 4;
my ($hashlines, $acceptlines, $failurelines, $removecolour, $help);
GetOptions(
"hashlines:i" => \$hashlines,
"acceptlines:i" => \$acceptlines,
"failurelines:i" => \$failurelines,
"removecolour" => \$removecolour,
"help" => \$help
);
die "Usage: $0 [options]\n\n" .
" where the options are:\n" .
" --hashlines=x Calculate average hashrate over the last x lines, default $DEFAULTHASHLINES\n" .
" --acceptlines=y Display the last y 'accept' lines, default $DEFAULTACCEPTLINES\n" .
" --failurelines=z Display the last z 'FAILURE' lines, default $DEFAULTFAILURELINES\n" .
" --removecolour Don't display colour in the accept and failure lines\n" .
" --help Display this help\n\n" .
"Enjoy. BokkyPooBah 2016.\n\n" .
"Stopped"
if defined $help;
$hashlines = $DEFAULTHASHLINES
unless defined $hashlines;
$acceptlines = $DEFAULTACCEPTLINES
unless defined $acceptlines;
$failurelines = $DEFAULTFAILURELINES
unless defined $failurelines;
my (@hashlinearray, @acceptlinearray, @failurelinearray) = ((), (), ());
while (<>) {
if (/(\d\d:\d\d:\d\d.\d\d\d).*:\s(\d+).*=\s(\d+).*\/\s(\d+\.\d+)/) {
push @hashlinearray, $_;
shift @hashlinearray
if ($#hashlinearray >= $hashlines);
} elsif (/accept/) {
push @acceptlinearray, $_;
shift @acceptlinearray
if ($#acceptlinearray >= $acceptlines);
} elsif (/FAILURE/) {
push @failurelinearray, $_;
shift @failurelinearray
if ($#failurelinearray >= $failurelines);
}
}
my ($totalhashes, $totalperiod) = (0, 0);
my ($lasttime) = ();
foreach (@hashlinearray) {
if (/(\d\d:\d\d:\d\d.\d\d\d).*:\s(\d+).*=\s(\d+).*\/\s(\d+\.\d+)/) {
my ($time, $rate, $hashes, $period) = $_ =~ /(\d\d:\d\d:\d\d.\d\d\d).*:\s(\d+).*=\s(\d+).*\/\s(\d+\.\d+)/;
$totalhashes += $hashes;
$totalperiod += $period;
$lasttime = $time;
}
}
foreach (@acceptlinearray) {
s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g
if defined $removecolour;
print;
}
foreach (@failurelinearray) {
s/\x1b\[[0-9;]*m//g
if defined $removecolour;
print;
}
if ($totalperiod > 0) {
my $averagehashrate = $totalhashes / $totalperiod / 1000 / 1000;
printf "%s %.3f MH/s\n", $lasttime, $averagehashrate;
} else {
print "No statistics\n";
}
Sample Usage
user@Kumquat:~$ calcHashrate --help
Usage: calcHashrate [options]
where the options are:
--hashlines=x Calculate average hashrate over the last x lines, default 1000
--acceptlines=y Display the last y 'accept' lines, default 4
--failurelines=z Display the last z 'FAILURE' lines, default 4
--removecolour Don't display colour in the accept and failure lines
--help Display this help
Enjoy. BokkyPooBah 2016.
Stopped at ./calcHashrate line 18.
Run the script with the default settings, calculating the average hashrate over the last 1,000 lines, show up to 4 accept
lines and show up to 4 FAILURE
lines. The line at the bottom shows the last hashrate time and the average hashrate in megahashes per second.
user@Kumquat:~$ calcHashrate logs/ethminer.log --removecolour
ℹ 21:24:12.221|ethminer B-) Submitted and accepted.
ℹ 21:24:14.671|ethminer B-) Submitted and accepted.
ℹ 21:24:17.519|ethminer B-) Submitted and accepted.
ℹ 21:24:30.835|ethminer B-) Submitted and accepted.
✘ 18:11:00.367|ethminer FAILURE: GPU gave incorrect result!
✘ 18:41:12.725|ethminer FAILURE: GPU gave incorrect result!
✘ 20:03:32.135|ethminer FAILURE: GPU gave incorrect result!
✘ 20:23:53.048|ethminer FAILURE: GPU gave incorrect result!
21:25:04.239 62.619 MH/s
Run the script to just display the hashrate over the last 1,000 hashrate lines.
user@Kumquat:~$ calcHashrate ethminer.log --acceptlines=0 --failurelines=0
21:25:04.239 62.619 MH/s
Best Answer
Geth doesn't deliver the blockTime directly.
I've written a simple PHP script that calculates the average blockTime and difficulty: https://github.com/3lue/Average-Blocktime-Difficulty-Calculator
Maybe someone else knows how to get the average hashrate.
EDIT: I've found following post: https://ethereum.stackexchange.com/a/11382
So you should be able to calculate the average network hashrate with this formula (output in GH/s):