diff --git a/Case study 1/IN-NCB Case 1 analysis.docx b/Case study 1/IN-NCB Case 1 analysis.docx new file mode 100644 index 0000000..78906e6 Binary files /dev/null and b/Case study 1/IN-NCB Case 1 analysis.docx differ diff --git a/Case study 1/diagram case 1.drawio b/Case study 1/diagram case 1.drawio new file mode 100644 index 0000000..4989020 --- /dev/null +++ b/Case study 1/diagram case 1.drawio @@ -0,0 +1,343 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Case study 1/monitoring/collect.py b/Case study 1/monitoring/collect.py new file mode 100644 index 0000000..54a8096 --- /dev/null +++ b/Case study 1/monitoring/collect.py @@ -0,0 +1,19 @@ +from flask import Flask, request, jsonify +from datetime import datetime +import json + +app = Flask(__name__) + +@app.route('/collect', methods=['POST']) +def collect(): + data = request.get_json() + timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + + with open("collected_data.log", "a") as f: + f.write(f"{timestamp} - {json.dumps(data)}\n") + + print(f"[{timestamp}] Data received from {data.get('hostname', 'unknown')}") + return jsonify({"status": "success"}), 200 + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000) diff --git a/Case study 1/monitoring/collected_data.log b/Case study 1/monitoring/collected_data.log new file mode 100644 index 0000000..5ae5d5f --- /dev/null +++ b/Case study 1/monitoring/collected_data.log @@ -0,0 +1 @@ +2025-10-28 14:55:03 - {"hostname": "hp-arch", "os": "Linux", "cpu_percent": 1.9, "memory_percent": 30.8, "disk_usage": 85.2, "time": "2025-10-28T14:55:03.021372"} diff --git a/Case study 1/monitoring/prereq.txt b/Case study 1/monitoring/prereq.txt new file mode 100644 index 0000000..e69de29 diff --git a/Case study 1/monitoring/send_metrics.py b/Case study 1/monitoring/send_metrics.py new file mode 100644 index 0000000..7dc375c --- /dev/null +++ b/Case study 1/monitoring/send_metrics.py @@ -0,0 +1,32 @@ +import psutil +import platform +import requests +import socket +from datetime import datetime + +SERVER_URL = "http://localhost:5000/collect" # change this! + +def collect_metrics(): + data = { + "hostname": socket.gethostname(), + "os": platform.system(), + "cpu_percent": psutil.cpu_percent(interval=1), + "memory_percent": psutil.virtual_memory().percent, + "disk_usage": psutil.disk_usage('/').percent, + "time": datetime.now().isoformat() + } + return data + +def send_data(data): + try: + response = requests.post(SERVER_URL, json=data, timeout=5) + if response.status_code == 200: + print("Data sent successfully") + else: + print("Server returned:", response.status_code) + except Exception as e: + print("Error sending data:", e) + +if __name__ == "__main__": + metrics = collect_metrics() + send_data(metrics) \ No newline at end of file diff --git a/python/flask_scripting/__pycache__/flask.cpython-313.pyc b/python/flask_scripting/__pycache__/flask.cpython-313.pyc new file mode 100644 index 0000000..733339c Binary files /dev/null and b/python/flask_scripting/__pycache__/flask.cpython-313.pyc differ diff --git a/python/flask_scripting/app.py b/python/flask_scripting/app.py new file mode 100644 index 0000000..953ee88 --- /dev/null +++ b/python/flask_scripting/app.py @@ -0,0 +1,12 @@ +from flask import Flask +# from flask import render_template + +app = Flask(__name__) + + +@app.route("/") +def init(): + return "

Hello, World!

" + + +app.run(host="127.0.0.1", port=5000) \ No newline at end of file