-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
38 lines (32 loc) · 1.24 KB
/
index.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
const eventSource = require('eventsource');
const fs = require('fs');
const errorChecker = require("./errorChecker.js")
const notifier = require("./notifier.js")
const FIVE_MIN_IN_MS = 5 * 60000
const CONFIG = process.env.CONFIG || 'validators.json'
function getValidatorStats() {
let validators = JSON.parse(fs.readFileSync(CONFIG))
for(const validator of validators){
let uri = `http://${validator.ipAddress}:3030/vitals`
try {
const sse = new eventSource(uri)
sse.onmessage = async (msg) => {
sse.close()
let response = JSON.parse(msg.data)
let errors = await errorChecker.checkForErrors(validator, response)
validator.address = response.account_view.address
notifier.sendNotification(validator, errors)
}
sse.onerror = (err) => {
sse.close()
notifier.sendNotification(validator, ['OFFLINE'])
}
} catch (err) {
console.log('error')
notifier.sendNotification(validator, ['OFFLINE'])
}
}
}
console.log('Starting 0l validator health ...')
//getValidatorStats()
setInterval(getValidatorStats, FIVE_MIN_IN_MS)