Netflix Spectator Python Client

1.1.2 · active · verified Thu Apr 16

netflix-spectator-py is a thin-client library for reporting metrics from Python applications to SpectatorD and the Netflix Atlas Timeseries Database. It is currently at version 1.1.2 and maintains an active release cadence, providing continuous bug fixes and feature enhancements.

Common errors

Warnings

Install

Imports

Quickstart

Initializes a `Registry` with an optional `Config` for common tags, then demonstrates basic usage of `Counter`, `Timer`, and `Gauge` to report metrics. By default, metrics are sent via UDP to a local SpectatorD agent.

from spectator import Registry, Config
import time
import os

# Configure with optional extra common tags (e.g., for environment, service)
config = Config(extra_common_tags={'env': os.environ.get('SPECTATOR_ENV', 'dev')})
registry = Registry(config)

# Create and interact with a counter
request_counter = registry.counter('my_service.request_count')
request_counter.increment()
print(f"Request Count: {request_counter.get()}")

# Create and interact with a timer
processing_timer = registry.timer('my_service.processing_latency')
with processing_timer.start():
    time.sleep(0.1) # Simulate work
print(f"Processing Latency recorded: {processing_timer.get_count()} events")

# Create and interact with a gauge (manual update)
current_items = registry.gauge('my_service.current_items')
current_items.set(5)
print(f"Current Items: {current_items.get()}")

# Note: Metrics are typically sent to a SpectatorD agent via UDP by default. Ensure SpectatorD is running.

view raw JSON →