fix database connection leak, disable default prometheus metrics

This commit is contained in:
ramil 2020-12-06 20:43:09 +03:00
parent 3a1f54eb8e
commit 473178e810
3 changed files with 13 additions and 4 deletions

View File

@ -12,5 +12,8 @@
"express": "^4.17.1",
"pg": "^8.5.1",
"prom-client": "^12.0.0"
},
"scripts": {
"start": "node ./src/index.js"
}
}

View File

@ -24,14 +24,21 @@ const startServer = () => {
server.listen(serverPort, serverHost, () => console.log(`Http server running on port ${serverHost}:${serverPort}`));
}
const run = async () => {
let dbStateDiff;
const connectToDB = () => {
const statediffUser = process.env.STATEDIFF_PG_USER;
const statediffPassword = process.env.STATEDIFF_PG_PASSWORD;
const statediffDB = process.env.STATEDIFF_PG_DATABASE;
const statediffHost = process.env.STATEDIFF_PG_HOST;
const statediffPort = process.env.STATEDIFF_PG_PORT;
const dbStateDiff = new DB('statediff', statediffUser, statediffPassword, statediffDB, statediffHost, statediffPort)
dbStateDiff = new DB('statediff', statediffUser, statediffPassword, statediffDB, statediffHost, statediffPort)
}
const run = async () => {
// statediff database
const dbStateDiffBlockNumber = dbStateDiff.getBlockNumber();
// Etherscan
@ -71,6 +78,7 @@ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const main = async () => {
startServer();
connectToDB();
let lock = false;

View File

@ -1,10 +1,8 @@
const client = require('prom-client');
const collectDefaultMetrics = client.collectDefaultMetrics;
const Registry = client.Registry;
const register = new Registry();
const prefix = 'eth_state_metrics_';
collectDefaultMetrics({ register });
const etherscanGauge = new client.Gauge({ name: `${prefix}etherscan`, help: 'Etherscan Block Number', registers: [register]});
const statediffDBGauge = new client.Gauge({ name: `${prefix}statediff_db`, help: 'Statediff DB Block Number', registers: [register]});