AWK Tutorial: How often do you generate a Witness Block? 使用AWK来看见证人生成块的速度

in #steemstem7 years ago (edited)

How many hours/minutes or blocks are there since last time you generate a block as a witness? Today we are going to find out the answer using the LINUX AWK programming.

First, we know that if you run docker logs [Your Container ID] you will see lots of log messages, such as:

image.png

The ./run.sh logs prints a tail-ed messages and we can to grep "Generated" to see the list of blocks:

image.png

So the next thing is to get the 8-th column with prints the block number. Using AWK, we know the 8-th column is stored in $8 and we can use the following Linux command to print the number of blocks since last commit and the hours passed (steemit generates a block every 3 seconds);

NR is the row number in AWK, and substr($8, 2) removes the hash tag.

{
  cur=substr($8,2);
  if (NR>1){
    print "blocks=",cur-prev," hours=", (cur-prev)*3/3600
  }
  prev=cur;
}

The complete command is:

docker logs [Replace with your Container ID] | grep "Generated" | awk '{cur=substr($8,2);if (NR>1){print "blocks=",cur-prev," hours=",(cur-prev)*3/3600}prev=cur;}'

image.png

Yeah, I am getting faster and faster... Please help me to achieve my aim of producing a block every hour by voting me as a witness. Thanks!

SteemIt Witness Post: Just another Witness


每次见证人出块,媳妇总我说 “又生了”。 每次出块我总会去算一下离上次出块多少时间,这是可以通过当前块数和上次出块数算出来的。

首先,我们可以通过 docker logs [容器 ID] 来显示很多很多的记录:

image.png

有一个脚本 ./run.sh logs是显示最近几条记录 (tail) 我们可以通过管道 grep "Generated" 列出出块时候的记录。

image.png

然后我们就可以通过AWK来处理文本了,比如 $8 返回第8列,我们就可以算出每次出块的间隔,然后已知每3秒STEEM产生一个块,这样我们就知道时间了。

NR 表示行号, substr($8, 2) 去掉第8列中的 # 字符,也就是得到块号。

{
  cur=substr($8,2);
  if (NR>1){ 
    print "blocks=",cur-prev," hours=", (cur-prev)*3/3600
  }
  prev=cur;
}

完整的命令如下:

docker logs [容器ID] | grep "Generated" | awk '{cur=substr($8,2);if (NR>1){print "blocks=",cur-prev," hours=",(cur-prev)*3/3600}prev=cur;}'

image.png

我的目标是一个小时生成一块,请帮助我达成这个目标吧, 投我为见证人,感谢!.

SteemIt 见证人贴: 投行长为见证人,带领CN社区一起脱贫致富!

Sort:  

厉害了!这awk用的风骚!

哈哈 骚操作

雖然, 知道見證人是甚麼?
有人以礦工來形容,但我卻未能理解。

不過,投了您票。

想問一問,見證人的排名高低,有甚麼意思?

Screenshot_20180309-232548.png

感谢。
STEEM见证人的主要职责就是打包。

支持您,已投票

感谢!

亲~@cntts为您准备了这篇博文的语音版:

如果您喜欢我的工作,请不吝为我点赞😊

有意思。

Coin Marketplace

STEEM 0.18
TRX 0.24
JST 0.036
BTC 94781.20
ETH 3263.66
USDT 1.00
SBD 3.08