Skip to content

Commit 77cb1b0

Browse files
authored
0.0.6 Landingpage (#2)
* not working * final 0.0.6
1 parent 292aeb0 commit 77cb1b0

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Use an official Python runtime as a parent image
22
FROM python:3.9-slim
33

4+
RUN DEBIAN_FRONTEND=noninteractive apt update -y \
5+
&& umask 0002 \
6+
&& DEBIAN_FRONTEND=noninteractive apt install -y procps
7+
48
# Set the working directory to /app
59
WORKDIR /app
610

@@ -19,4 +23,4 @@ ENV NAME=World
1923
# Run app.py when the container launches
2024
CMD ["python", "app.py"]
2125

22-
#harbor.freshbrewed.science/library/pybsposter:0.0.5
26+
#harbor.freshbrewed.science/library/pybsposter:0.0.6

app.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,67 @@
11
from flask import Flask, request, jsonify
22
from atproto import Client, client_utils
3+
from datetime import datetime
4+
import subprocess
35

46
app = Flask(__name__)
57

8+
@app.route('/')
9+
def index():
10+
try:
11+
# Get uptime using "uptime" command and parse output
12+
# ["cat", "/proc/uptime", "|", "sed '{print $2}'"],
13+
uptime_output = subprocess.run(
14+
["uptime"],
15+
capture_output=True,
16+
text=True,
17+
shell=True
18+
)
19+
20+
uptimeoutput = "N/A"
21+
22+
if uptime_output.returncode == 0:
23+
uptimeoutput = uptime_output.stdout
24+
25+
# Get current time
26+
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
27+
28+
# Read last 50 lines of log file
29+
log_output = subprocess.run(
30+
["tail", "-n", "50", "/var/log/pybsposter.log"],
31+
capture_output=True,
32+
text=True
33+
)
34+
35+
if log_output.returncode == 0:
36+
logs = log_output.stdout.split('\n')
37+
logs = [log.strip() for log in logs if log]
38+
else:
39+
logs = ["No log entries found"]
40+
41+
except subprocess.CalledProcessError as e:
42+
print(f"Error: {e}")
43+
uptime_seconds, current_time, logs = "N/A", "N/A", ["Error reading metrics or logs"]
44+
45+
return f"""
46+
<pre>
47+
______ ______ ______ _
48+
| ___ \ | ___ \ | ___ \ | |
49+
| |_/ / _ _ | |_/ / ___ | |_/ / ___ ___ | |_ ___ _ __
50+
| __/ | | | || ___ \/ __|| __/ / _ \ / __|| __| / _ \| '__|
51+
| | | |_| || |_/ /\__ \| | | (_) |\__ \| |_ | __/| |
52+
\_| \__, |\____/ |___/\_| \___/ |___/ \__| \___||_|
53+
__/ |
54+
|___/
55+
</pre>
56+
<br/>
57+
<br/>
58+
<h1>Container Metrics</h1>
59+
<p>Uptime: {uptimeoutput}</p>
60+
<p>Last Updated: {current_time}</p>
61+
<h2>Recent Logs:</h2>
62+
<ul>{''.join(f'<li>{log}</li>' for log in logs)}</ul>
63+
"""
64+
665
@app.route('/post', methods=['POST'])
766
def handle_post():
867
data = request.json

0 commit comments

Comments
 (0)