-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator-exporter.py
executable file
·51 lines (40 loc) · 1.21 KB
/
validator-exporter.py
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
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import sys
import os
import time
import traceback
import socket
from prometheus_client import (
start_http_server,
Gauge,
REGISTRY,
GC_COLLECTOR,
PLATFORM_COLLECTOR,
PROCESS_COLLECTOR,
)
sys.path.append(os.path.join(sys.path[0], '../mytonctrl'))
from mypylib.mypylib import MyPyClass
from mytoncore.mytoncore import MyTonCore
mytoncore_local = MyPyClass('../mytonctrl/mytoncore/mytoncore.py')
ton = MyTonCore(mytoncore_local)
# Setup metrics
REGISTRY.unregister(GC_COLLECTOR)
REGISTRY.unregister(PLATFORM_COLLECTOR)
REGISTRY.unregister(PROCESS_COLLECTOR)
VALIDATOR_NAME = os.getenv('VALIDATOR_NAME', socket.gethostname())
VALIDATOR_OUT_OF_SYNC = Gauge('validator_out_of_sync', 'Validator synchronization lag', ['name'])
# Settings
HTTP_PORT = int(os.getenv('HTTP_PORT', 9150))
INTERVAL = 30
def main():
while True:
try:
print('\nCollecting metrics...')
validator_status = ton.GetValidatorStatus()
VALIDATOR_OUT_OF_SYNC.labels(VALIDATOR_NAME).set(validator_status['outOfSync'])
except Exception:
traceback.print_exc()
time.sleep(INTERVAL)
if __name__ == '__main__':
start_http_server(HTTP_PORT)
main()