This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
66 lines (42 loc) · 1.83 KB
/
main.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
import asyncio
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)8s : %(name)30s : %(funcName)-20s : %(lineno)4d : %(message)s')
import aiohttp
from prometheus_async import aio
from settings import _speedport, _password, _cookie_persistent_path
from speedport import Client
from speedport import DslCollector, InterfaceCollector, LteCollector, ModuleCollector, BondingTunnelCollector, \
PPPoESessionCollector, CPUMemoryCollector, BondingTR181Collector
async_collectors = []
server_stats_save = aio.web.server_stats
async def server_stats(*args, **kwargs):
wait = []
for collector in async_collectors:
wait.append(asyncio.create_task(collector.collect()))
await asyncio.wait(wait)
return await server_stats_save(*args, **kwargs)
aio.web.server_stats = server_stats
async def main():
async with aiohttp.ClientSession() as session:
client = Client(_speedport, _password, session, _cookie_persistent_path)
login_task = asyncio.create_task(client.login_loop())
dsl = DslCollector(client)
async_collectors.append(dsl)
lte = LteCollector(client)
async_collectors.append(lte)
interface = InterfaceCollector(client)
async_collectors.append(interface)
module = ModuleCollector(client)
async_collectors.append(module)
bonding_tunnel = BondingTunnelCollector(client)
async_collectors.append(bonding_tunnel)
pppoe = PPPoESessionCollector(client)
async_collectors.append(pppoe)
cpu_mem = CPUMemoryCollector(client)
async_collectors.append(cpu_mem)
bonding_tr181 = BondingTR181Collector(client)
async_collectors.append(bonding_tr181)
await aio.web.start_http_server(port=9611)
await login_task
loop = asyncio.get_event_loop()
loop.run_until_complete(main())