Prometheus Config Generator
Build production-ready prometheus.yml with scrape targets, alerting rules, recording rules, and service discovery.
Prometheus Configuration
Global Configuration
Alertmanager
Rule Files
Scrape Jobs
Alerting Rules
Overview
The Prometheus Config Generator helps you build production-ready prometheus.yml configuration files with scrape targets, alerting rules, recording rules, remote write/read, and service discovery for Kubernetes, Docker, Consul, and cloud environments.
Prometheus uses a pull-based scraping model that actively connects to HTTP endpoints to collect time-series metrics. It supports multiple service discovery mechanisms (Kubernetes, Consul, EC2, Docker, DNS, file-based SD) and provides powerful relabeling for dynamic label manipulation. This generator produces syntactically correct prometheus.yml files with all components fully configured.
How It Works
1. Configure Global Settings: Set scrape_interval (how often to scrape targets), evaluation_interval (how often to evaluate rules), scrape_timeout, and external_labels for all scrape jobs.
2. Define Scrape Jobs: Create scrape_configs entries for each target type — static endpoints, Kubernetes pods/nodes/services, Consul services, EC2 instances, Docker containers, DNS records, or file-based service discovery.
3. Add Relabeling: Use relabel_configs to dynamically modify labels before scraping (filter targets, extract instance names, add metadata). Use metric_relabel_configs to modify labels on scraped metrics.
4. Configure Rules: Define alerting_rules for conditions that trigger alerts (sent to Alertmanager) and recording_rules for precomputing expensive PromQL expressions.
5. Enable Remote Storage: Configure remote_write to send samples to long-term storage (Thanos, Cortex, Mimir) and remote_read to query historical data from external backends.
Best Practices
- Set scrape_interval to 15s for most production workloads; use 5-10s only for critical high-resolution metrics.
- Always set evaluation_interval to a value greater than or equal to scrape_interval for reliable alerting.
- Use recording rules for frequently evaluated expensive PromQL expressions to reduce query-time load.
- Configure scrape_timeout to be less than scrape_interval to prevent overlapping scrapes.
- Use relabel_configs with keep/drop actions to filter targets and reduce cardinality.
- Set external_labels on all Prometheus instances in HA setups for proper deduplication in Thanos/Cortex.
- Use metric_relabel_configs to drop high-cardinality labels and reduce storage costs.
- Always set rule_files paths to valid locations accessible by the Prometheus process.
Common Mistakes
- Setting scrape_interval below 10s without justification, causing high storage and network overhead.
- Forgetting to configure rule_files, which prevents alerting and recording rules from being evaluated.
- Using relabel_configs and metric_relabel_configs interchangeably — relabel_configs apply before scrape, metric_relabel_configs after.
- Not setting scrape_timeout, causing Prometheus to use the default 10s which may be too short for slow endpoints.
- Configuring remote_write without proper queue_config, leading to data loss under high load.
- Missing external_labels in HA setups, causing deduplication failures in Thanos or Cortex.
Security Recommendations
- Enable TLS on the Prometheus web endpoint (web.config.file) for encrypted access to the UI and API.
- Use basic_auth or bearer_token on scrape endpoints that expose sensitive metrics.
- Restrict network access to port 9090 using firewalls or security groups.
- Run Prometheus as a non-root user with minimal filesystem permissions.
- Use relabel_configs with drop action to exclude sensitive targets from scraping.
- Avoid exposing Prometheus directly to the internet — use a reverse proxy with authentication.
Production Tips
- Deploy Prometheus with persistent storage (PVC in Kubernetes) to survive restarts without data loss.
- Use the Thanos sidecar pattern for long-term storage and global query view across multiple Prometheus instances.
- Monitor Prometheus itself using the prometheus_target_interval_length_seconds and up metrics.
- Configure Alertmanager in a cluster with --cluster.peers for high availability and deduplication.
- Use kube-prometheus-stack Helm chart for a production-ready Kubernetes monitoring setup with pre-built dashboards.
- Set retention flags (--storage.tsdb.retention.time, --storage.tsdb.retention.size) to manage disk usage.
- Use file_sd_configs for dynamic target management in non-Kubernetes environments.