PowerFlex Python Monitoring library (powerflex-monitoring)
Tools to assist in monitoring a Python service.
Installation
You can install from PyPi directly:
pip install powerflex-monitoring
Demo
See ./demo.py for a usage example.
Also see the type hints and the docstrings.
To run the demo:
- Install docker and docker-compose
- Run
make up - Run
docker container lsto see the open ports and try hitting the monitoring URLs listed below
$ docker logs powerflex_monitoring_main
[INFO] Added route at port 8000: /monitoring/health/
[INFO] Added route at port 8000: /monitoring/ready/
[INFO] Added route at port 8000: /monitoring/metrics/
[INFO] 🚀 Starting monitoring server at port 8000
[INFO] Connected to NATS_ADDRESS nats:4222
[INFO] Configuration for NATS health check
[INFO] Service has been marked as ready. Cause: Service is initialized
Feature: monitoring server
from powerflex_monitoring.monitoring import MonitoringServer
- Readiness and healthiness endpoints are at
/monitoring/ready/and/monitoring/health/. These are useful in environments like Kubernetes: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ - Prometheus metrics are at
/monitoring/metrics/. Use theprometheus_clientlibrary to expose more metrics.
Feature: NATS health checker
from powerflex_monitoring.nats_health_check import NatsHealthChecker
This class checks if NATS is healthy and marks the service as unhealthy if NATS is ever down for a certain period of time.
Feature: Redis health checker
This feature checks if Redis service is healthy and marks the service as unhealthy if Redis is ever down for a certain period of time. How to use it?
- Import the
RedisHealthChecker
from powerflex_monitoring.redis_health_check import RedisHealthChecker
- Instantiate a RedisHealtChecher object with the Redis connection that you want to ckeck and the monitoring server to which you will inform the health status
redis_health_checker = RedisHealthChecker(redis_conn, monitoring_server)
- Run the async function
periodically_check_redis_healthlike this:
await redis_health_checker.periodically_check_redis_health()
Feature: wait for service to be ready
This is useful when starting your integration tests. If you use the readiness check, then you can delay an action until your service is ready.
python -m powerflex_monitoring.wait_for_service_ready \
--ready-check-url http://localhost:8000/monitoring/ready/
Make sure this library is installed in your virtualenv or globally, otherwise you won't be able to run this script.
See our Makefile for an example of using this script to wait before running integration tests.
Test results
This library is unit tested with 100% coverage in Python versions 3.8 to 3.11 and in pypy 3.9.
Developing
- Install the dependencies with
make setup. This will usepipenvto manage a virtualenv. - Run the commands in the
Makefileto test your code. Runpipenv shellbefore running the commands or runpipenv run make ...to run the Makefile commands withpipenv.
make commitreadymake test-unitormake test-unit-all-python-versionsmake format-fixmake lintmake type-check-strict
- Please keep the unit test coverage at 100%.
Releasing to PyPi.org
- Make sure all code checks have passed with
make commitready. - Make sure you commit all code you wish to release with
git commit. - Set the version in
./src/powerflex_monitoring/VERSIONPlease attempt to follow semantic versioning. - Run
make bump-versionto commit the change to theVERSIONfile. - Run
make releaseto upload the package to pypi.org and to push a new git tag
Metadata
Release files for powerflex-monitoring 1.8.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| powerflex_monitoring-1.8.2.tar.gz | 12.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| powerflex_monitoring-1.8.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.7 kB
Release files / powerflex_monitoring-1.8.2.tar.gz
| Download URL | powerflex_monitoring-1.8.2.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a16595d80b34b527010929f844fc38bc896fcbc9443a9dec8f1263a7824c901d
|
|
BLAKE2b-256 checksum How to use checksums |
ce811853b8a69b04472daa36c98692c72c78575861bad3391aaebe3e9fa20432
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.17
|
Release files / powerflex_monitoring-1.8.2-py3-none-any.whl
| Download URL | powerflex_monitoring-1.8.2-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af0cc71cd70bbd1b62fa7270a2f6d51634dfb624c0d3604c3afd9302087deccb
|
|
BLAKE2b-256 checksum How to use checksums |
588a4eab455bbab40e26a33bd960f1172a2cd2980fbdd16de7a04133b20c37d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.17
|