Registry / observability / statshog

statshog

JSON →
library1.0.6pypypi✓ verified 21d ago

statshog is a simple Python client for emitting metrics to StatsD servers, including both Etsy's original StatsD and InfluxDB's Telegraf StatsD server. It provides functionalities for incrementing counters, recording gauges, and tracking timings. The library is currently at version 1.0.6, with a stable but infrequent release cadence, reflecting its mature and focused functionality.

pip install statshog
INSTALL
IMPORT
SIG · STATSHOG
S
statshog
observabilitypythonv1.0.6
Install
1.8s avg
Import
26ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.026s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.026s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StatsClient
from statshog import StatsClient
statsd (Django default)
from statshog.defaults.django import statsd
import statsd # if not configured via Django settings
This import is for Django-specific integration and assumes configuration via Django settings. For standalone use, initialize StatsClient directly.

This quickstart demonstrates how to initialize the `StatsClient` and send common metric types: increments, gauges, and timings. It also shows how to use tags when `telegraf=True` is enabled.

import statshog import time # Initialize a StatsD client (defaults to localhost:8125) # For Telegraf's StatsD with tags, use telegraf=True statsd = statshog.StatsClient(host='127.0.0.1', port=8125, telegraf=True) # Increment a counter statsd.incr('my_app.requests_total') statsd.incr('my_app.errors', tags={'type': 'database_error'}) # Record a gauge value statsd.gauge('my_app.cpu_usage', 55) statsd.gauge('my_app.memory_percent', 72.5, tags={'host': 'server_a'}) # Record a timing start_time = time.time() time.sleep(0.05) # Simulate some work end_time = time.time() duration_ms = (end_time - start_time) * 1000 statsd.timing('my_app.api_response_time', duration_ms, tags={'endpoint': '/api/data'}) print('Metrics sent to StatsD.') # In a real application, ensure your StatsD server (e.g., Telegraf) is running on 127.0.0.1:8125 # and listening for UDP packets.
Debug
Known issues
gotchaStatsD clients, including statshog, typically use UDP for sending metrics. UDP is an unreliable protocol, meaning there is no guarantee that packets will reach the StatsD server. For critical metrics, consider the implications of potential packet loss.
fix
Be aware of UDP's unreliable nature; implement checks at the monitoring backend level if metric integrity is paramount. For high-volume, non-critical metrics, UDP is generally acceptable.
affects: All versions
gotchaWhen initializing `StatsClient`, ensure `host` and `port` parameters are correctly configured for your StatsD server. The defaults (`localhost:8125`) might not match your deployment.
fix
Always explicitly pass `host` and `port` to `statshog.StatsClient(...)` or confirm that `localhost:8125` is indeed where your StatsD server is listening.
affects: All versions
gotchaUsing the `telegraf=True` parameter changes the wire format for sending tags. If your StatsD server is not Telegraf-compatible (or another server that understands Telegraf's tag format), tags will likely be ignored or cause parsing errors.
fix
Only set `telegraf=True` if your StatsD backend explicitly supports the Telegraf (or similar) tagged StatsD format. Otherwise, tags will not be transmitted correctly.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'statshog'
The `statshog` package has not been installed in the current Python environment.
fix
pip install statshog
socket.gaierror: [Errno -2] Name or service not known
The hostname provided to `statshog.configure()` is invalid, misspelled, or cannot be resolved by the system's DNS.
fix
statshog.configure(host='your_valid_statsd_host', port=8125)
TypeError: an integer is required (got type str)
The port number provided to `statshog.configure()` was supplied as a string or another non-integer type.
fix
statshog.configure(host='localhost', port=8125)
TypeError: increment() missing 1 required positional argument: 'metric_name'
A required argument, such as `metric_name` for `statshog.increment()`, was not provided when calling the function.
fix
statshog.increment('my.app.event_count')
Upgrade
Version history
1.0.6latest on PyPI · released May 7, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
statshog — pip install statshog · libregistry