BGP-Ranking/tools/monitoring.py

35 lines
1.4 KiB
Python
Raw Permalink Normal View History

2018-03-29 22:37:28 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2021-12-06 14:30:08 +01:00
import json
2018-03-29 22:37:28 +02:00
2021-12-06 14:30:08 +01:00
from redis import Redis
from bgpranking.default import get_socket_path
from bgpranking.helpers import get_ipasn
2018-03-29 22:37:28 +02:00
class Monitor():
def __init__(self):
2021-12-06 14:30:08 +01:00
self.intake = Redis(unix_socket_path=get_socket_path('intake'), db=0, decode_responses=True)
self.sanitize = Redis(unix_socket_path=get_socket_path('prepare'), db=0, decode_responses=True)
self.cache = Redis(unix_socket_path=get_socket_path('cache'), db=1, decode_responses=True)
self.ipasn = get_ipasn()
2018-03-29 22:37:28 +02:00
def get_values(self):
ips_in_intake = self.intake.scard('intake')
ready_to_insert = self.sanitize.scard('to_insert')
ipasn_meta = self.ipasn.meta()
if len(ipasn_meta['cached_dates']['caida']['v4']['cached']) > 15:
ipasn_meta['cached_dates']['caida']['v4']['cached'] = 'Too many entries'
if len(ipasn_meta['cached_dates']['caida']['v6']['cached']) > 15:
ipasn_meta['cached_dates']['caida']['v6']['cached'] = 'Too many entries'
return json.dumps({'Non-parsed IPs': ips_in_intake, 'Parsed IPs': ready_to_insert,
2021-12-06 14:30:08 +01:00
'running': self.cache.zrangebyscore('running', '-inf', '+inf', withscores=True),
'IPASN History': ipasn_meta},
indent=2)
2021-12-06 14:30:08 +01:00
if __name__ == '__main__':
m = Monitor()
print(m.get_values())