diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-07-03 12:40:00 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-07-03 12:40:00 +0200 |
commit | 70519875ee76bd8ab6ae49422ebc36598da28ec3 (patch) | |
tree | ffdbb1c3d17de8e036bf15394b311ef8deb01471 /example_stats_receiver.py | |
parent | 7054b2e43ee636dc4882bbd5fd7cc56b93e7f339 (diff) | |
download | ODR-AudioEnc-70519875ee76bd8ab6ae49422ebc36598da28ec3.tar.gz ODR-AudioEnc-70519875ee76bd8ab6ae49422ebc36598da28ec3.tar.bz2 ODR-AudioEnc-70519875ee76bd8ab6ae49422ebc36598da28ec3.zip |
Add stats sender to UNIX datagram socket
Diffstat (limited to 'example_stats_receiver.py')
-rwxr-xr-x | example_stats_receiver.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/example_stats_receiver.py b/example_stats_receiver.py new file mode 100755 index 0000000..99ce199 --- /dev/null +++ b/example_stats_receiver.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +import logging +logging.basicConfig(level=logging.DEBUG) +import sys +import os +import os.path +import socket +import argparse +import yaml + +parser = argparse.ArgumentParser( + description="Example Stats UNIX Datagram Socket Receiver") +parser.add_argument('-s', '--socket', default="/tmp/stats", type=str, + help='Full path of the socket', + required=False) + +cli_args = parser.parse_args() + +sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) + +if os.path.exists(cli_args.socket): + try: + os.unlink(cli_args.socket) + except OSError: + logging.warning("Could not unlink socket %s", cli_args.socket) + +sock.bind(cli_args.socket) + +logging.info("Starting receiver using socket '{}'".format(cli_args.socket)) + + +while True: + data, addr = sock.recvfrom(256) + + logging.info("RX from {}". format(addr)) + data = yaml.load(data) + print(data) |