Skip to content

Commit

Permalink
📈 add active documents metric
Browse files Browse the repository at this point in the history
  • Loading branch information
anuejn committed May 3, 2024
1 parent 5efffe3 commit 1cf9084
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions backend/transcribee_backend/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,22 @@ def refresh(self, session: Session):

class Documents(GaugeMetric):
def __init__(self):
self.collector = Gauge("transcribee_documents", "Documents")
self.collector = Gauge("transcribe_documents", "Documents", ["group"])

def refresh(self, session: Session):
(result,) = session.query(func.count(Document.id)).one()
self.collector.set(result)
self.collector.labels(group="all").set(result)

now = now_tz_aware()
document_timeout_active = now - datetime.timedelta(hours=1)
(result,) = (
session.query(func.count(func.distinct(Document.id)))
.where(
col(Document.changed_at) >= document_timeout_active,
)
.one()
)
self.collector.labels(group="active").set(result)


class Queue(GaugeMetric):
Expand Down

0 comments on commit 1cf9084

Please sign in to comment.