This script collects and exports real-time exchange rates for various currency pairs to Prometheus. Using the AwesomeAPI, it retrieves the latest exchange rates and makes them available for monitoring in Prometheus, which can then be visualized in Grafana.
-
Exchange Rate Collection: Fetches real-time exchange rates from the AwesomeAPI for a configurable list of currency pairs.
-
Prometheus Integration: Provides metrics in a format compatible with Prometheus scraping.
-
Flexible Configuration: Easily configurable to include the currency pairs you are interested in via a
config.yaml
file. -
Efficient Performance: Designed to handle multiple currency pairs with minimal resource usage.
-
API Configuration:
Update the
config.yaml
file with the currency pairs you want to monitor. The format used isBASE_CURRENCY-TARGET_CURRENCY
, where:- BASE_CURRENCY is the currency you are converting from.
- TARGET_CURRENCY is the currency you are converting to.
Each currency pair should be separated by a hyphen. For example, to get the exchange rate from US Dollars (USD) to Brazilian Reais (BRL), you would use
USD-BRL
.Example
config.yaml
:currencies: - USD-BRL - EUR-BRL - GBP-BRL
In this example:
-
USD-BRL
retrieves the exchange rate from US Dollars to Brazilian Reais. -
USD-BRL
retrieves the exchange rate from US Dollars to Brazilian Reais. -
USD-BRL
retrieves the exchange rate from US Dollars to Brazilian Reais.
-
Exporter Port (Optional):
Set the port for the Prometheus exporter in the script:
PORT = 7575
-
Install Dependencies:
Install the required Python packages:
pip install requests prometheus_client pyyaml
-
Run the Script:
Launch the script to start the Prometheus exporter:
python currency_exporter.py
-
Access Metrics:
http://localhost:7575/metrics
-
Currency Pairs: Ensure that the currency pairs in
config.yaml
follow the formatBASE_CURRENCY-TARGET_CURRENCY
, where each currency is represented by its standard ISO code. For example,USD-BRL
is for US Dollars to Brazilian Reais. -
API Limitations: Be aware of any rate limits or restrictions imposed by the AwesomeAPI.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.