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
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
1 parent
b435a3b
commit 9ad5d73
Showing
10 changed files
with
132 additions
and
5 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 | ||
|
||
from prometheus_client import Histogram | ||
|
||
|
||
_MEMCACHED_BUCKETS = [0.001, 0.005, 0.01, 0.025] | ||
|
||
|
||
class MemcachedHistogram: | ||
def __init__(self, name, documentation, *args, **kwargs): | ||
self._state = threading.local() | ||
self._cached = Histogram(f"{name}_cached", f"{documentation} (cached)", *args, buckets=_MEMCACHED_BUCKETS, **kwargs) | ||
self._uncached = Histogram(f"{name}_uncached", f"{documentation} (uncached)", *args, **kwargs) | ||
|
||
def cached(self, func): | ||
@functools.wraps(func) | ||
def wrapped(*args, **kwargs): | ||
self._state.cached = True | ||
|
||
start = time.perf_counter() | ||
ret = func(*args, **kwargs) | ||
|
||
if self._state.cached: | ||
self._cached.observe(time.perf_counter() - start) | ||
|
||
return ret | ||
|
||
return wrapped | ||
|
||
def uncached(self, func): | ||
@functools.wraps(func) | ||
def wrapped(*args, **kwargs): | ||
self._state.cached = False | ||
|
||
start = time.perf_counter() | ||
ret = func(*args, **kwargs) | ||
self._uncached.observe(time.perf_counter() - start) | ||
|
||
return ret | ||
|
||
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