# PowerFlex Python Monitoring library (powerflex-monitoring)
<!-- Badges (images) related to Python package information -->
[   ](https://pypi.org/project/powerflex-monitoring/)
Tools to assist in monitoring a Python service.
# Installation
You can install from [PyPi](https://pypi.org/project/powerflex-monitoring/) directly:
```shellscript
pip install powerflex-monitoring
```
## Demo
See [`./demo.py`](./demo.py) for a usage example.
Also see the type hints and the docstrings.
To run the demo:
1. Install docker and docker-compose
1. Run `make up`
1. Run `docker container ls` to 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 the [`prometheus_client`](https://pypi.org/project/prometheus-client/) library 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?
1. Import the `RedisHealthChecker`
```
from powerflex_monitoring.redis_health_check import RedisHealthChecker
```
2. 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)
```
3. Run the async function `periodically_check_redis_health` like 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
1. Install the dependencies with `make setup`.
This will use `pipenv` to manage a virtualenv.
1. Run the commands in the [`Makefile`](./Makefile) to test your code.
Run `pipenv shell` before running the commands or run `pipenv run make ...` to run the Makefile commands with `pipenv`.
- `make commitready`
- `make test-unit` or `make test-unit-all-python-versions`
- `make format-fix`
- `make lint`
- `make type-check-strict`
1. Please keep the unit test coverage at 100%.
# Releasing to [PyPi.org](https://pypi.org/project/powerflex-monitoring/)
1. Make sure all code checks have passed with `make commitready`.
1. Make sure you commit all code you wish to release with `git commit`.
1. Set the version in [`./src/powerflex_monitoring/VERSION`](./src/powerflex_monitoring/VERSION)
Please attempt to follow [semantic versioning](https://semver.org/).
1. Run `make bump-version` to commit the change to the `VERSION` file.
1. Run `make release` to upload the package to pypi.org and to push a new git tag
Raw data
{
"_id": null,
"home_page": null,
"name": "powerflex-monitoring",
"maintainer": "Powerflex",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "monitoring, powerflex, python",
"author": "Powerflex",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/7c/13/019f1aa39a7bd5f9d11ae0a8277e1d10ca5a8ade31ddbf3e28e193fd76db/powerflex_monitoring-1.8.1.tar.gz",
"platform": null,
"description": "# PowerFlex Python Monitoring library (powerflex-monitoring)\n\n<!-- Badges (images) related to Python package information -->\n[   ](https://pypi.org/project/powerflex-monitoring/)\n\nTools to assist in monitoring a Python service.\n\n# Installation\n\nYou can install from [PyPi](https://pypi.org/project/powerflex-monitoring/) directly:\n\n```shellscript\npip install powerflex-monitoring\n```\n\n## Demo\n\nSee [`./demo.py`](./demo.py) for a usage example.\nAlso see the type hints and the docstrings.\n\nTo run the demo:\n\n1. Install docker and docker-compose\n1. Run `make up`\n1. Run `docker container ls` to see the open ports and try hitting the monitoring URLs listed below\n\n```\n$ docker logs powerflex_monitoring_main\n[INFO] Added route at port 8000: /monitoring/health/\n[INFO] Added route at port 8000: /monitoring/ready/\n[INFO] Added route at port 8000: /monitoring/metrics/\n[INFO] \ud83d\ude80 Starting monitoring server at port 8000\n[INFO] Connected to NATS_ADDRESS nats:4222\n[INFO] Configuration for NATS health check\n[INFO] Service has been marked as ready. Cause: Service is initialized\n```\n\n## Feature: monitoring server\n\n```\nfrom powerflex_monitoring.monitoring import MonitoringServer\n```\n\n- Readiness and healthiness endpoints are at `/monitoring/ready/` and `/monitoring/health/`.\n These are useful in environments like Kubernetes: \n https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/\n- Prometheus metrics are at `/monitoring/metrics/` .\n Use the [`prometheus_client`](https://pypi.org/project/prometheus-client/) library to expose more metrics.\n\n## Feature: NATS health checker\n\n```\nfrom powerflex_monitoring.nats_health_check import NatsHealthChecker\n```\n\nThis class checks if NATS is healthy and marks the service as unhealthy if NATS is ever down for a certain period of time.\n\n## Feature: Redis health checker\n\nThis feature checks if Redis service is healthy and marks the service as unhealthy if Redis is ever down for a certain period of time.\nHow to use it?\n1. Import the `RedisHealthChecker`\n\n```\nfrom powerflex_monitoring.redis_health_check import RedisHealthChecker\n```\n\n2. 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\n\n```\nredis_health_checker = RedisHealthChecker(redis_conn, monitoring_server)\n```\n\n3. Run the async function `periodically_check_redis_health` like this:\n\n```\nawait redis_health_checker.periodically_check_redis_health()\n```\n\n## Feature: wait for service to be ready\n\nThis is useful when starting your integration tests.\nIf you use the readiness check, then you can delay an action until your service is ready.\n\n```\npython -m powerflex_monitoring.wait_for_service_ready \\\n --ready-check-url http://localhost:8000/monitoring/ready/\n```\n\nMake sure this library is installed in your virtualenv or globally,\notherwise you won't be able to run this script.\n\nSee our Makefile for an example of using this script to wait before running integration tests.\n\n## Test results\n\nThis library is unit tested with 100% coverage in Python versions 3.8 to 3.11 and in pypy 3.9.\n\n## Developing\n\n1. Install the dependencies with `make setup`.\n This will use `pipenv` to manage a virtualenv.\n1. Run the commands in the [`Makefile`](./Makefile) to test your code.\n Run `pipenv shell` before running the commands or run `pipenv run make ...` to run the Makefile commands with `pipenv`.\n - `make commitready`\n - `make test-unit` or `make test-unit-all-python-versions`\n - `make format-fix`\n - `make lint`\n - `make type-check-strict`\n1. Please keep the unit test coverage at 100%.\n\n# Releasing to [PyPi.org](https://pypi.org/project/powerflex-monitoring/)\n\n1. Make sure all code checks have passed with `make commitready`.\n1. Make sure you commit all code you wish to release with `git commit`.\n1. Set the version in [`./src/powerflex_monitoring/VERSION`](./src/powerflex_monitoring/VERSION)\n Please attempt to follow [semantic versioning](https://semver.org/).\n1. Run `make bump-version` to commit the change to the `VERSION` file.\n1. Run `make release` to upload the package to pypi.org and to push a new git tag\n\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Tools to assist in monitoring a Python service.",
"version": "1.8.1",
"project_urls": {
"Homepage": "https://github.com/edf-re/powerflex_python_monitoring",
"Issue Tracker": "https://github.com/edf-re/powerflex_python_monitoring/issues"
},
"split_keywords": [
"monitoring",
" powerflex",
" python"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "c88ed1720be714318d5dc6da483158b34ad6cb3c1a19c2adb749853237b7b135",
"md5": "96d581830ed1d6fb33936b8747b96f82",
"sha256": "9686d274839bcd1e591de26244c8813e1e818ca01601430426258aaf4e5dfbb4"
},
"downloads": -1,
"filename": "powerflex_monitoring-1.8.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "96d581830ed1d6fb33936b8747b96f82",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 16962,
"upload_time": "2025-07-24T19:34:11",
"upload_time_iso_8601": "2025-07-24T19:34:11.805279Z",
"url": "https://files.pythonhosted.org/packages/c8/8e/d1720be714318d5dc6da483158b34ad6cb3c1a19c2adb749853237b7b135/powerflex_monitoring-1.8.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "7c13019f1aa39a7bd5f9d11ae0a8277e1d10ca5a8ade31ddbf3e28e193fd76db",
"md5": "bd202cdb2faa018521cf5f1f30a6323f",
"sha256": "de6dc1e552918579c1324983f321604e67e3bc9b764ea4d53d75d43b749038fe"
},
"downloads": -1,
"filename": "powerflex_monitoring-1.8.1.tar.gz",
"has_sig": false,
"md5_digest": "bd202cdb2faa018521cf5f1f30a6323f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 12727,
"upload_time": "2025-07-24T19:34:13",
"upload_time_iso_8601": "2025-07-24T19:34:13.025587Z",
"url": "https://files.pythonhosted.org/packages/7c/13/019f1aa39a7bd5f9d11ae0a8277e1d10ca5a8ade31ddbf3e28e193fd76db/powerflex_monitoring-1.8.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-24 19:34:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "edf-re",
"github_project": "powerflex_python_monitoring",
"github_not_found": true,
"lcname": "powerflex-monitoring"
}