11""" Server metrics upload.
22"""
3- # -*- coding: utf-8 -*-
4-
3+ import asyncio
54import os
65import platform
76import time
1211from aleph_message .status import MessageStatus
1312
1413from aleph .sdk .chains .ethereum import get_fallback_account
15- from aleph .sdk .client import AuthenticatedAlephClientSync , AuthenticatedAlephHttpClient
14+ from aleph .sdk .client import AuthenticatedAlephHttpClient
1615from aleph .sdk .conf import settings
1716
17+ # -*- coding: utf-8 -*-
18+
1819
1920def get_sysinfo ():
2021 uptime = int (time .time () - psutil .boot_time ())
@@ -53,10 +54,12 @@ def get_cpu_cores():
5354 return [c ._asdict () for c in psutil .cpu_times_percent (0 , percpu = True )]
5455
5556
56- def send_metrics (
57- session : AuthenticatedAlephClientSync , metrics
57+ async def send_metrics (
58+ session : AuthenticatedAlephHttpClient , metrics
5859) -> Tuple [AlephMessage , MessageStatus ]:
59- return session .create_aggregate (key = "metrics" , content = metrics , channel = "SYSINFO" )
60+ return await session .create_aggregate (
61+ key = "metrics" , content = metrics , channel = "SYSINFO"
62+ )
6063
6164
6265def collect_metrics ():
@@ -68,17 +71,17 @@ def collect_metrics():
6871 }
6972
7073
71- def main ():
74+ async def main ():
7275 account = get_fallback_account ()
73- with AuthenticatedAlephHttpClient (
76+ async with AuthenticatedAlephHttpClient (
7477 account = account , api_server = settings .API_HOST
7578 ) as session :
7679 while True :
7780 metrics = collect_metrics ()
78- message , status = send_metrics (session , metrics )
81+ message , status = await send_metrics (session , metrics )
7982 print ("sent" , message .item_hash )
8083 time .sleep (10 )
8184
8285
8386if __name__ == "__main__" :
84- main ()
87+ asyncio . run ( main () )
0 commit comments