How to add additional scrape config to Prometheus
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Adding additional scrape configurations to Prometheus involves augmenting the prometheus.yml configuration file to specify new targets and settings from which Prometheus will collect metrics. This article provides a detailed guide on how to accomplish this task, including technical explanations and practical examples.
Understanding Prometheus Scrape Configurations
Prometheus uses scrape configurations to define where and how it collects metrics from various services. Each job in the scrape configuration specifies a set of endpoints and parameters for querying metrics.
Key Components of a Scrape Configuration
- job_name: A human-readable name for identifying the metrics of a particular job or service.
- static_configs: Contains the list of targets, usually consisting of IP addresses or DNS names combined with ports where Prometheus can collect metrics.
- metrics_path: Defines the HTTP path that Prometheus should scrape (default is
/metrics). - relabel_configs: Provides dynamic labeling for scraped metrics, allowing customization of labels.
Adding Additional Scrape Configurations
To add more scrape configurations, follow these steps:
- Locate the Prometheus configuration file: The
prometheus.ymlfile is usually found in the Prometheus configuration directory. Its location can vary based on your system setup. - Edit the Configuration File: Open
prometheus.ymlusing your preferred text editor. Each additional scrape configuration is added as a new entry under thescrape_configssection. - Define the New Scrape Job: Below is an example of how to structure an additional scrape job:
- job_name: 'example-scrape-job'
- targets: ['hostname1:9100', 'hostname2:9200']
- source_labels: [address]
job_nameis set toexample-scrape-job.- Two targets are defined under
static_configswith their respective paths. - The
metrics_pathis customized to/custom-metrics. - A
relabel_configssection is included to modify label information for clearer identification.
- job_name: 'microservice'
- targets: ['microservice:9300']
scrape_interval: Determines the frequency with which Prometheus queries metrics for a job. Default is 15s.scrape_timeout: Sets the timeout before a scrape is considered failed.basic_authandbearer_token: Enable secure access to targets using authentication.- Check Prometheus Logs: The Prometheus logs can reveal errors related to configuration changes.
- Test Endpoint Access: Ensure Prometheus can reach the endpoints specified in your targets.
- Review Service Status: Verify that the service exposing metrics is up and running properly.
Related reading
- How to add basic authentication for Tensorflow serving
- How to add flag to Kubernetes controller manager
- How to add multiple keys for elastic beanstalk instance?
- How to add users to Docker container?
- How to analyze disk usage of a Docker container
- How to analyze logs in a distributed system?
- How to assign a static IP to a pod using Kubernetes on deployment
- How to assign AWS IAM Role to Service Account with Terraform?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.