Skip to content

Commit

Permalink
Set up prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
danpalmer committed Apr 23, 2018
1 parent 2340b4d commit cd5fa2f
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions plugins/routemaster-prometheus/routemaster_prometheus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
('type',),
)

cron_jobs_processed = Counter(
'cron_jobs_processed',
"Cron jobs processed",
('fn_name', 'state_machine', 'state'),
)

webhooks_triggered = Counter(
'webhooks_triggered',
"Webhooks triggered",
('state_machine', 'state'),
)

feed_requests = Counter(
'feed_requests',
"Feed requests",
('feed_url', 'state_machine', 'state'),
)


class PrometheusLogger(BaseLogger):
"""Instruments Routemaster with Prometheus."""
Expand All @@ -34,21 +52,29 @@ def process_cron(self, state_machine, state, fn_name):
"""Send cron exceptions to Prometheus."""
with exceptions.labels(type='cron').count_exceptions():
yield
cron_jobs_processed.labels(
fn_name=fn_name,
state_machine=state_machine.name,
state=state.name,
).inc()

@contextlib.contextmanager
def process_webhook(self, state_machine, state):
"""Send webhook request exceptions to Prometheus."""
with exceptions.labels(type='webhook').count_exceptions():
yield
webhooks_triggered.labels(
state_machine=state_machine.name,
state=state.name,
).inc()

@contextlib.contextmanager
def process_feed(self, state_machine, state, feed_url):
"""Send feed request exceptions to Prometheus."""
with exceptions.labels(type='feed').count_exceptions():
yield

@contextlib.contextmanager
def process_request(self):
"""Send API request exceptions to Prometheus."""
with exceptions.labels(type='request').count_exceptions():
yield
feed_requests.labels(
feed_url=feed_url,
state_machine=state_machine.name,
state=state.name,
).inc()

0 comments on commit cd5fa2f

Please sign in to comment.