Spaces:
Sleeping
Sleeping
DaCrow13
commited on
Commit
·
b4e6edc
1
Parent(s):
888d4a9
Configura Prometheus per girare su Hugging Face Space
Browse files- Dockerfile +1 -0
- monitoring/README.md +5 -0
- nginx.conf +13 -0
- scripts/start_space.sh +29 -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
|
|
|
|
| 14 |
nginx \
|
| 15 |
procps \
|
| 16 |
curl \
|
| 17 |
+
prometheus \
|
| 18 |
&& rm -rf /var/lib/apt/lists/*
|
| 19 |
|
| 20 |
# Create a non-root user
|
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.
|
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,15 @@ 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 |
+
# Prometheus UI
|
| 77 |
+
location /prometheus/ {
|
| 78 |
+
proxy_pass http://prometheus/prometheus/;
|
| 79 |
+
proxy_set_header Host $host;
|
| 80 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 81 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 82 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
# Streamlit (Catch-all)
|
| 86 |
location / {
|
| 87 |
proxy_pass http://streamlit;
|
scripts/start_space.sh
CHANGED
|
@@ -52,6 +52,35 @@ 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 |
echo "$(date) - Starting Nginx reverse proxy..."
|
| 85 |
if ! command -v nginx &> /dev/null; then
|
| 86 |
echo "$(date) - ERROR: nginx not found in PATH"
|