Files
Scrobbler/src/scrobbler/federation/metrics.py
T
mattandClaude Sonnet 5 ba30d5cb15
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 11s
CI / federation-interop (push) Successful in 1m7s
CI / test (push) Successful in 3m15s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
Now-playing publisher and worker task (phase 4, step 3)
publishing/now_playing.py: a periodic scan (federation.now_playing,
every 30s) that pushes a throttled Update(Person) for the profile
field (5 minutes) and, for users opted into posts, publishes a Note
after a track's been playing 30+ seconds (throttled to 30 minutes),
deleting the previous now-playing post once the new one is confirmed
published - not before, so a failed publish never leaves a user with
none showing. Reuses publishing.publish()/delete_post() unchanged;
now_playing is just another post kind.

Fixed a real bug before it ever ran against Postgres: the key
(artist/track/started_at) was going straight into federation_posts.key
(VARCHAR(64)), which routinely overflows for real track and artist
names. Hashed instead - it's an idempotency token, not something
anyone needs to read.

New metric scrobbler_federation_profile_updates_total{result}; posts
already get scrobbler_federation_posts_total{kind="now_playing",...}
for free from the existing publish() instrumentation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
2026-09-26 17:13:10 +01:00

80 lines
2.5 KiB
Python

"""Federation's own metrics (the core's HTTP metrics already cover rate/latency)."""
from prometheus_client import Counter, Gauge, Histogram
lookups_total = Counter(
"scrobbler_federation_lookups_total",
"Fediverse lookups answered: WebFinger, actor, NodeInfo, profile",
["kind", "result"],
)
sharing_changes_total = Counter(
"scrobbler_federation_sharing_changes_total",
"Users switching fediverse sharing on or off",
["change"],
)
inbox_requests_total = Counter(
"scrobbler_federation_inbox_requests_total",
"Deliveries received at an inbox (not yet processed: phase 2)",
["inbox"],
)
inbox_activities_total = Counter(
"scrobbler_federation_inbox_activities_total",
"Activities received: queued, duplicate, blocked or invalid at intake; then processed, "
"rejected or failed",
["type", "result"],
)
signatures_total = Counter(
"scrobbler_federation_signatures_total",
"HTTP signature checks (in) and signing (out), by scheme and result",
["direction", "scheme", "result"],
)
deliveries_total = Counter(
"scrobbler_federation_deliveries_total",
"Outgoing deliveries: delivered, retry, abandoned (gave up or refused) or gone (410)",
["result"],
)
delivery_seconds = Histogram(
"scrobbler_federation_delivery_seconds",
"Time to deliver one activity to one inbox",
buckets=(0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 20),
)
queue = Gauge(
"scrobbler_federation_queue",
"Inbox items and deliveries by status (set by the worker)",
["queue", "status"],
multiprocess_mode="max",
)
followers = Gauge(
"scrobbler_federation_followers",
"Followers across all users, by state (set by the worker)",
["state"],
multiprocess_mode="max",
)
posts_total = Counter(
"scrobbler_federation_posts_total",
"Posts published: weekly summaries, milestones and now-playing",
["kind", "visibility"],
)
post_deletions_total = Counter(
"scrobbler_federation_post_deletions_total",
"Posts deleted, by reason",
["reason"],
)
milestone_checks_total = Counter(
"scrobbler_federation_milestone_checks_total",
"Milestone checks, by result: disabled, none or posted",
["result"],
)
weekly_total = Counter(
"scrobbler_federation_weekly_total",
"Weekly summary checks, by result: disabled, skipped_empty, already_posted or posted",
["result"],
)
profile_updates_total = Counter(
"scrobbler_federation_profile_updates_total",
"Now-playing Update(Person) pushes: sent, or throttled (still within the 5-minute "
"window since the last one)",
["result"],
)