From ccaec84906dcae0cf4930bd63fd3ea8267354a34 Mon Sep 17 00:00:00 2001 From: hackyminer Date: Mon, 23 Apr 2018 07:44:53 +0900 Subject: [PATCH 1/5] Pool stats using the open-ethereum-pool api/stats --- app.json | 3 +++ lib/node.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/app.json b/app.json index 65f4f535..d73f4080 100644 --- a/app.json +++ b/app.json @@ -13,6 +13,9 @@ "NODE_ENV" : "production", "RPC_HOST" : "localhost", "RPC_PORT" : "8545", + "API_HOST" : "localhost", + "API_PORT" : "8080", + "API_URL" : "/api/stats", "LISTENING_PORT" : "30303", "INSTANCE_NAME" : "", "CONTACT_DETAILS" : "", diff --git a/lib/node.js b/lib/node.js index 59103aa2..3fb849df 100644 --- a/lib/node.js +++ b/lib/node.js @@ -2,6 +2,7 @@ require('./utils/logger.js'); +var http = require('http'); var os = require('os'); var Web3 = require('web3'); var web3; @@ -10,6 +11,7 @@ var _ = require('lodash'); var debounce = require('debounce'); var pjson = require('./../package.json'); var chalk = require('chalk'); +var poolOptions = null; var Primus = require('primus'), Emitter = require('primus-emit'), @@ -91,6 +93,10 @@ function Node () transactions: [], uncles: [] }, + pool: { + hashrate: 0, + minersTotal: 0 + }, syncing: false, uptime: 0 }; @@ -126,6 +132,7 @@ function Node () this._timeOffset = null; this.startWeb3Connection(); + this.setupPoolOptions(); return this; } @@ -140,6 +147,18 @@ Node.prototype.startWeb3Connection = function() this.checkWeb3Connection(); } +Node.prototype.setupPoolOptions = function() +{ + if (!process.env.NODE_TYPE || process.env.NODE_TYPE != 'pool') + return; + + poolOptions = { + hostname: (process.env.API_HOST || 'localhost'), + port: (process.env.API_PORT || 8080), + path: (process.env.API_URL || '/api/stats') + }; +} + Node.prototype.checkWeb3Connection = function() { var self = this; @@ -498,6 +517,23 @@ Node.prototype.getStats = function(forced) syncing: function (callback) { web3.eth.getSyncing(callback); + }, + pool: function (callback) + { + if (poolOptions == null) { + callback(null, {hashrate: 0, minersTotal: 0}); + return; + } + http.get(poolOptions, function(res) { + if (res.statusCode != 200) { + console.error('Status:', res.statusCode); + } + + res.on('data', function(data) { + var result = JSON.parse(data); + callback(null, result); + }); + }); } }, function (err, results) @@ -525,6 +561,11 @@ Node.prototype.getStats = function(forced) self.stats.hashrate = results.hashrate; self.stats.gasPrice = results.gasPrice.toString(10); + // setup pool stats + self.stats.pool = results.pool; + // sum hashares + self.stats.hashrate += results.pool.hashrate; + if(results.syncing !== false) { var sync = results.syncing; @@ -662,6 +703,7 @@ Node.prototype.prepareStats = function () hashrate: this.stats.hashrate, peers: this.stats.peers, gasPrice: this.stats.gasPrice, + pool: this.stats.pool, uptime: this.stats.uptime } }; From 396f749952c52b58824c42e6637986c7741ae030 Mon Sep 17 00:00:00 2001 From: turbobit Date: Wed, 30 May 2018 09:04:12 +0000 Subject: [PATCH 2/5] fork from https://github.com/OpenCommunityCoin/eth-netstats-client-api edit for simple run --- .env | 13 ++++++++ Dockerfile | 61 ---------------------------------- README.md | 70 +++++++++++++++----------------------- app.js | 2 +- app.json | 27 --------------- app.json.example | 24 -------------- bin/update.sh | 83 ---------------------------------------------- package.json | 1 + processes-ec2.json | 43 ------------------------ 9 files changed, 42 insertions(+), 282 deletions(-) create mode 100644 .env delete mode 100644 Dockerfile delete mode 100644 app.json delete mode 100644 app.json.example delete mode 100755 bin/update.sh delete mode 100644 processes-ec2.json diff --git a/.env b/.env new file mode 100644 index 00000000..58a407dc --- /dev/null +++ b/.env @@ -0,0 +1,13 @@ +DE_ENV=production +RPC_HOST=localhost +RPC_PORT=8545 +API_HOST=localhost +API_PORT=8080 +API_URL=/api/stats +LISTENING_PORT=50505 +INSTANCE_NAME= +CONTACT_DETAILS= +WS_SERVER=wss://escstats.gonsmine.com +WS_SECRET=EtherSocial +VERBOSITY=2 + diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index b2690e4d..00000000 --- a/Dockerfile +++ /dev/null @@ -1,61 +0,0 @@ -## Dockerfile for eth-net-intelligence-api (build from git). -## -## Build via: -# -# `docker build -t ethnetintel:latest .` -# -## Run via: -# -# `docker run -v :/home/ethnetintel/eth-net-intelligence-api/app.json ethnetintel:latest` -# -## Make sure, to mount your configured 'app.json' into the container at -## '/home/ethnetintel/eth-net-intelligence-api/app.json', e.g. -## '-v /path/to/app.json:/home/ethnetintel/eth-net-intelligence-api/app.json' -## -## Note: if you actually want to monitor a client, you'll need to make sure it can be reached from this container. -## The best way in my opinion is to start this container with all client '-p' port settings and then -# share its network with the client. This way you can redeploy the client at will and just leave 'ethnetintel' running. E.g. with -## the python client 'pyethapp': -## -# -# `docker run -d --name ethnetintel \ -# -v /home/user/app.json:/home/ethnetintel/eth-net-intelligence-api/app.json \ -# -p 0.0.0.0:30303:30303 \ -# -p 0.0.0.0:30303:30303/udp \ -# ethnetintel:latest` -# -# `docker run -d --name pyethapp \ -# --net=container:ethnetintel \ -# -v /path/to/data:/data \ -# pyethapp:latest` -# -## If you now want to deploy a new client version, just redo the second step. - - -FROM debian - -RUN apt-get update &&\ - apt-get install -y curl git-core &&\ - curl -sL https://deb.nodesource.com/setup | bash - &&\ - apt-get update &&\ - apt-get install -y nodejs - -RUN apt-get update &&\ - apt-get install -y build-essential - -RUN adduser ethnetintel - -RUN cd /home/ethnetintel &&\ - git clone https://github.com/cubedro/eth-net-intelligence-api &&\ - cd eth-net-intelligence-api &&\ - npm install &&\ - npm install -g pm2 - -RUN echo '#!/bin/bash\nset -e\n\ncd /home/ethnetintel/eth-net-intelligence-api\n/usr/bin/pm2 start ./app.json\ntail -f \ - /home/ethnetintel/.pm2/logs/node-app-out-0.log' > /home/ethnetintel/startscript.sh - -RUN chmod +x /home/ethnetintel/startscript.sh &&\ - chown -R ethnetintel. /home/ethnetintel - -USER ethnetintel -ENTRYPOINT ["/home/ethnetintel/startscript.sh"] diff --git a/README.md b/README.md index 912e0df6..0c0802e8 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,51 @@ -Ethereum Network Intelligence API +ESN Network Intelligence API ============ [![Build Status][travis-image]][travis-url] [![dependency status][dep-image]][dep-url] -This is the backend service which runs along with ethereum and tracks the network status, fetches information through JSON-RPC and connects through WebSockets to [eth-netstats](https://github.com/cubedro/eth-netstats) to feed information. For full install instructions please read the [wiki](https://github.com/ethereum/wiki/wiki/Network-Status). +## forked from https://github.com/OpenCommunityCoin/eth-netstats-client-api + +This is the backend service which runs along with ethereum and tracks the network status, fetches information through JSON-RPC and connects through WebSockets to [eth-netstats](https://github.com/turbobit/eth-netstats) to feed information. For full install instructions please read the [wiki](https://github.com/ethereum/wiki/wiki/Network-Status). + +Live Work : https://escstats.gonsmine.com ## Prerequisite -* eth, geth or pyethapp -* node +* ESN node ( https://github.com/ethersocial/go-esn ) * npm -## Installation on an Ubuntu EC2 Instance +## Configuration -Fetch and run the build shell. This will install everything you need: latest ethereum - CLI from develop branch (you can choose between eth or geth), node.js, npm & pm2. +edit .env file -```bash -bash <(curl https://raw.githubusercontent.com/cubedro/eth-net-intelligence-api/master/bin/build.sh) ``` -## Installation as docker container (optional) - -There is a `Dockerfile` in the root directory of the repository. Please read through the header of said file for -instructions on how to build/run/setup. Configuration instructions below still apply. - -## Configuration - -Configure the app modifying [processes.json](/eth-net-intelligence-api/blob/master/processes.json). Note that you have to modify the backup processes.json file located in `./bin/processes.json` (to allow you to set your env vars without being rewritten when updating). - -```json -"env": - { - "NODE_ENV" : "production", // tell the client we're in production environment - "RPC_HOST" : "localhost", // eth JSON-RPC host - "RPC_PORT" : "8545", // eth JSON-RPC port - "LISTENING_PORT" : "30303", // eth listening port (only used for display) - "INSTANCE_NAME" : "", // whatever you wish to name your node - "CONTACT_DETAILS" : "", // add your contact details here if you wish (email/skype) - "WS_SERVER" : "wss://rpc.ethstats.net", // path to eth-netstats WebSockets api server - "WS_SECRET" : "see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic", // WebSockets api server secret used for login - "VERBOSITY" : 2 // Set the verbosity (0 = silent, 1 = error, warn, 2 = error, warn, info, success, 3 = all logs) - } +DE_ENV=production +RPC_HOST=localhost +RPC_PORT=8545 +API_HOST=localhost +API_PORT=8080 +API_URL=/api/stats +LISTENING_PORT=50505 +INSTANCE_NAME= +CONTACT_DETAILS= +WS_SERVER=wss://escstats.gonsmine.com +WS_SECRET=EtherSocial +VERBOSITY=2 ``` ## Run -Run it using pm2: +Run it using node: ```bash -cd ~/bin -pm2 start processes.json +node app.js ``` -## Updating - -To update the API client use the following command: -```bash -~/bin/www/bin/update.sh -``` It will stop the current netstats client processes, automatically detect your ethereum implementation and version, update it to the latest develop build, update netstats client and reload the processes. -[travis-image]: https://travis-ci.org/cubedro/eth-net-intelligence-api.svg -[travis-url]: https://travis-ci.org/cubedro/eth-net-intelligence-api -[dep-image]: https://david-dm.org/cubedro/eth-net-intelligence-api.svg -[dep-url]: https://david-dm.org/cubedro/eth-net-intelligence-api +[travis-image]: https://travis-ci.org/turbobit/eth-net-intelligence-api.svg +[travis-url]: https://travis-ci.org/turbobit/eth-net-intelligence-api +[dep-image]: https://david-dm.org/turbobit/eth-net-intelligence-api.svg +[dep-url]: https://david-dm.org/turbobit/eth-net-intelligence-api diff --git a/app.js b/app.js index 6574d8da..c856670f 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,5 @@ 'use strict'; - +require('dotenv').load(); var nodeModel = require('./lib/node'); var node = new nodeModel(); diff --git a/app.json b/app.json deleted file mode 100644 index d73f4080..00000000 --- a/app.json +++ /dev/null @@ -1,27 +0,0 @@ -[ - { - "name" : "node-app", - "script" : "app.js", - "log_date_format" : "YYYY-MM-DD HH:mm Z", - "merge_logs" : false, - "watch" : false, - "max_restarts" : 10, - "exec_interpreter" : "node", - "exec_mode" : "fork_mode", - "env": - { - "NODE_ENV" : "production", - "RPC_HOST" : "localhost", - "RPC_PORT" : "8545", - "API_HOST" : "localhost", - "API_PORT" : "8080", - "API_URL" : "/api/stats", - "LISTENING_PORT" : "30303", - "INSTANCE_NAME" : "", - "CONTACT_DETAILS" : "", - "WS_SERVER" : "wss://rpc.ethstats.net", - "WS_SECRET" : "see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic", - "VERBOSITY" : 2 - } - } -] diff --git a/app.json.example b/app.json.example deleted file mode 100644 index 65f4f535..00000000 --- a/app.json.example +++ /dev/null @@ -1,24 +0,0 @@ -[ - { - "name" : "node-app", - "script" : "app.js", - "log_date_format" : "YYYY-MM-DD HH:mm Z", - "merge_logs" : false, - "watch" : false, - "max_restarts" : 10, - "exec_interpreter" : "node", - "exec_mode" : "fork_mode", - "env": - { - "NODE_ENV" : "production", - "RPC_HOST" : "localhost", - "RPC_PORT" : "8545", - "LISTENING_PORT" : "30303", - "INSTANCE_NAME" : "", - "CONTACT_DETAILS" : "", - "WS_SERVER" : "wss://rpc.ethstats.net", - "WS_SECRET" : "see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic", - "VERBOSITY" : 2 - } - } -] diff --git a/bin/update.sh b/bin/update.sh deleted file mode 100755 index 4b9a3dcf..00000000 --- a/bin/update.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/bash - -# setup colors -red=`tput setaf 1` -green=`tput setaf 2` -cyan=`tput setaf 6` -bold=`tput bold` -reset=`tput sgr0` - -heading() -{ - echo - echo "${cyan}==>${reset}${bold} $1${reset}" -} - -success() -{ - echo - echo "${green}==>${bold} $1${reset}" -} - -error() -{ - echo - echo "${red}==>${bold} Error: $1${reset}" -} - -heading "Updating ethereum" - -# figure out what we have to update -if [[ -f /usr/bin/geth ]]; -then - ethtype="geth" - success "Found geth" -else - if [[ -f /usr/bin/eth ]]; - then - ethtype="eth" - success "Found eth" - else - error "Couldn't find ethereum" - exit 0 - fi -fi - -heading "Stopping processes" -pm2 stop all - -heading "Flushing logs" -pm2 flush -rm -Rf ~/logs/* -rm -rf ~/.local/share/Trash/* - -heading "Stopping pm2" -pm2 kill - -heading "Killing remaining node processes" -echo `ps auxww | grep node | awk '{print $2}'` -kill -9 `ps auxww | grep node | awk '{print $2}'` - -heading "Removing ethereum" -sudo apt-get remove -y $ethtype - -heading "Updating repos" -sudo apt-get clean -sudo add-apt-repository -y ppa:ethereum/ethereum -sudo add-apt-repository -y ppa:ethereum/ethereum-dev -sudo apt-get update -y -sudo apt-get upgrade -y - -heading "Installing ethereum" -sudo apt-get install -y $ethtype - -heading "Updating eth-netstats client" -cd ~/bin/www -git pull -sudo npm update -cd .. - -success "Ethereum was updated successfully" - -heading "Restarting processes" -pm2 start processes.json diff --git a/package.json b/package.json index 39885bfd..21a0955a 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "chalk": "^1.0.0", "debounce": "1.0.0", "debug": "2.2.0", + "dotenv": "^5.0.1", "lodash": "4.1.0", "primus": "4.0.5", "primus-emit": "1.0.0", diff --git a/processes-ec2.json b/processes-ec2.json deleted file mode 100644 index c4caa87a..00000000 --- a/processes-ec2.json +++ /dev/null @@ -1,43 +0,0 @@ -[ - { - "name" : "eth", - "cwd" : "/home/ubuntu/bin/www/", - "script" : "bin/eth.sh", - "args" : "ethpassword", - "log_date_format" : "YYYY-MM-DD HH:mm Z", - "log_file" : "/home/ubuntu/logs/eth-log.log", - "out_file" : "/home/ubuntu/logs/eth-out.log", - "error_file" : "/home/ubuntu/logs/eth-err.log", - "merge_logs" : false, - "watch" : false, - "max_restarts" : 10, - "exec_interpreter" : "bash", - "exec_mode" : "fork_mode" - }, - { - "name" : "node-app", - "cwd" : "/home/ubuntu/bin/www/", - "script" : "app.js", - "log_date_format" : "YYYY-MM-DD HH:mm Z", - "log_file" : "/home/ubuntu/logs/node-app-log.log", - "out_file" : "/home/ubuntu/logs/node-app-out.log", - "error_file" : "/home/ubuntu/logs/node-app-err.log", - "merge_logs" : false, - "watch" : false, - "max_restarts" : 10, - "exec_interpreter" : "node", - "exec_mode" : "fork_mode", - "env": - { - "NODE_ENV" : "production", - "RPC_HOST" : "localhost", - "RPC_PORT" : "8545", - "LISTENING_PORT" : "30303", - "INSTANCE_NAME" : "", - "CONTACT_DETAILS" : "", - "WS_SERVER" : "wss://rpc.ethstats.net", - "WS_SECRET" : "see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic", - "VERBOSITY" : 2 - } - } -] From c5d18692e6815cb07b24409101fe9a6aacb15627 Mon Sep 17 00:00:00 2001 From: turbobit Date: Wed, 30 May 2018 10:58:08 +0000 Subject: [PATCH 3/5] rpc port 9545 --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index 58a407dc..014df7d4 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ DE_ENV=production RPC_HOST=localhost -RPC_PORT=8545 +RPC_PORT=9545 API_HOST=localhost API_PORT=8080 API_URL=/api/stats From 567f005fc0f8ca6825b89bcf4f10afeeba3581c5 Mon Sep 17 00:00:00 2001 From: turbobit Date: Wed, 30 May 2018 11:01:57 +0000 Subject: [PATCH 4/5] readme edit rpc port 9545 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c0802e8..18159692 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ edit .env file ``` DE_ENV=production RPC_HOST=localhost -RPC_PORT=8545 +RPC_PORT=9545 API_HOST=localhost API_PORT=8080 API_URL=/api/stats From d211d15baea0333849f34f75b6bf910fb2b177a8 Mon Sep 17 00:00:00 2001 From: turbobit Date: Wed, 30 May 2018 11:13:53 +0000 Subject: [PATCH 5/5] delete non use text msg --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 18159692..e39d88bf 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,6 @@ Run it using node: node app.js ``` - - -It will stop the current netstats client processes, automatically detect your ethereum implementation and version, update it to the latest develop build, update netstats client and reload the processes. - [travis-image]: https://travis-ci.org/turbobit/eth-net-intelligence-api.svg [travis-url]: https://travis-ci.org/turbobit/eth-net-intelligence-api [dep-image]: https://david-dm.org/turbobit/eth-net-intelligence-api.svg