This document describes the monitoring setup for ImgForge using Prometheus and Grafana.
The monitoring stack includes:
- Prometheus: Metrics collection and storage
- Grafana: Metrics visualization and dashboarding
- ImgForge: Application with built-in
/metricsendpoint
docker-compose up -dThis will start three services:
imgforgeon port 3000prometheuson port 9090grafanaon port 3001
- ImgForge: http://localhost:3000
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3001
- Username:
admin - Password:
admin
- Username:
The ImgForge dashboard is automatically provisioned and includes the following panels:
- HTTP Status Codes: Rate of responses by status code
- Total HTTP Requests: Total number of HTTP requests processed
- HTTP Request Duration: p50, p95, and p99 latencies by endpoint
- Image Processing Duration: Processing time percentiles by output format
- Cache Hit Rate: Hit rate percentage by cache type
- Cache Hits vs Misses: Rate of cache hits and misses
- Processed Images by Format: Rate of processed images grouped by output format
- Total Processed Images: Counter of all processed images
- libvips Memory Usage: Current and peak memory usage
- libvips Active Allocations: Number of active memory allocations
- Source Image Fetch Duration: p50, p95, and p99 latencies for fetching source images
- Source Images Fetched by Status: Rate of fetches by success/error status
ImgForge exposes the following Prometheus metrics at /metrics:
| Metric | Type | Labels | Description |
|---|---|---|---|
http_requests_duration_seconds |
Histogram | method, path |
HTTP request duration |
image_processing_duration_seconds |
Histogram | format |
Image processing duration |
image_operation_semaphore_wait_duration_seconds |
Histogram | operation |
Worker-permit wait duration |
image_operation_blocking_queue_duration_seconds |
Histogram | operation |
Blocking-pool queue duration |
image_operation_execution_duration_seconds |
Histogram | operation |
Blocking execution duration |
image_operation_concurrency_limit |
Gauge | - | Configured operation limit |
image_operations_active |
Gauge | operation |
Currently executing operations |
image_operations_waiting |
Gauge | operation |
Operations waiting to execute |
source_image_fetch_duration_seconds |
Histogram | - | Source image fetch duration |
processed_images_total |
Counter | format |
Total processed images |
source_images_fetched_total |
Counter | status |
Total source images fetched |
cache_hits_total |
Counter | cache_type |
Total cache hits |
cache_misses_total |
Counter | cache_type |
Total cache misses |
status_codes_total |
Counter | status |
Total HTTP response codes |
vips_tracked_mem_bytes |
Gauge | - | Current libvips memory usage |
vips_tracked_mem_highwater_bytes |
Gauge | - | Peak libvips memory usage |
vips_tracked_allocs |
Gauge | - | Active libvips allocations |
The Prometheus configuration is in prometheus.yml:
- Scrape interval: 15 seconds
- ImgForge scrape interval: 10 seconds
- Target:
imgforge:9000/metrics
Grafana is configured via:
grafana-datasources.yml: Configures Prometheus as the default datasourcegrafana-dashboards/dashboard-provisioning.yml: Enables dashboard auto-provisioninggrafana-dashboards/imgforge-dashboard.json: The main ImgForge dashboard
You can customize the dashboard in two ways:
-
Through the Grafana UI:
- Log into Grafana
- Navigate to the "ImgForge Monitoring Dashboard"
- Click the settings icon and select "Edit"
- Make your changes and save
-
Editing the JSON file:
- Edit
grafana-dashboards/imgforge-dashboard.json - Restart the Grafana container:
docker-compose restart grafana
- Edit
To add new metrics to ImgForge:
- Define the metric in
src/monitoring.rs - Register it in the
register_metrics()function - Update the Grafana dashboard JSON to visualize the new metric
- Check that ImgForge is running:
curl http://localhost:9000/metrics - Verify Prometheus can reach ImgForge: Check Prometheus targets at http://localhost:9090/targets
- Check Prometheus logs:
docker-compose logs prometheus
- Verify the datasource is configured: Go to Configuration > Data Sources in Grafana
- Check Grafana logs:
docker-compose logs grafana - Manually import the dashboard: Copy the content of
imgforge-dashboard.jsonand import via Grafana UI
The Docker Compose setup includes persistent volumes for both Prometheus and Grafana:
prometheus-data: Stores Prometheus time-series datagrafana-data: Stores Grafana configuration and dashboards
To reset all data:
docker-compose down -vFor production deployments, consider:
-
Security:
- Change the default Grafana admin password
- Add authentication to Prometheus
- Use HTTPS for all services
-
Persistence:
- Use external volumes or cloud storage for data persistence
- Configure retention policies for Prometheus
-
Scalability:
- Consider using Thanos or Cortex for long-term Prometheus storage
- Set up alerting rules in Prometheus
- Configure alert notifications in Grafana
-
Networking:
- Restrict access to monitoring services
- Use a reverse proxy for external access