diff --git a/Dockerfile b/Dockerfile index 4bb7cca..728733b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,10 @@ # Use an official Python runtime as a parent image FROM python:3.9-slim +RUN DEBIAN_FRONTEND=noninteractive apt update -y \ + && umask 0002 \ + && DEBIAN_FRONTEND=noninteractive apt install -y procps + # Set the working directory to /app WORKDIR /app @@ -19,4 +23,4 @@ ENV NAME=World # Run app.py when the container launches CMD ["python", "app.py"] -#harbor.freshbrewed.science/library/pybsposter:0.0.5 \ No newline at end of file +#harbor.freshbrewed.science/library/pybsposter:0.0.6 diff --git a/app.py b/app.py index fbe4d18..801b6a5 100644 --- a/app.py +++ b/app.py @@ -1,8 +1,67 @@ from flask import Flask, request, jsonify from atproto import Client, client_utils +from datetime import datetime +import subprocess app = Flask(__name__) +@app.route('/') +def index(): + try: + # Get uptime using "uptime" command and parse output + # ["cat", "/proc/uptime", "|", "sed '{print $2}'"], + uptime_output = subprocess.run( + ["uptime"], + capture_output=True, + text=True, + shell=True + ) + + uptimeoutput = "N/A" + + if uptime_output.returncode == 0: + uptimeoutput = uptime_output.stdout + + # Get current time + current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + + # Read last 50 lines of log file + log_output = subprocess.run( + ["tail", "-n", "50", "/var/log/pybsposter.log"], + capture_output=True, + text=True + ) + + if log_output.returncode == 0: + logs = log_output.stdout.split('\n') + logs = [log.strip() for log in logs if log] + else: + logs = ["No log entries found"] + + except subprocess.CalledProcessError as e: + print(f"Error: {e}") + uptime_seconds, current_time, logs = "N/A", "N/A", ["Error reading metrics or logs"] + + return f""" +
+         ______        ______      ______              _               
+        | ___ \       | ___ \     | ___ \            | |              
+        | |_/ / _   _ | |_/ / ___ | |_/ /  ___   ___ | |_   ___  _ __ 
+        |  __/ | | | || ___ \/ __||  __/  / _ \ / __|| __| / _ \| '__|
+        | |    | |_| || |_/ /\__ \| |    | (_) |\__ \| |_ |  __/| |   
+        \_|     \__, |\____/ |___/\_|     \___/ |___/ \__| \___||_|   
+                __/ |                                                
+                |___/                                                 
+        
+
+
+

Container Metrics

+

Uptime: {uptimeoutput}

+

Last Updated: {current_time}

+

Recent Logs:

+ + """ + @app.route('/post', methods=['POST']) def handle_post(): data = request.json