Skip to main content

Tools to assist in monitoring a Python service.

Project description

PowerFlex Python Monitoring library (powerflex-monitoring)

PyPI - Version PyPI - License PyPI - Implementation PyPI - Python Version

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:

  1. Install docker and docker-compose
  2. Run make up
  3. 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

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
  1. 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)
  1. 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.
  2. Run the commands in the 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

  1. Make sure all code checks have passed with make commitready.
  2. Make sure you commit all code you wish to release with git commit.
  3. Set the version in ./src/powerflex_monitoring/VERSION Please attempt to follow semantic versioning.
  4. Run make bump-version to commit the change to the VERSION file.
  5. Run make release to upload the package to pypi.org and to push a new git tag

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

powerflex_monitoring-1.8.2.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

powerflex_monitoring-1.8.2-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file powerflex_monitoring-1.8.2.tar.gz.

File metadata

  • Download URL: powerflex_monitoring-1.8.2.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.17

File hashes

Hashes for powerflex_monitoring-1.8.2.tar.gz
Algorithm Hash digest
SHA256 a16595d80b34b527010929f844fc38bc896fcbc9443a9dec8f1263a7824c901d
MD5 83eaca427ff03e9282c04e4ece4338d4
BLAKE2b-256 ce811853b8a69b04472daa36c98692c72c78575861bad3391aaebe3e9fa20432

See more details on using hashes here.

File details

Details for the file powerflex_monitoring-1.8.2-py3-none-any.whl.

File metadata

File hashes

Hashes for powerflex_monitoring-1.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 af0cc71cd70bbd1b62fa7270a2f6d51634dfb624c0d3604c3afd9302087deccb
MD5 de11bcd59ec484a3aaf71559161ade69
BLAKE2b-256 588a4eab455bbab40e26a33bd960f1172a2cd2980fbdd16de7a04133b20c37d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page