Getting started with Prometheus and Grafana

Table of Contents
- Repository Execution
- Prometheus
- Grafana
- Configuration
- Data Collection Service
- Appendix - Introduction to OpenWeather and API Creation
Repository Execution
To execute this repository in a Linux environment, follow these steps:
- Make sure Python 3.8 and pip are installed on your system.
- Clone the repository to your local machine:
git clone <REPOSITORY_URL>
- Navigate to the cloned repository directory:
cd <REPOSITORY_NAME>
- Create and activate a virtual environment to isolate project dependencies:
python3 -m venv venv source venv/bin/activate
- Install the project dependencies:
pip install -r requirements.txt
- 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
- 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.
- Sign up for OpenWeather: Visit the OpenWeather website ( https://openweathermap.org/ ) and sign up for a free account.
- Get your API key: After signing up, log in to your account and navigate to the API Keys section.
- 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.