# Prometheus Data Ingestion - Summary ## What Was Created A complete Prometheus data ingestion solution consisting of: ### 1. **Standalone Go Binary** (`prometheus-pusher`) - **Size**: ~12MB standalone executable - **Language**: Go 1.21 - **Dependencies**: Prometheus client library - **Function**: Generates and pushes metrics to Pushgateway every 15 seconds ### 2. **Pushgateway Deployment** - **Type**: Kubernetes deployment in `monitoring` namespace - **Image**: `prom/pushgateway:v1.10.0` - **Port**: 9091 - **Function**: Receives metrics from the Go binary and exposes them for Prometheus to scrape ### 3. **Prometheus Configuration** - Updated `/home/paul/git/conf/f3s/prometheus/additional-scrape-configs.yaml` - Added Pushgateway as a scrape target - Prometheus automatically scrapes Pushgateway every 15-30 seconds ## Data Format The binary pushes metrics in **Prometheus text format** via HTTP POST to the Pushgateway. This is the standard format for all Prometheus metrics. Example: ``` # HELP app_requests_total Total number of requests processed # TYPE app_requests_total counter app_requests_total{instance="example-app",job="example_metrics_pusher"} 42 ``` ## Metric Types Demonstrated ### 1. **Counter**: `app_requests_total` - Monotonically increasing value - Best for: Total requests, errors, events ### 2. **Gauge**: `app_active_connections`, `app_temperature_celsius` - Value that can increase or decrease - Best for: Current state (connections, temperature, memory) ### 3. **Histogram**: `app_request_duration_seconds` - Distribution of values in buckets - Best for: Latency, response times, sizes - Automatically provides percentile calculations ### 4. **Counter with Labels**: `app_jobs_processed_total` - Counter with multiple dimensions - Labels: `job_type` (email, report, backup), `status` (success, failed) - Best for: Categorized counting ## Why This Format? The Prometheus text format was chosen because: 1. **Standard**: Universal format understood by all Prometheus components 2. **Human-readable**: Easy to debug and understand 3. **Efficient**: Compact representation 4. **Type-safe**: Explicit metric types prevent errors 5. **Labeled**: Supports multi-dimensional data ## How to Use ### Quick Start ```bash cd /home/paul/git/conf/f3s/prometheus-pusher ./run.sh ``` ### Manual Operation ```bash # 1. Port-forward Pushgateway kubectl port-forward -n monitoring svc/pushgateway 9091:9091 # 2. Run binary (in another terminal) ./prometheus-pusher ``` ### Query Metrics ```bash # Port-forward Prometheus kubectl port-forward -n monitoring svc/prometheus-kube-prometheus-prometheus 9090:9090 # Open http://localhost:9090 and query: app_requests_total app_active_connections rate(app_requests_total[5m]) histogram_quantile(0.95, rate(app_request_duration_seconds_bucket[5m])) ``` ## Example Data See `example-metrics.txt` for a complete example of all metric types with sample values. ## Testing Results ✅ **Binary compilation**: Success (12MB executable) ✅ **Pushgateway deployment**: Running in monitoring namespace ✅ **Metrics push**: Successfully pushing every 15 seconds ✅ **Prometheus scraping**: Confirmed metrics visible in Prometheus ✅ **Query testing**: All metric types queryable ### Sample Query Results ```json { "status": "success", "data": { "result": [{ "metric": { "__name__": "app_requests_total", "instance": "example-app", "job": "example_metrics_pusher" }, "value": [1767121623.654, "10"] }] } } ``` ## Architecture ``` ┌──────────────────────┐ │ prometheus-pusher │ Standalone Go binary │ (your machine) │ - Generates metrics └──────────┬───────────┘ - Pushes via HTTP POST │ │ HTTP POST │ :9091/metrics/job/ ▼ ┌──────────────────────┐ │ Pushgateway │ Kubernetes pod │ (monitoring ns) │ - Receives pushed metrics └──────────┬───────────┘ - Exposes /metrics endpoint │ │ HTTP GET (scrape) │ Every 15-30s ▼ ┌──────────────────────┐ │ Prometheus │ Kubernetes pod │ (monitoring ns) │ - Scrapes Pushgateway └──────────┬───────────┘ - Stores time-series data │ │ HTTP API │ PromQL queries ▼ ┌──────────────────────┐ │ Grafana / Users │ Visualization & Alerts │ │ - Query metrics └──────────────────────┘ - Create dashboards ``` ## Files Created ``` /home/paul/git/conf/f3s/prometheus-pusher/ ├── main.go # Go source code ├── go.mod, go.sum # Go dependencies ├── prometheus-pusher # Compiled binary (12MB) ├── run.sh # Helper script ├── README.md # Project overview ├── USAGE.md # Detailed usage guide ├── SUMMARY.md # This file ├── example-metrics.txt # Example metrics format └── Dockerfile # Docker build (optional) /home/paul/git/conf/f3s/pushgateway/ └── helm-chart/ # Kubernetes deployment ├── Chart.yaml # Helm chart metadata ├── values.yaml # Configuration values ├── README.md # Chart documentation └── templates/ ├── deployment.yaml # Pushgateway pod └── service.yaml # Pushgateway service /home/paul/git/conf/f3s/prometheus/ └── additional-scrape-configs.yaml # Prometheus config (updated) ``` ## Next Steps ### For Production Use 1. **Modify metrics** in `main.go` to track your actual application data 2. **Adjust push interval** (currently 15 seconds) 3. **Add authentication** if Pushgateway is exposed externally 4. **Set up Grafana dashboards** to visualize the metrics 5. **Configure alerts** in Prometheus for critical thresholds ### For Learning 1. Experiment with different metric types 2. Try querying with different PromQL expressions 3. Create Grafana dashboards 4. Set up alerting rules 5. Compare Pushgateway approach vs. direct scraping ## Key Concepts - **Push vs. Pull**: Pushgateway allows pushing metrics (vs. Prometheus scraping) - **Labels**: Enable multi-dimensional metrics - **Metric Types**: Different types for different use cases - **Aggregation**: Histograms automatically calculate percentiles - **Time Series**: Prometheus stores timestamped values ## References - Prometheus text format: https://prometheus.io/docs/instrumenting/exposition_formats/ - Prometheus client library: https://github.com/prometheus/client_golang - Pushgateway: https://github.com/prometheus/pushgateway - Metric types: https://prometheus.io/docs/concepts/metric_types/