Skip to content

Commit

Permalink
fix database connection leak, disable default prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ramilexe committed Dec 6, 2020
1 parent 3a1f54e commit 473178e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"express": "^4.17.1",
"pg": "^8.5.1",
"prom-client": "^12.0.0"
},
"scripts": {
"start": "node ./src/index.js"
}
}
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,6 +78,7 @@ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

const main = async () => {
startServer();
connectToDB();

let lock = false;

Expand Down
2 changes: 0 additions & 2 deletions src/prometheus.js
Original file line number Diff line number Diff line change
@@ -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]});
Expand Down

0 comments on commit 473178e

Please sign in to comment.