-
Notifications
You must be signed in to change notification settings - Fork 8
/
misscheck.py
79 lines (64 loc) · 2.56 KB
/
misscheck.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import asyncio
import time
import aiohttp
from aiohttp.client import ClientSession
import json
from influxdb import InfluxDBClient
from datetime import datetime
from dotenv import load_dotenv
chains = {
"umee": "https://api.umee.huginn.tech/umee/oracle/v1/validators",
"kujira" : "https://lcd.kaiyo.kujira.setten.io/oracle/validators"
}
load_dotenv()
INFLUXDBNAME=os.getenv("INFLUXDB")
INFLUXDB_USERNAME=os.getenv("INFLUXDB_USERNAME")
INFLUXDB_PASSWORD=os.getenv("INFLUXDB_PASSWoRD")
def dbrecord(chain, moniker, addr, missing):
datestr = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
json_body = [
{
"measurement": "miss",
"tags": {
"address": addr,
"chain" : chain,
"moniker" : moniker
},
"time": datestr,
"fields": {
"missing": missing
}
}
]
return json_body
dbclient = InfluxDBClient(host='127.0.0.1',
port=8086,
username=INFLUXDB_USERNAME,
password=INFLUXDB_PASSWORD)
dbclient.switch_database(INFLUXDBNAME)
async def download_link(chain:str, url:str,
addr:str, moniker:str,
session:ClientSession):
full_url = f"{url}/{addr}/miss"
async with session.get(full_url) as response:
result = await response.text()
r = json.loads(result)
missing = int(r["miss_counter"])
dbclient.write_points(dbrecord(chain, moniker, addr, missing))
async def download_all(urls:list):
my_conn = aiohttp.TCPConnector(limit=10)
async with aiohttp.ClientSession(connector=my_conn) as session:
tasks = []
for chainname, url, addr, moniker in urls:
task = asyncio.ensure_future(
download_link(chain=chainname, url=url,
addr=addr, moniker=moniker, session=session))
tasks.append(task)
await asyncio.gather(*tasks,return_exceptions=True) # the await must be nest inside of the session
temp = []
for chainname, url in chains.items():
lines = open(f"/home/kujiracheck/cosmos/chain_{chainname}.txt").readlines()
for line in lines:
addr, moniker = line.strip().split("|||")
temp.append((chainname, url, addr, moniker))
asyncio.run(download_all(temp))