Skip to content
Snippets Groups Projects
Commit 0c124b2b authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

monitor.sh ahora se llama monitor.js y se mejoro

parent 3935331d
No related branches found
No related tags found
No related merge requests found
......@@ -100,6 +100,13 @@ module.exports = class Libbfa
params: 0
}]
});
w3.eth.extend({
methods: [{
name: 'adminpeers',
call: 'admin_peers',
params: 0
}]
});
if ( undefined != process.env.BFAACCOUNT ) {
w3.eth.defaultAccount = this.account;
}
......
#!/usr/bin/node
// vim:syntax:filetype=javascript:ai:sm
// vim:expandtab:backspace=indent,eol,start:softtabstop=4
"use strict"
const Libbfa = require( process.env.BFAHOME + '/bin/libbfa.js');
function monitor()
{
var bfa = new Libbfa();
var web3 = bfa.newweb3();
var now = new Date();
//console.log(web3.eth);
web3.eth.adminpeers().then(
function(nodelist) {
var peers = [];
nodelist.forEach(
function(node) {
if ( typeof(node.protocols.eth) == 'object' )
{
var dir = "out";
if ( node.network.inbound )
dir = "in";
peers.push( "peer "+dir+": "+node.enode );
}
}
);
console.log(
"UTC: " + now.toUTCString() + "\n"
+ "BFA peers: " + peers.length + "\n"
+ peers.sort().join("\n")
);
},
function(x)
{
console.log( x );
process.exit(1)
}
);
}
monitor();
#!/bin/bash
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
ERRTEXT="Monitoring failed"
function json_query
{
local ERRTEXT="Monitoring RPC failed"
trap '' ERR
json=$( geth_rpc $* )
trap errtrap ERR
}
function json_arraylength
{
jq -r length
}
json_query admin_peers
test -n "${json}" || exit 0
numpeers=$( echo $json | json_arraylength )
statusfile=$( mktemp )
cleanup "${statusfile}"
chmod 644 "${statusfile}"
echo -n "time: " > ${statusfile}
date >> ${statusfile}
echo "total-peer-count: ${numpeers}" >> ${statusfile}
peercount=0
for idx in $( seq 0 $(( $numpeers - 1 )) )
do
eth=$( echo "$json" | jq -r .[$idx].protocols.eth )
if [ "$eth" = "handshake" ]
then
continue
fi
#echo -n "$idx: "; echo "$eth" | jq -c
remoteid=$(
echo "$json" |
jq -r .[$idx].id
)
remoteaddress=$(
echo "$json" |
jq -r .[$idx].network.remoteAddress
)
remoteip=$(
echo "$remoteaddress" |
sed 's/:[0-9][0-9]*$//'
)
# IPv6 has the address surrounded by [ and ] - we strip that away
if [ "${remoteip:0:1}" = "[" -a "${remoteip:$((${#remoteip}-1))}" = "]" ]
then
remoteip="${remoteip:1:$((${#remoteip}-2))}"
fi
remoteport=$(
echo "$remoteaddress" |
sed 's/^.*://'
)
echo "peer: enode://${remoteid}@[${remoteip}]:${remoteport}" >> $statusfile
mkdir -p "${BFANETWORKDIR}/lastseen/${remoteid}"
if [ -r "${BFANETWORKDIR}/lastseen/${remoteid}/${remoteip}" ]
then
storedport=$( cat "${BFANETWORKDIR}/lastseen/${remoteid}/${remoteip}" )
test "${remoteport}" = "${storedport}" &&
unset remoteport
fi
if [ -n "${remoteport}" ]
then
echo "${remoteport}" > "${BFANETWORKDIR}/lastseen/${remoteid}/${remoteip}"
else
touch "${BFANETWORKDIR}/lastseen/${remoteid}/${remoteip}"
fi
peercount=$(( $peercount + 1 ))
done
echo "valid-peer-count: ${peercount}" >> $statusfile
mv -f $statusfile ${BFANETWORKDIR}/status
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment