Create a flask app to show metrics from collectd 27/72427/18
authorEmma Foley <efoley@redhat.com>
Wed, 21 Apr 2021 18:59:52 +0000 (19:59 +0100)
committerEmma Foley <efoley@redhat.com>
Fri, 17 Dec 2021 09:48:20 +0000 (09:48 +0000)
Change-Id: Ief2e99d551809705c0b246a7cae5bd5804f97137
Signed-off-by: Emma Foley <efoley@redhat.com>
docker/flask_app/Dockerfile [new file with mode: 0644]
docker/flask_app/README [new file with mode: 0644]
docker/flask_app/flask_app.py [new file with mode: 0644]
docker/flask_app/requirements.txt [new file with mode: 0644]
docs/release/release-notes/notes/collectd-6-testing-flask-app-2bb0ca1326775dd8.yaml [new file with mode: 0644]

diff --git a/docker/flask_app/Dockerfile b/docker/flask_app/Dockerfile
new file mode 100644 (file)
index 0000000..67e6d58
--- /dev/null
@@ -0,0 +1,25 @@
+# Copyright 2021 Anuket and others. All rights reserved.
+#
+# 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.
+#
+
+FROM python:3-alpine
+
+EXPOSE 5000
+
+WORKDIR /app
+COPY ./ /app
+
+RUN python -m pip  install -r requirements.txt
+
+ENTRYPOINT ["python", "flask_app.py"]
diff --git a/docker/flask_app/README b/docker/flask_app/README
new file mode 100644 (file)
index 0000000..03f8f3f
--- /dev/null
@@ -0,0 +1,45 @@
+To build this run:
+  sudo docker build -t my-flask-app .
+
+To run the app and see collectd metrics:
+
+  sudo docker run -d --net=host  my-flask-app
+  OR
+  sudo docker run -d -p 5000:5000  my-flask-app
+
+and configure collectd to use the write_http plugin:
+
+ LoadPlugin write_http
+
+ <Plugin "write_http">
+   <Node "example">
+     URL "http://127.0.0.1:5000"
+     Format Command
+     # Format JSON
+   </Node>
+ </Plugin>
+
+Format Command is used to make the output more readable for humans.
+You can also use JSON.
+
+Later the server will do something more useful.
+To view the metrics that are being sent by collectd, run::
+
+   sudo docker inspect <container_id>
+   #OR
+   sudo docker logs <container_id>
+
+Metrics from collectd-5.x will use PUTVAL
+Metrics from collectd-6.x will use PUTMETRIC
+
+Sample output::
+
+  127.0.0.1 - - [21/Apr/2021 19:31:49] "POST / HTTP/1.1" 200 -
+  PUTVAL fbae30cc-2f20-11b2-a85c-819293100691/turbostat-cpu00/gauge-TSC interval=10.000 1619029909.268:2112.02271161789
+  PUTVAL fbae30cc-2f20-11b2-a85c-819293100691/turbostat-cpu00/frequency-busy interval=10.000 1619029909.268:1613.51555288381
+  PUTVAL fbae30cc-2f20-11b2-a85c-819293100691/turbostat-cpu00/percent-c1 interval=10.000 1619029909.268:86.2353665532377
+  PUTVAL fbae30cc-2f20-11b2-a85c-819293100691/turbostat-cpu00/frequency-average interval=10.000 1619029909.268:222.094501460956
+  PUTVAL fbae30cc-2f20-11b2-a85c-819293100691/turbostat-pkg00/temperature interval=10.000 1619029909.268:53
+  PUTVAL fbae30cc-2f20-11b2-a85c-819293100691/turbostat-pkg00/temperature-tcc_activation interval=10.000 1619029909.268:100
+  PUTVAL fbae30cc-2f20-11b2-a85c-819293100691/turbostat-cpu04/frequency-average interval=10.000 1619029909.268:206.978572579757
+
diff --git a/docker/flask_app/flask_app.py b/docker/flask_app/flask_app.py
new file mode 100644 (file)
index 0000000..771a91b
--- /dev/null
@@ -0,0 +1,16 @@
+from flask import Flask, request
+import json
+
+app = Flask(__name__)
+
+@app.route('/', methods=['GET', 'POST'])
+def get_data():
+    #print(request.data)
+    #print(type(request.data))
+    print(request.data.decode('utf-8'))
+    #print(json.loads(request.data.decode("utf-8")))
+
+    return 'This is working!'
+
+if __name__=='__main__':
+    app.run(debug=True, host='0.0.0.0')
diff --git a/docker/flask_app/requirements.txt b/docker/flask_app/requirements.txt
new file mode 100644 (file)
index 0000000..e3e9a71
--- /dev/null
@@ -0,0 +1 @@
+Flask
diff --git a/docs/release/release-notes/notes/collectd-6-testing-flask-app-2bb0ca1326775dd8.yaml b/docs/release/release-notes/notes/collectd-6-testing-flask-app-2bb0ca1326775dd8.yaml
new file mode 100644 (file)
index 0000000..9c60587
--- /dev/null
@@ -0,0 +1,3 @@
+containers:
+  - |
+    Add a flask app for testing collectd using metrics sent via write_http plugin.