diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/blkin/babeltrace-plugins/json | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/blkin/babeltrace-plugins/json')
-rw-r--r-- | src/blkin/babeltrace-plugins/json/README.md | 5 | ||||
-rwxr-xr-x | src/blkin/babeltrace-plugins/json/src/babeltrace_json.py | 88 |
2 files changed, 93 insertions, 0 deletions
diff --git a/src/blkin/babeltrace-plugins/json/README.md b/src/blkin/babeltrace-plugins/json/README.md new file mode 100644 index 00000000..be0bbe2c --- /dev/null +++ b/src/blkin/babeltrace-plugins/json/README.md @@ -0,0 +1,5 @@ +babeltrace-json plugin +======================== + +This plugin enables us to send LTTng trace data to a Scribe server in a valid +json format diff --git a/src/blkin/babeltrace-plugins/json/src/babeltrace_json.py b/src/blkin/babeltrace-plugins/json/src/babeltrace_json.py new file mode 100755 index 00000000..0d21e018 --- /dev/null +++ b/src/blkin/babeltrace-plugins/json/src/babeltrace_json.py @@ -0,0 +1,88 @@ +#!/usr/bin/python +# babeltrace_zipkin.py + +import sys +sys.path.append("../../babeltrace-plugins") +import json +import getopt +from babeltrace import * +from scribe_client import ScribeClient + +HELP = "Usage: python babeltrace_zipkin.py path/to/file -s <server> -p <port>" +CATEGORY = "LTTng" + + +def main(argv): + try: + path = argv[0] + except: + raise TypeError(HELP) + + try: + opts, args = getopt.getopt(argv[1:], "hs:p:") + except getopt.GetoptError: + raise TypeError(HELP) + + server = None + port = None + for opt, arg in opts: + if opt == '-h': + raise TypeError(HELP) + elif opt == '-s': + server = arg + elif opt == '-p': + port = arg + + if not server: + server = "localhost" + if not port: + port = 1463 + + # Open connection with scribe + scribe_client = ScribeClient(port, server) + + # Create TraceCollection and add trace: + traces = TraceCollection() + trace_handle = traces.add_trace(path, "ctf") + if trace_handle is None: + raise IOError("Error adding trace") + + #iterate over events + for event in traces.events: + data = dict() + + data["parent_span_id"]= event["parent_span_id"] + data['name'] = event["trace_name"] + data ["trace_id"] = event["trace_id"] + data["span_id"] = event["span_id"] + data['port'] = event['port_no'] + data['service_name'] = event['service_name'] + data['ip'] = event['ip'] + data['evemt'] = event['event'] + data['timestamp'] = event.timestamp + ''' + for k, v in event.items(): + field_type = event._field(k).type + data[k] = format_value(field_type, v) + ''' + json_data = json.dumps(data) + + #send data to scribe + scribe_client.log(CATEGORY, json_data) + + scribe_client.close() + + +def format_value(field_type, value): + + if field_type == 1: + return int(value) + elif field_type == 2: + return float(value) + elif field_type == 8: + return [x for x in value] + else: + return str(value) + +if __name__ == "__main__": + main(sys.argv[1:]) |