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/telemetry | |
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/telemetry')
-rw-r--r-- | src/telemetry/README.md | 4 | ||||
-rw-r--r-- | src/telemetry/server/app.wsgi | 10 | ||||
-rw-r--r-- | src/telemetry/server/ceph_telemetry/__init__.py | 1 | ||||
-rwxr-xr-x | src/telemetry/server/ceph_telemetry/app.py | 25 | ||||
-rw-r--r-- | src/telemetry/server/ceph_telemetry/rest/__init__.py | 2 | ||||
-rw-r--r-- | src/telemetry/server/ceph_telemetry/rest/device.py | 40 | ||||
-rw-r--r-- | src/telemetry/server/ceph_telemetry/rest/index.py | 7 | ||||
-rw-r--r-- | src/telemetry/server/ceph_telemetry/rest/report.py | 12 | ||||
-rw-r--r-- | src/telemetry/server/requirements.txt | 3 |
9 files changed, 104 insertions, 0 deletions
diff --git a/src/telemetry/README.md b/src/telemetry/README.md new file mode 100644 index 00000000..f5cdccad --- /dev/null +++ b/src/telemetry/README.md @@ -0,0 +1,4 @@ +# Ceph-telemetry +This is a renewed version of `ceph-brag`. It enables the Ceph project to collect statistics from users' clusters where the `telemetry` module is enabled. + +Statistics are indexed in Elasticsearch. diff --git a/src/telemetry/server/app.wsgi b/src/telemetry/server/app.wsgi new file mode 100644 index 00000000..280a7775 --- /dev/null +++ b/src/telemetry/server/app.wsgi @@ -0,0 +1,10 @@ +import sys +import os +pwd = os.path.dirname(os.path.realpath(__file__)) +sys.path.insert(0, pwd) + +from ceph_telemetry import create_app + +app = create_app(__name__) + +application = app diff --git a/src/telemetry/server/ceph_telemetry/__init__.py b/src/telemetry/server/ceph_telemetry/__init__.py new file mode 100644 index 00000000..b23f70e0 --- /dev/null +++ b/src/telemetry/server/ceph_telemetry/__init__.py @@ -0,0 +1 @@ +from .app import create_app
\ No newline at end of file diff --git a/src/telemetry/server/ceph_telemetry/app.py b/src/telemetry/server/ceph_telemetry/app.py new file mode 100755 index 00000000..0d2b5e1d --- /dev/null +++ b/src/telemetry/server/ceph_telemetry/app.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +import argparse +from flask_restful import Api +from flask import Flask +from ceph_telemetry.rest import Index, Report, Device + + +def create_app(name): + app = Flask(name) + api = Api(app, catch_all_404s=True) + api.add_resource(Index, '/') + api.add_resource(Report, '/report') + api.add_resource(Device, '/device') + return app + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Ceph Telemetry REST API') + parser.add_argument("--host", action="store", dest="host", + default="::", help="Host/IP to bind on") + parser.add_argument("--port", action="store", dest="port", type=int, + default=9000, help="Port to listen on") + args = parser.parse_args() + app = create_app(__name__) + app.run(debug=True, host=args.host, port=args.port) diff --git a/src/telemetry/server/ceph_telemetry/rest/__init__.py b/src/telemetry/server/ceph_telemetry/rest/__init__.py new file mode 100644 index 00000000..31521440 --- /dev/null +++ b/src/telemetry/server/ceph_telemetry/rest/__init__.py @@ -0,0 +1,2 @@ +from .index import Index +from .report import Report diff --git a/src/telemetry/server/ceph_telemetry/rest/device.py b/src/telemetry/server/ceph_telemetry/rest/device.py new file mode 100644 index 00000000..02506c0e --- /dev/null +++ b/src/telemetry/server/ceph_telemetry/rest/device.py @@ -0,0 +1,40 @@ +from flask import request, jsonify +from flask_restful import Resource +import datetime +import hashlib +import json +import copy +import psycopg2 + +class Device(Resource): + def __init__(self, report=None): + super(Device, self).__init__() + self.report = report + with open('/opt/telemetry/pg_pass.txt', 'r') as f: + p = f.read() + self.pg_password = p.strip() + + def put(self): + self.report = request.get_json(force=True) + + self.post_to_postgres() + + return jsonify(status=True) + + def _connect_pg(self): + return psycopg2.connect( + host='localhost', + database='telemetry', + user='telemetry', + password=self.pg_password, + ) + + def post_to_postgres(self): + conn = self._connect_pg() + cur = conn.cursor() + for devid, devinfo in self.report: + for stamp, report in devinfo: + cur.execute( + 'INSERT INTO device_report (device_id, report_stamp, report) VALUES (%s,%s,%s) ON CONFLICT DO NOTHING', + (devid, stamp, report)) + conn.commit() diff --git a/src/telemetry/server/ceph_telemetry/rest/index.py b/src/telemetry/server/ceph_telemetry/rest/index.py new file mode 100644 index 00000000..413d4947 --- /dev/null +++ b/src/telemetry/server/ceph_telemetry/rest/index.py @@ -0,0 +1,7 @@ +from flask import jsonify +from flask_restful import Resource + + +class Index(Resource): + def get(self): + return jsonify(status=True) diff --git a/src/telemetry/server/ceph_telemetry/rest/report.py b/src/telemetry/server/ceph_telemetry/rest/report.py new file mode 100644 index 00000000..e589e65b --- /dev/null +++ b/src/telemetry/server/ceph_telemetry/rest/report.py @@ -0,0 +1,12 @@ +from flask import request, jsonify +from flask_restful import Resource +from elasticsearch import Elasticsearch + + +class Report(Resource): + def put(self): + report = request.get_json(force=True) + es = Elasticsearch() + es.index(index='telemetry', doc_type='report', id=report['report_id'], + body=report) + return jsonify(status=True) diff --git a/src/telemetry/server/requirements.txt b/src/telemetry/server/requirements.txt new file mode 100644 index 00000000..dca98199 --- /dev/null +++ b/src/telemetry/server/requirements.txt @@ -0,0 +1,3 @@ +flask +flask_restful +elasticsearch |