-
Notifications
You must be signed in to change notification settings - Fork 20
/
diag.py
executable file
·68 lines (58 loc) · 1.5 KB
/
diag.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
#!/usr/bin/env python3
import asyncio
import logging.config
import os
import sys
import socket
LOG_ROOT = '.'
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'stream': sys.stderr,
'formatter': 'standard',
},
'default': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': os.path.join(LOG_ROOT, 'default.log'),
'formatter': 'standard',
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
},
}
logging.config.dictConfig(LOGGING)
from aiozk import ZKClient # noqa
def printe(msg):
print(msg, file=sys.stderr)
sys.stderr.flush()
async def main():
# await asyncio.sleep(10)
logging.debug('Start')
zk = ZKClient('zk', session_timeout=3)
await zk.start()
while 1:
try:
await zk.exists('/zookeeper')
c = zk.session.conn
ip = c.host_ip
logging.debug('DIAG Curr conn: {}'.format([socket.gethostbyaddr(ip)[0]]))
except Exception as e:
logging.error('DIAG Exc: {}'.format(e))
await asyncio.sleep(1)
if __name__ == '__main__':
asyncio.run(main())