Prometheus is an open-source monitoring and alerting toolkit that provides a robust time-series database, robust query language, efficient data collection, and more. One of the key aspects of Prometheus is its ability to scrape metrics from HTTP endpoints, making it highly versatile and useful for monitoring various types of systems and applications. The default HTTP scraping endpoint in Prometheus is on port 9090, which it uses to fetch data from configured targets.
In this comprehensive guide, we will explore the usage of http://prometheus.io:9090 or http://IP_ADDRESS:9090 to scrape metrics from Prometheus' targets, understand the target configuration process, and delve into the different scraping methods available.
Configuring Prometheus Targets
Before diving into the scraping process, it's crucial to understand how to configure targets in Prometheus. Targets are the systems or applications from which Prometheus scrapes metrics.
Targets can be configured using various methods, including static configuration files, using the service discovery, or even dynamically updating based on factors like labels or instances.
Static Configuration
One of the most basic ways to configure targets is by specifying them statically. This can be done by adding the targets in the Prometheus configuration file (usually located at /etc/prometheus/prometheus.yml). Here's an example:
scrape_configs:
- job_name: 'test'
static_configs:
- targets: ['example.com:80', '192.168.1.1:80']
Service Discovery
Service discovery is another powerful feature of Prometheus. It allows Prometheus to discover and monitor new targets automatically based on certain criteria. Examples of service discovery include Kubernetes service discovery and DNS-based service discovery.
Scraping Metrics from Targets
Once targets are properly configured, Prometheus begins scraping metrics from them at regular intervals. The default scraping interval is 15 seconds.
Prometheus supports multiple methods for scraping metrics, including the HTTP json format, plaintext format, and others. Let's explore these methods.
HTTP JSON
The HTTP JSON scraping method is one of the most common. It involves Prometheus sending an HTTP GET request to the target's endpoint, usually on port 9090, and expecting JSON-formatted data in response. This data is then parsed by Prometheus and stored in its time-series database.
Plaintext Instant Vectors
Plaintext instant vectors method is another way of scraping metrics. Instead of sending an HTTP GET request, Prometheus sends a line to the target's input, which then replies with an instant vector in the plaintext format.
Tip: Always ensure that the targets' endpoints are correctly set up and that they respond to Prometheus' requests with the expected data format.
With this understanding of how to configure targets and scrape metrics from them, you can now effectively use Prometheus to monitor your systems and applications. Whether you're scraping metrics from localhost:9090 or from distributed targets, the process remains the same.
Remember to continually validate your target configurations and monitor the logs for any errors or issues. Always keep your Prometheus server and its targets up-to-date with the latest security patches and performance improvements.
Happy monitoring!