From eccbde3d4d9f9ed552d10c8eb2ab6a55a3659633 Mon Sep 17 00:00:00 2001 From: Isaac Johnson Date: Fri, 7 Feb 2025 07:45:10 -0600 Subject: [PATCH 1/2] not working --- Dockerfile | 4 ++++ app.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/Dockerfile b/Dockerfile index 4bb7cca..18e8326 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 diff --git a/app.py b/app.py index fbe4d18..4757edd 100644 --- a/app.py +++ b/app.py @@ -1,8 +1,61 @@ 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( + ["awk '{print $1}'", "/proc/uptime"], + capture_output=True, + text=True, + shell=True + ) + + if uptime_output.returncode == 0: + print("Response:", flush=True) + print(uptime_output.stdout, flush=True) + print("STDERR:", flush=True) + print(uptime_output.stderr, flush=True) + + uptime_seconds = float(uptime_output.stdout.strip()) + minutes, seconds = divmod(int(uptime_seconds * 60), 60) + else: + minutes, seconds = "N/A", "N/A" + + # 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: {minutes} minutes and {seconds} seconds

+

Last Updated: {current_time}

+

Recent Logs:

+ + """ + @app.route('/post', methods=['POST']) def handle_post(): data = request.json From 0ea6118aa4ff80d8259f2e30b083ffbff4928167 Mon Sep 17 00:00:00 2001 From: Isaac Johnson Date: Fri, 7 Feb 2025 07:57:52 -0600 Subject: [PATCH 2/2] final 0.0.6 --- Dockerfile | 2 +- app.py | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 18e8326..728733b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,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 4757edd..801b6a5 100644 --- a/app.py +++ b/app.py @@ -11,22 +11,16 @@ def index(): # Get uptime using "uptime" command and parse output # ["cat", "/proc/uptime", "|", "sed '{print $2}'"], uptime_output = subprocess.run( - ["awk '{print $1}'", "/proc/uptime"], + ["uptime"], capture_output=True, text=True, shell=True ) - if uptime_output.returncode == 0: - print("Response:", flush=True) - print(uptime_output.stdout, flush=True) - print("STDERR:", flush=True) - print(uptime_output.stderr, flush=True) + uptimeoutput = "N/A" - uptime_seconds = float(uptime_output.stdout.strip()) - minutes, seconds = divmod(int(uptime_seconds * 60), 60) - else: - minutes, seconds = "N/A", "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") @@ -49,8 +43,20 @@ def index(): uptime_seconds, current_time, logs = "N/A", "N/A", ["Error reading metrics or logs"] return f""" +
+         ______        ______      ______              _               
+        | ___ \       | ___ \     | ___ \            | |              
+        | |_/ / _   _ | |_/ / ___ | |_/ /  ___   ___ | |_   ___  _ __ 
+        |  __/ | | | || ___ \/ __||  __/  / _ \ / __|| __| / _ \| '__|
+        | |    | |_| || |_/ /\__ \| |    | (_) |\__ \| |_ |  __/| |   
+        \_|     \__, |\____/ |___/\_|     \___/ |___/ \__| \___||_|   
+                __/ |                                                
+                |___/                                                 
+        
+
+

Container Metrics

-

Uptime: {minutes} minutes and {seconds} seconds

+

Uptime: {uptimeoutput}

Last Updated: {current_time}

Recent Logs: