This project demonstrates how to use Prometheus Python client library to create and expose metrics for monitoring purposes.
These instructions will help you set up and run the example script that generates random metrics and exposes them for Prometheus.
-
Python 3.x
-
Install required packages using:
pip install -r requirements.txt
-
Clone the repository:
git clone https://github.com/your_username/prometheus-metrics-example.git cd prometheus-metrics-example
-
Install dependencies:
pip install -r requirements.txt
-
Run the script:
python script.py
This will start an HTTP server on port 8000, allowing Prometheus to scrape metrics.
-
Access Prometheus UI:
Open your web browser and go to http://localhost:8000 to access the Prometheus UI and view the metrics.
The script.py
file contains a simple Python script that generates random metrics (request processing time and update count) and exposes them for Prometheus.
request_processing_seconds
: Measures the time spent processing requests.update_count
: Counts the number of updates.
- The Prometheus metrics are exposed on the
/metrics
endpoint. - Prometheus is configured to scrape metrics from
http://localhost:8000
in the example.
- Prometheus Python Client: Python client for Prometheus monitoring system.
This section describes an extension to the project that automates the backup process for a PostgreSQL database and sends notifications to multiple messaging platforms (Telegram, Slack, Discord) upon successful completion.
- Automated PostgreSQL database backup.
- Notifications to multiple platforms (Telegram, Slack, Discord) on backup success.
Follow these instructions to set up and run the database backup script with notifications.
-
Python 3.x
-
Install required packages using:
pip install -r requirements.txt
-
Open the
config.py
file and update the configuration parameters:# PostgreSQL Database Configuration DB_HOST = "your_db_host" DB_PORT = "your_db_port" DB_NAME = "your_db_name" DB_USER = "your_db_user" DB_PASSWORD = "your_db_password" # Telegram Configuration TELEGRAM_BOT_TOKEN = "your_telegram_bot_token" TELEGRAM_CHAT_ID = "your_telegram_chat_id" # Slack Configuration SLACK_TOKEN = "your_slack_token" SLACK_CHANNEL = "#your_slack_channel" # Discord Configuration DISCORD_WEBHOOK_URL = "your_discord_webhook_url"
-
Save the
config.py
file.
-
Clone the repository:
git clone https://github.com/your_username/database-backup-project.git cd database-backup-project
-
Install dependencies:
pip install -r requirements.txt
-
Run the backup script:
python backup_script.py
This will perform a database backup and send notifications on success.
Notifications are sent to the configured channels/platforms upon successful completion of the database backup.
-
Telegram:
- A notification will be sent to the specified Telegram chat.
-
Slack:
- A notification will be posted to the specified Slack channel.
-
Discord:
- A notification will be sent to the configured Discord webhook.
Feel free to contribute to this project. Open issues for suggestions or bug reports.
This project is licensed under the MIT License - see the LICENSE.md file for details.