-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose some initial Prometheus metrics (#1402)
The Prometheus client library for Python seems not great, but we really need metrics to get a sense of some upcoming performance improvements.
- Loading branch information
Showing
10 changed files
with
149 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM docker.io/prom/prometheus:v2.51.1 | ||
COPY prometheus.yml /etc/prometheus/prometheus.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
global: | ||
scrape_interval: 15s | ||
evaluation_interval: 15s | ||
|
||
scrape_configs: | ||
- job_name: web | ||
static_configs: | ||
- targets: ['web:8080'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import functools | ||
import threading | ||
import time | ||
|
||
|
||
class CachedMetric: | ||
""" | ||
A metric for a cached operation. Adds a `cached` label. | ||
""" | ||
|
||
def __init__(self, metric): | ||
self._state = threading.local() | ||
self._metric = metric | ||
metric.labels(cached="no") | ||
metric.labels(cached="yes") | ||
|
||
def cached(self, func): | ||
state = self._state | ||
metric = self._metric | ||
|
||
@functools.wraps(func) | ||
def wrapped(*args, **kwargs): | ||
state.cached = True | ||
|
||
start = time.perf_counter() | ||
ret = func(*args, **kwargs) | ||
duration = time.perf_counter() - start | ||
|
||
metric.labels(cached="yes" if state.cached else "no").observe(duration) | ||
|
||
return ret | ||
|
||
return wrapped | ||
|
||
def uncached(self, func): | ||
state = self._state | ||
|
||
@functools.wraps(func) | ||
def wrapped(*args, **kwargs): | ||
state.cached = False | ||
return func(*args, **kwargs) | ||
|
||
return wrapped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters