Prometheus
scrape config
monitoring
DevOps
tutorial

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.

Practice system design

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

  1. job_name: A human-readable name for identifying the metrics of a particular job or service.
  2. static_configs: Contains the list of targets, usually consisting of IP addresses or DNS names combined with ports where Prometheus can collect metrics.
  3. metrics_path: Defines the HTTP path that Prometheus should scrape (default is /metrics).
  4. relabel_configs: Provides dynamic labeling for scraped metrics, allowing customization of labels.

Adding Additional Scrape Configurations

To add more scrape configurations, follow these steps:

  1. Locate the Prometheus configuration file: The prometheus.yml file is usually found in the Prometheus configuration directory. Its location can vary based on your system setup.
  2. Edit the Configuration File: Open prometheus.yml using your preferred text editor. Each additional scrape configuration is added as a new entry under the scrape_configs section.
  3. 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_name is set to example-scrape-job.
    • Two targets are defined under static_configs with their respective paths.
    • The metrics_path is customized to /custom-metrics.
    • A relabel_configs section 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_auth and bearer_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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.