Skip to main content

Lightweight heartbeat and critical alert monitoring for microservices

Project description

lifebeacon

English | Українська


English

Lightweight monitoring library for microservices. Provides two independent components: periodic heartbeat pings and one-time critical alert notifications over HTTP.

Installation

pip install lifebeacon
uv add lifebeacon

Requirements

  • Python 3.11+

Components

Heartbeat

Sends periodic HTTP requests to a specified endpoint on a background daemon thread. Useful for signaling liveness to external monitoring systems.

from lifebeacon import Heartbeat

heartbeat = Heartbeat(
    url="https://monitoring.example.com/ping",
    interval=60,           # seconds between requests, default 120
    token="your-token",    # optional Bearer token
    method="POST",         # default POST
    timeout=5,             # request timeout in seconds, default 5
    service="my-service",  # any extra fields go into the JSON body
)

heartbeat.start()  # starts background thread, no effect if already running
# ...
heartbeat.stop()   # stops the thread and waits up to 5 seconds for it to finish

CriticalAlert

Sends a one-time HTTP request. Designed for notifying external systems about critical events such as failures or exceptions. Supports both async and sync usage.

The internal HTTP client is created lazily on first use and reused across subsequent calls. Call aclose() in async contexts or close() in sync contexts when the instance is no longer needed to release the underlying connection pool.

Async usage:

from lifebeacon import CriticalAlert

alert = CriticalAlert(
    url="https://monitoring.example.com/alert",
    token="your-token",    # optional Bearer token
    method="POST",         # default POST
    timeout=5,             # request timeout in seconds, default 5
    service="my-service",  # any extra fields become default JSON body fields
)

await alert.async_send(message="Database connection failed", level="critical")

await alert.aclose()

Sync usage:

from lifebeacon import CriticalAlert

alert = CriticalAlert(
    url="https://monitoring.example.com/alert",
    token="your-token",
    service="my-service",
)

alert.sync_send(message="Database connection failed", level="critical")

alert.close()

Extra keyword arguments passed to async_send() or sync_send() are merged with the instance-level defaults. Call-time values override instance-level defaults for duplicate keys.

Notes

  • All HTTP errors are silently suppressed in both components to avoid disrupting the host application.
  • Heartbeat runs on a daemon thread — it will not prevent the process from exiting.
  • CriticalAlert.aclose() / CriticalAlert.close() must be called explicitly when the instance is no longer needed.

Українська

Легковагова бібліотека моніторингу для мікросервісів. Надає два незалежних компоненти: періодичні heartbeat-пінги та одноразові сповіщення про критичні події через HTTP.

Встановлення

pip install lifebeacon
uv add lifebeacon

Вимоги

  • Python 3.11+

Компоненти

Heartbeat

Відправляє періодичні HTTP-запити на вказаний endpoint у фоновому daemon-потоці. Використовується для сигналізації про роботу сервісу зовнішнім системам моніторингу.

from lifebeacon import Heartbeat

heartbeat = Heartbeat(
    url="https://monitoring.example.com/ping",
    interval=60,           # секунди між запитами, за замовчуванням 120
    token="your-token",    # опціональний Bearer токен
    method="POST",         # за замовчуванням POST
    timeout=5,             # таймаут запиту в секундах, за замовчуванням 5
    service="my-service",  # будь-які додаткові поля потрапляють у тіло JSON
)

heartbeat.start()  # запускає фоновий потік, не має ефекту якщо вже запущений
# ...
heartbeat.stop()   # зупиняє потік і чекає до 5 секунд на завершення

CriticalAlert

Відправляє одноразовий HTTP-запит. Призначений для сповіщення зовнішніх систем про критичні події — збої, виключення тощо. Підтримує як async, так і sync використання.

HTTP-клієнт створюється ліниво при першому виклику і перевикористовується між наступними викликами. Викличте aclose() в async-контексті або close() в sync-контексті, коли інстанс більше не потрібен, щоб звільнити connection pool.

Async використання:

from lifebeacon import CriticalAlert

alert = CriticalAlert(
    url="https://monitoring.example.com/alert",
    token="your-token",    # опціональний Bearer токен
    method="POST",         # за замовчуванням POST
    timeout=5,             # таймаут запиту в секундах, за замовчуванням 5
    service="my-service",  # будь-які додаткові поля стають дефолтними полями JSON тіла
)

await alert.async_send(message="Database connection failed", level="critical")

await alert.aclose()

Sync використання:

from lifebeacon import CriticalAlert

alert = CriticalAlert(
    url="https://monitoring.example.com/alert",
    token="your-token",
    service="my-service",
)

alert.sync_send(message="Database connection failed", level="critical")

alert.close()

Додаткові keyword-аргументи, передані в async_send() або sync_send(), мерджаться з дефолтними полями інстансу. При дублюванні ключів — значення з виклику методу мають пріоритет.

Примітки

  • Всі HTTP-помилки мовчазно ігноруються в обох компонентах, щоб не переривати роботу хост-додатку.
  • Heartbeat працює в daemon-потоці — він не блокує завершення процесу.
  • CriticalAlert.aclose() / CriticalAlert.close() потрібно викликати явно коли інстанс більше не потрібен.

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

lifebeacon-2.0.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

lifebeacon-2.0.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file lifebeacon-2.0.0.tar.gz.

File metadata

  • Download URL: lifebeacon-2.0.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lifebeacon-2.0.0.tar.gz
Algorithm Hash digest
SHA256 4174c70cfb299c16d0c07f5714d5a101eeeb83f6442ddac7cf5ef8b815a4ef11
MD5 abc78fa60d0719a946e70ac136a990a6
BLAKE2b-256 3ca4df472379ca1e1ba6200dc4d3961d9cdeee4cd3ced2102eae4c9283fa7c0f

See more details on using hashes here.

File details

Details for the file lifebeacon-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: lifebeacon-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lifebeacon-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab21b8fd65a97ae1d24530d4f2c20e0b8bd8e901a9048652ef5fd5bcc709af87
MD5 ea86d419dd5805c1aaba72a1ff86c6bb
BLAKE2b-256 13637c7c0b37fc4713718b8eeabfcb1b6aff7de2ed1a12375d934058f91cd38c

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