Merge branch 'main' into aggiornamento-doc
Browse filesAlign aggiornamento-doc with latest main to resolve PR conflicts.
- Dockerfile +22 -0
- docker/nginx.conf +31 -0
- docker/scripts/start_space.sh +49 -0
- monitoring/README.md +5 -0
- monitoring/grafana/grafana.ini +20 -0
Dockerfile
CHANGED
|
@@ -14,6 +14,7 @@ RUN apt-get update && apt-get install -y \
|
|
| 14 |
nginx \
|
| 15 |
procps \
|
| 16 |
curl \
|
|
|
|
| 17 |
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
# Create a non-root user
|
|
@@ -22,6 +23,27 @@ RUN useradd -m -u 1000 user
|
|
| 22 |
# Set working directory
|
| 23 |
WORKDIR /app
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Copy requirements first for caching
|
| 26 |
COPY requirements.txt .
|
| 27 |
|
|
|
|
| 14 |
nginx \
|
| 15 |
procps \
|
| 16 |
curl \
|
| 17 |
+
prometheus \
|
| 18 |
&& rm -rf /var/lib/apt/lists/*
|
| 19 |
|
| 20 |
# Create a non-root user
|
|
|
|
| 23 |
# Set working directory
|
| 24 |
WORKDIR /app
|
| 25 |
|
| 26 |
+
# Grafana
|
| 27 |
+
RUN apt-get update && apt-get install -y wget apt-transport-https && \
|
| 28 |
+
wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key && \
|
| 29 |
+
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | tee /etc/apt/sources.list.d/grafana.list && \
|
| 30 |
+
apt-get update && \
|
| 31 |
+
apt-get install -y grafana && \
|
| 32 |
+
apt-get clean && \
|
| 33 |
+
rm -rf /var/lib/apt/lists/*
|
| 34 |
+
|
| 35 |
+
# Prometheus
|
| 36 |
+
RUN wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz && \
|
| 37 |
+
tar xvfz prometheus-*.tar.gz && \
|
| 38 |
+
mv prometheus-*/prometheus /usr/local/bin/ && \
|
| 39 |
+
mv prometheus-*/promtool /usr/local/bin/ && \
|
| 40 |
+
mkdir -p /etc/prometheus /var/lib/prometheus && \
|
| 41 |
+
rm -rf prometheus-*
|
| 42 |
+
|
| 43 |
+
COPY monitoring/grafana/provisioning /etc/grafana/provisioning
|
| 44 |
+
COPY monitoring/grafana/dashboards /var/lib/grafana/dashboards
|
| 45 |
+
COPY monitoring/prometheus/prometheus.yml /etc/prometheus/prometheus.yml
|
| 46 |
+
|
| 47 |
# Copy requirements first for caching
|
| 48 |
COPY requirements.txt .
|
| 49 |
|
docker/nginx.conf
CHANGED
|
@@ -29,6 +29,10 @@ http {
|
|
| 29 |
server 127.0.0.1:8000;
|
| 30 |
}
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
server {
|
| 33 |
listen 7860;
|
| 34 |
server_name localhost;
|
|
@@ -69,6 +73,33 @@ http {
|
|
| 69 |
proxy_set_header Host $host;
|
| 70 |
}
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
# Streamlit (Catch-all)
|
| 73 |
location / {
|
| 74 |
proxy_pass http://streamlit;
|
|
|
|
| 29 |
server 127.0.0.1:8000;
|
| 30 |
}
|
| 31 |
|
| 32 |
+
upstream prometheus {
|
| 33 |
+
server 127.0.0.1:9090;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
server {
|
| 37 |
listen 7860;
|
| 38 |
server_name localhost;
|
|
|
|
| 73 |
proxy_set_header Host $host;
|
| 74 |
}
|
| 75 |
|
| 76 |
+
# Grafana
|
| 77 |
+
location /grafana/ {
|
| 78 |
+
rewrite ^/grafana/(.*) /$1 break;
|
| 79 |
+
|
| 80 |
+
proxy_pass http://127.0.0.1:3000;
|
| 81 |
+
proxy_set_header Host $host;
|
| 82 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 83 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 84 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 85 |
+
|
| 86 |
+
proxy_set_header X-Forwarded-Host $host;
|
| 87 |
+
proxy_set_header X-Forwarded-Server $host;
|
| 88 |
+
|
| 89 |
+
proxy_http_version 1.1;
|
| 90 |
+
proxy_set_header Upgrade $http_upgrade;
|
| 91 |
+
proxy_set_header Connection "upgrade";
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
# Prometheus UI
|
| 95 |
+
location /prometheus/ {
|
| 96 |
+
proxy_pass http://prometheus/prometheus/;
|
| 97 |
+
proxy_set_header Host $host;
|
| 98 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 99 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 100 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
# Streamlit (Catch-all)
|
| 104 |
location / {
|
| 105 |
proxy_pass http://streamlit;
|
docker/scripts/start_space.sh
CHANGED
|
@@ -52,6 +52,55 @@ for i in {1..30}; do
|
|
| 52 |
sleep 2
|
| 53 |
done
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
echo "$(date) - Starting Nginx reverse proxy..."
|
| 56 |
if ! command -v nginx &> /dev/null; then
|
| 57 |
echo "$(date) - ERROR: nginx not found in PATH"
|
|
|
|
| 52 |
sleep 2
|
| 53 |
done
|
| 54 |
|
| 55 |
+
echo "$(date) - Configuring and starting Prometheus..."
|
| 56 |
+
# Create a config for the space
|
| 57 |
+
cat <<EOF > /tmp/prometheus.yml
|
| 58 |
+
global:
|
| 59 |
+
scrape_interval: 15s
|
| 60 |
+
evaluation_interval: 15s
|
| 61 |
+
|
| 62 |
+
scrape_configs:
|
| 63 |
+
- job_name: 'hopcroft-api'
|
| 64 |
+
metrics_path: '/metrics'
|
| 65 |
+
static_configs:
|
| 66 |
+
- targets: ['127.0.0.1:8000']
|
| 67 |
+
scrape_interval: 10s
|
| 68 |
+
|
| 69 |
+
- job_name: 'prometheus'
|
| 70 |
+
static_configs:
|
| 71 |
+
- targets: ['127.0.0.1:9090']
|
| 72 |
+
EOF
|
| 73 |
+
|
| 74 |
+
# Start Prometheus
|
| 75 |
+
# --web.external-url needs to match the path in Nginx
|
| 76 |
+
prometheus \
|
| 77 |
+
--config.file=/tmp/prometheus.yml \
|
| 78 |
+
--storage.tsdb.path=/tmp/prometheus_data \
|
| 79 |
+
--web.listen-address=0.0.0.0:9090 \
|
| 80 |
+
--web.external-url=/prometheus/ \
|
| 81 |
+
--web.route-prefix=/prometheus/ \
|
| 82 |
+
>> /tmp/prometheus.log 2>&1 &
|
| 83 |
+
|
| 84 |
+
# Start Grafana
|
| 85 |
+
echo "$(date) - Starting Grafana..."
|
| 86 |
+
grafana-server --homepath=/usr/share/grafana \
|
| 87 |
+
--config=/app/monitoring/grafana/grafana.ini \
|
| 88 |
+
cfg:default.paths.data=/tmp/grafana_data \
|
| 89 |
+
cfg:default.paths.logs=/tmp/grafana_logs \
|
| 90 |
+
cfg:default.paths.plugins=/usr/share/grafana/plugins \
|
| 91 |
+
>> /tmp/grafana.log 2>&1 &
|
| 92 |
+
|
| 93 |
+
# Wait for Grafana to start
|
| 94 |
+
echo "$(date) - Waiting for Grafana (20s)..."
|
| 95 |
+
for i in {1..20}; do
|
| 96 |
+
if curl -s http://127.0.0.1:3000/api/health > /dev/null; then
|
| 97 |
+
echo "$(date) - Grafana is UP!"
|
| 98 |
+
break
|
| 99 |
+
fi
|
| 100 |
+
sleep 1
|
| 101 |
+
done
|
| 102 |
+
|
| 103 |
+
|
| 104 |
echo "$(date) - Starting Nginx reverse proxy..."
|
| 105 |
if ! command -v nginx &> /dev/null; then
|
| 106 |
echo "$(date) - ERROR: nginx not found in PATH"
|
monitoring/README.md
CHANGED
|
@@ -49,6 +49,11 @@ We used Better Stack Uptime to monitor the availability of the production deploy
|
|
| 49 |
- https://dacrow13-hopcroft-skill-classification.hf.space/openapi.json
|
| 50 |
- https://dacrow13-hopcroft-skill-classification.hf.space/docs
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
**Checks and alerts**
|
| 53 |
- Monitors are configured to run from multiple locations.
|
| 54 |
- Email notifications are enabled for failures.
|
|
|
|
| 49 |
- https://dacrow13-hopcroft-skill-classification.hf.space/openapi.json
|
| 50 |
- https://dacrow13-hopcroft-skill-classification.hf.space/docs
|
| 51 |
|
| 52 |
+
## Prometheus on Hugging Face Space
|
| 53 |
+
|
| 54 |
+
Prometheus is also running directly on the Hugging Face Space and is accessible at:
|
| 55 |
+
- https://dacrow13-hopcroft-skill-classification.hf.space/prometheus/
|
| 56 |
+
|
| 57 |
**Checks and alerts**
|
| 58 |
- Monitors are configured to run from multiple locations.
|
| 59 |
- Email notifications are enabled for failures.
|
monitoring/grafana/grafana.ini
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[server]
|
| 2 |
+
protocol = http
|
| 3 |
+
http_port = 3000
|
| 4 |
+
domain = localhost
|
| 5 |
+
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
|
| 6 |
+
serve_from_sub_path = true
|
| 7 |
+
|
| 8 |
+
[auth.anonymous]
|
| 9 |
+
enabled = true
|
| 10 |
+
org_role = Viewer
|
| 11 |
+
|
| 12 |
+
[security]
|
| 13 |
+
allow_embedding = true
|
| 14 |
+
|
| 15 |
+
[users]
|
| 16 |
+
allow_sign_up = false
|
| 17 |
+
|
| 18 |
+
[log]
|
| 19 |
+
mode = console
|
| 20 |
+
level = info
|