ELK stack for visualizing Wownero network
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

51 lines
1.7 KiB

import requests
import os
import arrow
import json
payload = {'jsonrpc': '2.0', 'id': '0', 'method': '', 'params': {}}
headers = {'Content-Type': 'application/json'}
daemon = 'http://crypto.int.lzahq.tech:34568'
json_rpc = daemon + '/json_rpc'
data_path = './data/logs'
def make_payload(rpc_method, params={}):
payload['method'] = rpc_method
payload['params'] = params
return payload
def make_rpc(rpc_method, http_method='get', _payload={}):
if http_method == 'get':
req = requests.get
else:
req = requests.post
r = req(
json_rpc, timeout=5, headers=headers,
json=make_payload(rpc_method, _payload)
)
r.raise_for_status()
return r.json()['result']
def run():
top_block = make_rpc('get_block_count', 'get')['count']
for block in range(top_block - 1, 0, -1):
_path = f'{data_path}/{block}.json'
if not os.path.isfile(_path):
block_data = make_rpc('get_block', 'get', {'height': block})['block_header']
ts = arrow.get(block_data['timestamp'])
if block_data['timestamp'] == 0:
ts = arrow.get('2018-04-01 04:20:00')
block_data['datetime'] = ts.format('YYYY-MM-DD HH:mm:ss')
index_date = ts.format('YYYY-MM')
index_name = f'wownero-block-data-{index_date}'
r = requests.post(
f'http://localhost:9200/{index_name}/_doc/{block_data["height"]}',
json=block_data, timeout=5, headers=headers
)
r.raise_for_status()
with open(_path, 'w') as f:
f.write(json.dumps(block_data))
print(f'Added file {_path} for index {index_name}')
if __name__ == '__main__':
run()