summaryrefslogtreecommitdiffstats
path: root/example_stats_receiver.py
diff options
context:
space:
mode:
Diffstat (limited to 'example_stats_receiver.py')
-rwxr-xr-xexample_stats_receiver.py38
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)