๐Ÿฆ€ Rust Core ๐Ÿ Python API v0.1.1 ๐Ÿ“ฆ PyPI

Monitor Python apps
at Rust speed

Drop-in middleware for FastAPI and Django.
CPU, memory, p95/p99 latency, and Prometheus export โ€” zero configuration.

$ pip install rust-py-monitor
python
>>> import rust_py_monitor
>>> m = rust_py_monitor.snapshot()
Snapshot(pid=8421, rss=48.2MB)
>>> stats = rust_py_monitor.aggregate()
AggregatedMetrics(p95=47.3ms, p99=92.1ms)
>>> โ–ˆ
87Tests passing
13Prometheus metrics
~300KBWheel size
0Runtime deps

Everything you need to monitor

Rust does the heavy lifting. Python stays simple.

๐Ÿ“Š

Process Snapshot

CPU usage, RSS memory, virtual memory, thread count, and PID โ€” sampled directly from the OS via the sysinfo Rust crate.

โšก

FastAPI Middleware

Add MonitorMiddleware in one line. Captures method, path, status code, and latency for every request with ASGI-native performance.

๐ŸŽธ

Django Middleware

Works with both WSGI and ASGI Django apps. Drop it first in your MIDDLEWARE list and it wraps the full request lifecycle.

๐Ÿ“ˆ

p95 / p99 Latency

The aggregator runs in Rust โ€” sorting, percentile calculation, and error rate are computed without any Python overhead on the hot path.

๐Ÿ”ฅ

Prometheus Export

One router include gives your FastAPI app a /metrics endpoint. Django gets a view function. No separate process, no config file.

๐Ÿฆ€

Rust Core via PyO3

The collection and aggregation logic lives in Rust and compiles to a native .so extension. Users just pip install โ€” no Rust needed.

Works with your stack

Three lines to get started with any Python web framework.

Python
from fastapi import FastAPI
from rust_py_monitor.fastapi import MonitorMiddleware
from rust_py_monitor.prometheus import make_fastapi_router

app = FastAPI()

# 1. Add monitoring middleware
app.add_middleware(MonitorMiddleware)

# 2. Expose /metrics endpoint for Prometheus
app.include_router(make_fastapi_router())

@app.get("/users")
async def list_users():
    return [{"id": 1, "name": "Alice"}]
Python
# settings.py
MIDDLEWARE = [
    "rust_py_monitor.django.MonitorMiddleware",
    # ... rest of your middleware
]

# urls.py
from django.urls import path
from rust_py_monitor.prometheus import django_metrics_view

urlpatterns = [
    path("metrics/", django_metrics_view),
    # ... your routes
]
Python
import rust_py_monitor

# Process snapshot
m = rust_py_monitor.snapshot()
print(m.pid)            # 8421
print(m.cpu_percent)    # 1.3
print(m.memory_rss_mb)  # 48.2
print(m.to_dict())      # {"pid": 8421, ...}

# Aggregated request stats
stats = rust_py_monitor.aggregate()
print(stats.total_requests)  # 1024
print(stats.error_rate)      # 1.17
print(stats.p95_latency_ms)  # 47.3
print(stats.p99_latency_ms)  # 92.1

# All recorded requests
for req in rust_py_monitor.get_requests()[-5:]:
    print(req)  # RequestMetric(GET /api/users 200 12.34ms)

Prometheus-ready metrics

Scrape /metrics directly โ€” compatible with any Prometheus setup.

HTTP Request Metrics

  • rpy_requests_total counter
  • rpy_errors_total counter
  • rpy_error_rate_percent gauge
  • rpy_latency_avg_ms gauge
  • rpy_latency_p50_ms gauge
  • rpy_latency_p95_ms gauge
  • rpy_latency_p99_ms gauge
  • rpy_latency_min_ms gauge
  • rpy_latency_max_ms gauge

Process Metrics

  • rpy_process_cpu_percent gauge
  • rpy_process_memory_rss_bytes gauge
  • rpy_process_memory_virtual_bytes gauge
  • rpy_process_threads gauge
GET /metrics
# HELP rpy_requests_total Total HTTP requests recorded
# TYPE rpy_requests_total counter
rpy_requests_total 1024

# HELP rpy_errors_total Total HTTP errors (status >= 400)
# TYPE rpy_errors_total counter
rpy_errors_total 12

# HELP rpy_latency_p95_ms P95 request latency in ms
# TYPE rpy_latency_p95_ms gauge
rpy_latency_p95_ms 47.3

# HELP rpy_latency_p99_ms P99 request latency in ms
# TYPE rpy_latency_p99_ms gauge
rpy_latency_p99_ms 92.1

# HELP rpy_process_memory_rss_bytes Process RSS memory
# TYPE rpy_process_memory_rss_bytes gauge
rpy_process_memory_rss_bytes 50331648

How it works

Rust collects and aggregates. Python integrates. You observe.

Your App
FastAPI Django
โ†’
Middleware
MonitorMiddleware record_request()
โ†’
๐Ÿฆ€ Rust Core
static Mutex<Vec> sysinfo aggregator
โ†’
Export
Prometheus JSON / dict

The native .so extension is compiled once at publish time via maturin + PyO3.
Your users just pip install โ€” no Rust toolchain required.

Ready in seconds

Install from PyPI. No Rust, no compilers, no configuration.

Basic

pip install rust-py-monitor

With FastAPI

pip install "rust-py-monitor[fastapi]"

With Django

pip install "rust-py-monitor[django]"

Full stack

pip install "rust-py-monitor[fastapi,django]"
Requires Python 3.10+ ยท Linux ยท macOS ยท Windows ยท MIT License
Copied!