Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Setting Up Prometheus

1. Introduction

Prometheus is an open-source monitoring and alerting toolkit designed for reliability and scalability. It collects metrics from configured targets at specified intervals, evaluates rule expressions, and can trigger alerts if certain conditions are met. This tutorial will guide you through the setup process of Prometheus on your system.

2. Prerequisites

Before you begin, ensure you have the following:

  • A Linux or macOS system.
  • Access to a terminal (command line interface).
  • Basic knowledge of using command line commands.

3. Downloading Prometheus

To get started, you need to download the latest version of Prometheus. You can do this by visiting the official Prometheus download page or using the following command in your terminal:

Using wget:

wget https://github.com/prometheus/prometheus/releases/latest/download/prometheus-.linux-amd64.tar.gz

Replace <version> with the latest version number. Once downloaded, extract the files:

tar xvfz prometheus-.linux-amd64.tar.gz

4. Configuring Prometheus

After extracting, navigate to the Prometheus directory. You will find a configuration file named prometheus.yml. This file is essential as it defines how Prometheus scrapes metrics and configures alerting rules.

Open prometheus.yml in your preferred text editor:

nano prometheus.yml

Here’s a basic configuration example:

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
                

This configuration sets a global scrape interval of 15 seconds and defines a job to scrape metrics from Prometheus itself running on localhost.

5. Running Prometheus

To start Prometheus, run the following command in the terminal, ensuring you are in the Prometheus directory:

./prometheus --config.file=prometheus.yml

If everything is set up correctly, Prometheus will start running, and you should see output indicating that it is listening on localhost:9090.

6. Accessing the Web Interface

Once Prometheus is running, access the web interface by opening a web browser and navigating to:

http://localhost:9090

Here, you can explore the available metrics, configure alerts, and visualize your data.

7. Conclusion

Congratulations! You have successfully set up Prometheus on your system. You can now begin to scrape metrics and set up alerts according to your monitoring needs. For more advanced configurations and integrations, refer to the official Prometheus documentation.