-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathar-subzero-graphite.py
More file actions
executable file
·64 lines (54 loc) · 2.04 KB
/
ar-subzero-graphite.py
File metadata and controls
executable file
·64 lines (54 loc) · 2.04 KB
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
#!/usr/bin/python3
#
# Copyright 2018 Lim Wei Chiang
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import argparse
import zmq
# Set up CLI options and input
parser = argparse.ArgumentParser(description="0MQ client")
parser.add_argument("--zmq-server", help="0MQ server address (default=localhost)")
parser.add_argument("--zmq-port", help="0MQ server port (default=5555)")
parser.add_argument("--zmq-topic", help="0MQ topics to subscribe to, comma delimited string, no spaces (default=all)")
args = parser.parse_args()
# Set 0MQ connection targets
zmq_server = args.zmq_server if args.zmq_server is not None else "localhost"
zmq_port = args.zmq_port if args.zmq_port is not None else "5555"
zmq_connect_target = "tcp://" + zmq_server + ":" + zmq_port
# Compile 0MQ topics for subscription
if args.zmq_topic is not None:
zmq_topic = args.zmq_topic.split(",")
else:
zmq_topic = [""]
# Prepare 0MQ context and sockets
context = zmq.Context()
zmq_socket = context.socket(zmq.SUB)
zmq_socket.connect(zmq_connect_target)
for t in zmq_topic:
zmq_socket.subscribe(t)
# Start reading
while zmq_socket.closed is not True:
try:
msg = zmq_socket.recv()
(msg_topic, msg_payload) = msg.decode("utf-8").split("\n", 1)
msg_json = json.loads(msg_payload)
#print(json.dumps(msg_json, indent=4))
if column in msg_json and data in msg_json
print(column)
print(data)
except KeyboardInterrupt:
zmq_socket.disconnect(zmq_connect_target)
zmq_socket.close()
# The end
print("\nShutting down, goodbye!")