-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.js
43 lines (38 loc) · 1.34 KB
/
metrics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const client = require('prom-client');
const { exec } = require('child_process');
const axios = require('axios');
const nodeApi = process.env.NODE_API;
const binary = process.env.BINARY;
function validatorMissedBlocks(registry) {
const gauge = new client.Gauge({
name: 'validator_missed_blocks',
help: 'Validator missed blocks counter',
registers: [registry],
});
async function collectValidatorMissedBlocks() {
exec(`${binary} tendermint show-address`, async (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
let valcons = stdout;
try {
const response = await axios.get(nodeApi + "/cosmos/slashing/v1beta1/signing_infos/" + valcons);
const missed = response.data.val_signing_info.missed_blocks_counter;
console.log(`Validator missed blocks: ${missed}`);
gauge.set(parseFloat(missed));
}
catch (err) {
console.log(err.message);
}
});
}
setInterval(collectValidatorMissedBlocks, 6000);
}
module.exports = (registry) => {
validatorMissedBlocks(registry);
};