- Posted on
- • Artificial Intelligence
Artificial Intelligence Dashboard Projects
- Author
-
-
- User
- linuxbash
- Posts by this author
- Posts by this author
-
Build an AI Dashboard on Linux: From Bash to Beautiful Metrics
Dashboards are how we turn AI from a black box into an operational system you can trust. If you’ve ever asked “Is my model healthy?” or “Why did latency spike last night?”, you need an AI dashboard. In this post, you’ll build a minimal but powerful AI dashboard stack on Linux using Bash, Python, and Streamlit. You’ll collect metrics, score data with a tiny API, persist results, and visualize everything in near real time.
Value: a well-instrumented AI system reduces outages, speeds up incident response, and makes it easier to improve accuracy, cost, and latency.
Why AI dashboards are worth your weekend
Visibility beats guessing: You can’t tune what you don’t measure. Latency, error rates, drift signals, and cost must be visible.
Cross-team alignment: Product, ops, and data science all need different views. A shared dashboard keeps everyone honest and fast.
Production readiness: Logs are retrospective. Dashboards give you live and historical slices for MTTD/MTTR, audits, and SLAs.
Linux-native glue: Most AI workloads deploy on Linux. Bash, curl, and cron make reliable, composable pipelines that you control.
What you’ll build
A tiny FastAPI service that simulates an AI model.
A Bash collector that:
- Calls the AI API
- Reads system metrics
- Stores everything in SQLite
A Streamlit dashboard that charts latency, load, and outcomes.
Optional automation via cron.
You can adapt this structure to real models or external APIs later.
1) Install prerequisites (apt/dnf/zypper)
The commands below cover Debian/Ubuntu (apt), Fedora/RHEL/CentOS (dnf), and openSUSE (zypper).
Packages: Python, virtualenv/pip, Git, curl, jq, Node.js (optional), Docker (optional).
APT (Debian/Ubuntu):
sudo apt update
sudo apt install -y python3 python3-venv python3-pip git curl jq nodejs npm docker.io docker-compose-plugin
sudo systemctl enable --now docker
DNF (Fedora/RHEL/CentOS Stream):
sudo dnf -y install python3 python3-virtualenv python3-pip git curl jq nodejs npm moby-engine docker-compose
sudo systemctl enable --now docker
Zypper (openSUSE Leap/Tumbleweed):
sudo zypper refresh
sudo zypper install -y python3 python3-virtualenv python3-pip git curl jq nodejs npm docker docker-compose
sudo systemctl enable --now docker
Create a project:
mkdir -p ~/ai-dashboard && cd ~/ai-dashboard
python3 -m venv venv
. venv/bin/activate
Requirements file:
cat > requirements.txt << 'EOF'
fastapi
uvicorn[standard]
pandas
requests
pydantic
streamlit
EOF
pip install -r requirements.txt
2) Spin up a tiny “AI” API (FastAPI)
This simulates a model scoring endpoint you can swap for your real service.
cat > model_api.py << 'EOF'
from fastapi import FastAPI
from pydantic import BaseModel
import time
app = FastAPI(title="Mini AI API")
class Item(BaseModel):
text: str
@app.post("/score")
def score(item: Item):
# Simulate some work
time.sleep(0.05)
text = item.text.lower()
sentiment = "positive" if "good" in text or "love" in text else "negative"
latency_ms = 50 # simulated
return {"sentiment": sentiment, "latency_ms": latency_ms}
EOF
Run the API:
uvicorn model_api:app --reload --host 127.0.0.1 --port 8000
Test it:
curl -s -X POST localhost:8000/score \
-H "Content-Type: application/json" \
-d '{"text":"I love fast, reliable models"}'
3) Collect and store metrics (Bash + curl + jq + SQLite via Python)
This script fetches:
System load from /proc
AI API latency/outcome from the FastAPI service
Writes a row to SQLite
cat > collector.sh << 'EOF'
#!/usr/bin/env bash
set -euo pipefail
DB="metrics.db"
API_URL="${API_URL:-http://127.0.0.1:8000/score}"
TEXT="${TEXT:-This is a good day for testing}"
# Create table if needed and insert a row (using Python's sqlite3)
init_and_insert() {
python3 - <<'PY'
import os, sqlite3, sys
from datetime import datetime, timezone
db = os.environ.get("DB","metrics.db")
ts = os.environ["TS"]
load1 = float(os.environ["LOAD1"])
sentiment = os.environ["SENTIMENT"]
latency = int(os.environ["LATENCY"])
con = sqlite3.connect(db)
cur = con.cursor()
cur.execute("""
CREATE TABLE IF NOT EXISTS metrics (
ts TEXT NOT NULL,
load1 REAL NOT NULL,
latency_ms INTEGER NOT NULL,
sentiment TEXT NOT NULL
)
""")
cur.execute("INSERT INTO metrics (ts, load1, latency_ms, sentiment) VALUES (?,?,?,?)",
(ts, load1, latency, sentiment))
con.commit()
con.close()
PY
}
# Collect system metric
LOAD1=$(awk '{print $1}' /proc/loadavg)
# Call model API
RESP=$(curl -s -X POST "$API_URL" -H "Content-Type: application/json" \
-d "$(printf '{"text":"%s"}' "$TEXT")")
LATENCY=$(echo "$RESP" | jq -r '.latency_ms')
SENTIMENT=$(echo "$RESP" | jq -r '.sentiment')
TS=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
export DB TS LOAD1 LATENCY SENTIMENT
init_and_insert
echo "OK: $TS load1=$LOAD1 latency_ms=$LATENCY sentiment=$SENTIMENT"
EOF
chmod +x collector.sh
Try it:
./collector.sh
./collector.sh
./collector.sh
Automate with cron (every minute):
( crontab -l 2>/dev/null; echo '* * * * * cd '"$HOME"'/ai-dashboard && . venv/bin/activate && ./collector.sh >> collector.log 2>&1' ) | crontab -
Tip: For fast iterations, you can also run it every 5 seconds in a tmux pane:
watch -n 5 ./collector.sh
4) Build a Streamlit dashboard
Charts latency, load, and aggregates of sentiment over time. Auto-refreshes.
cat > dashboard.py << 'EOF'
import sqlite3
import pandas as pd
import streamlit as st
from datetime import datetime, timedelta
DB = "metrics.db"
st.set_page_config(page_title="AI Dashboard", layout="wide")
st.title("AI Operations Dashboard")
@st.cache_data(ttl=5)
def load_data(limit=5000):
con = sqlite3.connect(DB)
df = pd.read_sql_query(
"SELECT ts, load1, latency_ms, sentiment FROM metrics ORDER BY ts DESC LIMIT ?",
con, params=(limit,)
)
con.close()
# To ascending chronological for charts:
df = df.iloc[::-1].reset_index(drop=True)
df["ts"] = pd.to_datetime(df["ts"])
return df
df = load_data()
if df.empty:
st.info("No data yet. Start uvicorn and run ./collector.sh or wait for cron.")
st.stop()
# KPI row
latest = df.iloc[-1]
col1, col2, col3 = st.columns(3)
col1.metric("Latency (ms)", f"{latest['latency_ms']}")
col2.metric("1-min Load", f"{latest['load1']:.2f}")
col3.metric("Sentiment", latest['sentiment'])
# Charts
st.subheader("Latency and System Load")
c1, c2 = st.columns(2)
c1.line_chart(df.set_index("ts")["latency_ms"])
c2.line_chart(df.set_index("ts")["load1"])
# Distribution
st.subheader("Sentiment Distribution")
st.bar_chart(df["sentiment"].value_counts())
# Time window filter
with st.expander("Options"):
window_mins = st.slider("Window (minutes)", 5, 240, 60)
cutoff = pd.Timestamp.utcnow() - pd.Timedelta(minutes=window_mins)
dfw = df[df["ts"] >= cutoff]
st.write(f"Rows in window: {len(dfw)}")
st.line_chart(dfw.set_index("ts")["latency_ms"])
EOF
Run the dashboard:
streamlit run dashboard.py
Remote server tip:
streamlit run dashboard.py --server.address 0.0.0.0 --server.port 8501
# Then browse http://SERVER_IP:8501 (open firewall if needed)
5) Real-world ways to extend this
Production model monitoring
- Replace the toy FastAPI with your real model service (or an external API).
- Track p50/p95 latency, error rate, token usage (for LLMs), and throughput by endpoint.
- Add drift signals (e.g., input length, vocabulary entropy) and highlight anomalies.
MLOps pipeline health
- Add pipeline steps (ETL durations, queue sizes, feature freshness).
- Surface DAG failures from Airflow or Argo with a simple
curl+jqcall in your collector.
Security and governance
- Log moderation outcomes and policy violation counts from your classifier.
- Provide audit trails in SQLite now; later migrate to Postgres.
Reliability upgrades
- Swap SQLite for Postgres, run via Docker:
- apt/dnf/zypper already installed Docker above; start a DB container and point your pipeline to it.
- Add alerting: small Bash rule that sends a webhook to Slack if latency > threshold:
if [ "$LATENCY" -gt 500 ]; then curl -X POST -H 'Content-type: application/json' \ --data "{\"text\":\"Latency alert: ${LATENCY}ms\"}" https://hooks.slack.com/services/XXX/YYY/ZZZ fi
Putting it all together (quick start)
Terminal 1:
. venv/bin/activate uvicorn model_api:app --reload --host 127.0.0.1 --port 8000Terminal 2:
. venv/bin/activate watch -n 5 ./collector.shTerminal 3:
. venv/bin/activate streamlit run dashboard.py
Open the dashboard, watch latency and load update live, and iterate.
Conclusion and next steps (CTA)
You now have a Linux-native AI dashboard that:
Collects model and system metrics with Bash
Persists data reliably
Visualizes KPIs for fast ops decisions
Next steps:
Swap the toy API with your real model or LLM endpoint.
Add more metrics (cost, token counts, accuracy samples).
Introduce thresholds and alerts.
Containerize components with Docker Compose for portability.
If you found this useful, fork this structure into your repo, add your model’s metrics, and share a screenshot of your dashboard. Questions or stuck on a distro quirk? Drop a comment with your apt/dnf/zypper details and I’ll help you debug.