-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.py
64 lines (53 loc) · 2.12 KB
/
monitor.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
52
53
54
55
56
57
58
59
60
61
62
63
64
from logging import getLogger
from time import sleep
from typing import List
import settings
from monitors import (
ArbRestakeMonitor,
DiscordMonitor,
DistManagerMonitor,
IndexerMonitor,
Monitor,
Network,
ProtocolManagerMonitor,
)
from monitors.base import MonitorException
from telegram import notify_exception, notify_monitor_exception
logger = getLogger(__name__)
class Monitoring:
monitors: List[Monitor] = []
def __init__(self):
logger.info("Setting up monitors")
self.monitors.append(IndexerMonitor("https://mainnet-indexer.sherlock.xyz", Network.MAINNET))
self.monitors.append(DistManagerMonitor(Network.MAINNET))
self.monitors.append(ProtocolManagerMonitor("https://mainnet-indexer.sherlock.xyz", Network.MAINNET))
self.monitors.append(ArbRestakeMonitor("https://mainnet-indexer.sherlock.xyz", Network.MAINNET))
self.monitors.append(DiscordMonitor(Network.MAINNET))
logger.info("%s monitors set up.", len(self.monitors))
def start(self):
logger.info("Monitor loop started")
try:
while True:
for monitor in self.monitors:
monitor_name = f"{monitor.__class__.__name__} - {monitor.network._name_}"
try:
logger.info("Running %s monitor", monitor_name)
monitor.run()
except MonitorException as e:
logger.error("Monitor %s has failed: %s", monitor_name, e)
notify_monitor_exception(monitor_name=monitor_name, exception=e)
except Exception as e:
logger.exception(e)
notify_exception(exception=e)
logger.info("Sleeping for %ss.", settings.MONITOR_SLEEP_BETWEEN_CALL)
sleep(settings.MONITOR_SLEEP_BETWEEN_CALL)
except KeyboardInterrupt:
pass
finally:
logger.info("Monitor loop ended")
def main():
logger.info("Monitor process started")
monitor = Monitoring()
monitor.start()
if __name__ == "__main__":
main()