Getting started with Prometheus and Grafana



Table of Contents

  1. Repository Execution
  2. Prometheus
  3. Grafana
  4. Configuration
  5. Data Collection Service
  6. Appendix - Introduction to OpenWeather and API Creation

Repository Execution

To execute this repository in a Linux environment, follow these steps:

  1. Make sure Python 3.8 and pip are installed on your system.
  2. Clone the repository to your local machine:
     git clone <REPOSITORY_URL> 
    
  3. Navigate to the cloned repository directory:
     cd <REPOSITORY_NAME> 
    
  4. Create and activate a virtual environment to isolate project dependencies:
     python3 -m venv venv
    source venv/bin/activate 
    
  5. Install the project dependencies:
     pip install -r requirements.txt 
    
  6. Create a symbolic link for the service file "temperaturas.service" in the "/home/systemd/system/" folder:
     ln -s temperaturas.service /home/systemd/system/temperaturas.service 
    
  7. Enable and start the service using systemctl:
     sudo systemctl enable temperaturas.service
    sudo systemctl start temperaturas.service 
    

Prometheus

To ensure that our temperature service is collected by Prometheus, we need to make some adjustments to the Prometheus configuration file, named "prometheus.yml". Below is how to add the necessary configuration:

 scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]
  - job_name: "temperatures"
    static_configs:
      - targets: ["127.0.0.1:9897"] 

Grafana

Grafana is a data visualization platform that integrates with Prometheus. It provides a graphical interface to explore and visualize the data collected by Prometheus.

Configuration

In the temperaturas.yml configuration file, you will find different sections that allow you to customize data collection and visualization:

Temperature

 Temperature:
  - City: Madrid
    Country: es
  - City: Paris
    Country: fr 

Configuration

Web

 Web:
  Period: 20
  Host: 127.0.0.1
  Port: 9897
  WRoute: /metrics
  APIKey: aaaaaaaaaaaaaaaa0000000000000000 

Logging

 Logging:
  File_name: 'app.log'
  Max_size: 11000000
  Backup_count: 3 

Data Collection Service

The data collection service retrieves information from the OpenWeather API for the cities specified in the configuration. The data is stored in log files located in the storage/logger/ folder.

Appendix - Introduction to OpenWeather and API Creation

OpenWeather is an online service that provides real-time weather data and forecasts globally. Through its API, developers can access a wide range of weather information.

  1. Sign up for OpenWeather: Visit the OpenWeather website ( https://openweathermap.org/ ) and sign up for a free account.
  2. Get your API key: After signing up, log in to your account and navigate to the API Keys section.
  3. Familiarize yourself with the documentation: Explore the API documentation at https://openweathermap.org/api.



Code: https://github.com/JavierAM01/Getting-Started-with-Prometheus-and-Grafana/

Contáctame

¿Tienes alguna pregunta? Estoy aquí para ayudarte. Envíame un mensaje y nos pondremos en contacto contigo lo antes posible. 

Teléfono
(412)287-5921
Email
javierabollado@gmail.com

Contáctenos

Share by: