From 562704641a500b3deee438f2e7566b895e54873d Mon Sep 17 00:00:00 2001 From: ramil Date: Fri, 4 Dec 2020 22:48:57 +0300 Subject: [PATCH] SIGINT handler, documentation --- Dockerfile | 10 ++-------- README.md | 31 +++++++++++++++++++++++++++++++ src/index.js | 9 ++++++++- 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 README.md diff --git a/Dockerfile b/Dockerfile index a54cd9d..6dc5a2a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,14 @@ -FROM node:10.15.2-alpine +FROM node:15.3.0-alpine3.10 # Create app directory WORKDIR /app -RUN apk add --no-cache \ - make g++ git ca-certificates - -#RUN npm config set unsafe-perm true && npm install -g typescript ts-node - COPY package*.json ./ RUN yarn COPY . . -#RUN npm run build - EXPOSE 3000 +CMD ["node", "./src/index.js"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..eb6513a --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# Prometheus Metrics for Geth-Statediff + +Server exposes `/metrics` endpoint with Prometheus metrics: +* `eth_state_metrics_etherscan` - latest block from Etherscan +* `eth_state_metrics_statediff_db` - latest block from Statediff Database + +## How to run + +### Locally + + +``` +# copy config template +cp .env.example .env + +# edit it and set Etherscan API Key and Database Credentials + +# run server +node src/index.js +``` +And then open in browser `http://172.17.0.2:3000/metrics` + +### Docker + +``` +docker run \ + -e SERVER_HOST=0.0.0.0 \ + -e ETHERSCAN_API_KEY=*** \ + -e STATEDIFF_PG_HOST=*** \ + -d vulcanize/eth-state-metrics +``` \ No newline at end of file diff --git a/src/index.js b/src/index.js index ba5e728..6bf829a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ require('dotenv').config() +var process = require('process') const express = require('express') const etherscan = require('./etherscan'); const AppError = require('./error'); @@ -17,7 +18,9 @@ const startServer = () => { } }); - server.listen(process.env.SERVER_PORT); + const serverPort = process.env.SERVER_PORT || 3000; + const serverHost = process.env.SERVER_HOST || '127.0.0.1'; + server.listen(serverPort, serverHost, () => console.log(`Http server running on port ${serverHost}:${serverPort}`)); } const main = async () => { @@ -70,3 +73,7 @@ const main = async () => { main().catch((e) => console.error(e)); +process.on('SIGINT', () => { + console.info("Interrupted") + process.exit(0) +}) \ No newline at end of file