Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
#harbor.freshbrewed.science/library/pybsposter:0.0.6
59 changes: 59 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -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"""
<pre>
______ ______ ______ _
| ___ \ | ___ \ | ___ \ | |
| |_/ / _ _ | |_/ / ___ | |_/ / ___ ___ | |_ ___ _ __
| __/ | | | || ___ \/ __|| __/ / _ \ / __|| __| / _ \| '__|
| | | |_| || |_/ /\__ \| | | (_) |\__ \| |_ | __/| |
\_| \__, |\____/ |___/\_| \___/ |___/ \__| \___||_|
__/ |
|___/
</pre>
<br/>
<br/>
<h1>Container Metrics</h1>
<p>Uptime: {uptimeoutput}</p>
<p>Last Updated: {current_time}</p>
<h2>Recent Logs:</h2>
<ul>{''.join(f'<li>{log}</li>' for log in logs)}</ul>
"""

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