diff --git a/Dockerfile b/Dockerfile old mode 100644 new mode 100755 index b2690e4..36c32d8 --- a/Dockerfile +++ b/Dockerfile @@ -1,61 +1,18 @@ -## 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 node:11-alpine +RUN apk update && apk add git ca-certificates +RUN adduser -S ethnetintel -FROM debian +WORKDIR /home/ethnetintel/ethstats-client -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 +ADD package.json . +RUN npm install && npm install -g pm2 -RUN apt-get update &&\ - apt-get install -y build-essential +ADD . . -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 +RUN chown -R ethnetintel. . +ENV NODE_ENVIRONMENT=production USER ethnetintel -ENTRYPOINT ["/home/ethnetintel/startscript.sh"] + +ENTRYPOINT ["pm2-runtime", "app.json"] \ No newline at end of file diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 912e0df..fa61844 --- a/README.md +++ b/README.md @@ -4,12 +4,40 @@ Ethereum Network Intelligence 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/cubedro/eth-netstats) to feed information. For full install instructions please read the [wiki](https://github.com/ethereum/wiki/wiki/Network-Status). - ## Prerequisite * eth, geth or pyethapp * node * npm +## Docker + +### Configuration (Environment Variables) + +To run the docker container against your client, you can pass in env variables + +``` +docker run \ + --net host \ + -e RPC_HOST=localhost \ + -e RPC_PORT=8545 \ + -e LISTENING_PORT=30303 \ + -e INSTANCE_NAME=MyLocalMachine \ + -e WS_SERVER=wss://rpc.ethstats.net + -e WS_SECRET= + -it goerli/ethstats-client +``` + +Alternatively, you can pass in an `--env-file` to Docker with all the above set. + +### Configuration (app.json) + +You can also overwrite the `app.json` file to pass in configuration, for example: + +``` +docker run \ + -v :/home/ethnetintel/ethstats-client/app.json \ + -it goerli/ethstats-client +``` ## Installation on an Ubuntu EC2 Instance @@ -18,31 +46,8 @@ Fetch and run the build shell. This will install everything you need: latest eth ```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) - } -``` -## Run +## Run Local Run it using pm2: @@ -61,6 +66,11 @@ To update the API client use the following command: 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. +## Notes + + - For the WS_SECRET, see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic + - Ensure that your container has connectivity to your Ethereum client. + [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 diff --git a/app.json b/app.json old mode 100644 new mode 100755 index 65f4f53..21d58cb --- a/app.json +++ b/app.json @@ -7,18 +7,6 @@ "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 - } + "exec_mode" : "fork_mode" } ] diff --git a/lib/node.js b/lib/node.js old mode 100644 new mode 100755 index 82ab4bd..e08a082 --- a/lib/node.js +++ b/lib/node.js @@ -491,9 +491,7 @@ Node.prototype.getStats = function(forced) }, hashrate: function (callback) { - if (web3.eth.mining) { - web3.eth.getHashrate(callback); - } + web3.eth.getHashrate(callback); }, gasPrice: function (callback) { @@ -519,16 +517,17 @@ Node.prototype.getStats = function(forced) results.end = _.now(); results.diff = results.end - self._lastFetch; - console.sstats('==>', 'Got getStats results in', chalk.reset.cyan(results.diff, 'ms')); + console.stats('==>', 'Got getStats results in', chalk.reset.cyan(results.diff, 'ms')); if(results.peers !== null) { self.stats.active = true; + self.stats.peers = results.peers; self.stats.mining = results.mining; self.stats.hashrate = results.hashrate; self.stats.gasPrice = results.gasPrice.toString(10); - + console.stats('==>', 'Peer count', self.stats.peers); if(results.syncing !== false) { var sync = results.syncing; diff --git a/package.json b/package.json old mode 100644 new mode 100755