Python http metrics monitoring
script
Add datasource http://prometheus:9090
chmod +x mon.shvi mon.sh#!/bin/bash
# Set working directory
WORKDIR="/root"
PROM_FILE="$WORKDIR/prometheus.yml"
# Create Prometheus config file
cat > "$PROM_FILE" <<EOF
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['node-exporter:9100']
- job_name: 'shopify_orders_api'
metrics_path: /metrics
scheme: https
static_configs:
- targets: ['shopify-orders-api-latest.onrender.com']
tls_config:
insecure_skip_verify: true # Optional: skip SSL verification if needed
EOF
# Create Docker network if it doesn't exist
docker network inspect monitoring-net >/dev/null 2>&1 || \
docker network create monitoring-net
# Remove existing containers if they exist
docker rm -f prometheus grafana >/dev/null 2>&1
# Run Prometheus container
docker run -d \
--name prometheus \
--network monitoring-net \
-p 9090:9090 \
-v "$PROM_FILE":/etc/prometheus/prometheus.yml \
prom/prometheus
# Run Grafana container
docker run -d \
--name grafana \
--network monitoring-net \
-p 3000:3000 \
grafana/grafana
echo "✅ Prometheus running at: http://localhost:9090"
echo "✅ Grafana running at: http://localhost:3000 (login: admin / admin)"
lab
prometheus.yml
Default credentials: admin / admin
To monitor production SLAs/SLOs and key metrics for your Shopify Orders API in Prometheus + Grafana, you already have some excellent custom metrics exposed. Below is a structured plan with Grafana chart suggestions and PromQL queries to track performance, availability, and reliability.
🔧 Metrics Breakdown & Key Monitoring Goals
🔹 1. Availability (SLA/SLO)
Measure if order fetch was successful, how often, and when.
Chart: Shopify Orders API - Success Count
📈 Type: Time Series or Stat Panel 📅 Interval:
[1h],[24h]for daily trendChart: Last Success Timestamp
📈 Type: Gauge / Stat panel 🧠 Format it as "Time" in Grafana
🔹 2. Latency (SLO)
Monitor duration to fetch orders (response time).
Chart: Orders Fetch Duration Histogram
📊 Show 90th percentile latency (can use 50, 95 as well)
Chart: Orders Fetch Duration Count
Useful to monitor the volume of fetches for correlation
🔹 3. Returned Orders Count
Number of orders returned per fetch – helps gauge traffic.
Chart: Orders Returned per Fetch
Chart: Orders Returned over Time
🔹 4. Revenue Monitoring (INR)
Track revenue processed through the API.
Chart: Revenue (INR) Increase Over Time
Chart: Total Revenue So Far
🔹 5. GC and Memory (Python Metrics)
Keep an eye on Python performance overhead.
Chart: Resident Memory Usage
Chart: GC Collections Count
Chart: Uncollectable Objects (Alert if > 0)
✅ SLO Alerts (Optional)
You can define SLOs like:
Latency < 1s for 95% of requests
Set this in Grafana alerting rules or Alertmanager.
Order fetch failed for more than 10 minutes
📊 Grafana Dashboard Suggestions
Orders Fetch Success Count
Stat / Bar
increase(shopify_orders_fetch_total{status="success"}[1h])
Last Successful Fetch Timestamp
Stat / Gauge
shopify_orders_last_success_timestamp
90th Percentile Duration
Line
histogram_quantile(0.90, rate(shopify_orders_fetch_duration_seconds_bucket[5m]))
Orders Returned per Fetch
Stat
shopify_orders_returned_total
Revenue Generated (Last 1h)
Line
increase(shopify_orders_revenue_inr_total[1h])
Current Memory Usage
Gauge
process_resident_memory_bytes
GC Collections Rate
Line
rate(python_gc_collections_total[5m])
If you’d like, I can generate a ready-to-import Grafana dashboard JSON based on the above. Want that?
Last updated