SIGINT handler, documentation

This commit is contained in:
ramil 2020-12-04 22:48:57 +03:00
parent ac71dc3a64
commit 562704641a
3 changed files with 41 additions and 9 deletions

View File

@ -1,20 +1,14 @@
FROM node:10.15.2-alpine FROM node:15.3.0-alpine3.10
# Create app directory # Create app directory
WORKDIR /app 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 ./ COPY package*.json ./
RUN yarn RUN yarn
COPY . . COPY . .
#RUN npm run build
EXPOSE 3000 EXPOSE 3000
CMD ["node", "./src/index.js"]

31
README.md Normal file
View File

@ -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
```

View File

@ -1,4 +1,5 @@
require('dotenv').config() require('dotenv').config()
var process = require('process')
const express = require('express') const express = require('express')
const etherscan = require('./etherscan'); const etherscan = require('./etherscan');
const AppError = require('./error'); 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 () => { const main = async () => {
@ -70,3 +73,7 @@ const main = async () => {
main().catch((e) => console.error(e)); main().catch((e) => console.error(e));
process.on('SIGINT', () => {
console.info("Interrupted")
process.exit(0)
})