-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prometheus http and kernel startup/shutdown metrics
- Loading branch information
maico
committed
Mar 27, 2024
1 parent
d01e84a
commit a71811f
Showing
6 changed files
with
99 additions
and
3 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
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,28 @@ | ||
import os | ||
|
||
from prometheus_client import Histogram | ||
|
||
metrics_prefix = os.environ.get("EG_METRICS_PREFIX", "enterprise_gateway") | ||
|
||
HTTP_REQUEST_DURATION_SECONDS = Histogram( | ||
'http_request_duration_seconds', | ||
'Request duration for all HTTP requests', | ||
['method', 'handler', 'status_code'], | ||
namespace=metrics_prefix, | ||
) | ||
|
||
KERNEL_START_DURATION_SECONDS = Histogram( | ||
'kernel_start_duration_seconds', | ||
'Kernel startup duration', | ||
['kernel_name', 'process_proxy'], | ||
buckets=[0.1, 0.25, 0.5, 1, 2.5, 5.0, 10.0, 15.0, 20.0, 30.0], | ||
namespace=metrics_prefix, | ||
) | ||
|
||
KERNEL_SHUTDOWN_DURATION_SECONDS = Histogram( | ||
'kernel_shutdown_duration_seconds', | ||
'Kernel startup duration for all HTTP requests', | ||
['kernel_name', 'process_proxy'], | ||
buckets=[0.1, 0.25, 0.5, 1, 2.5, 5.0, 10.0, 15.0, 20.0, 30.0], | ||
namespace=metrics_prefix, | ||
) |
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,32 @@ | ||
|
||
from tornado import web | ||
from tornado.web import RequestHandler | ||
|
||
from enterprise_gateway.metrics import HTTP_REQUEST_DURATION_SECONDS | ||
|
||
|
||
class EnterpriseGatewayWebApp(web.Application): | ||
|
||
def log_request(self, handler: RequestHandler) -> None: | ||
""" | ||
Tornado log handler for recording RED metrics. | ||
We record the following metrics: | ||
Rate: the number of requests, per second, your services are serving. | ||
Errors: the number of failed requests per second. | ||
Duration: the amount of time each request takes expressed as a time interval. | ||
We use a fully qualified name of the handler as a label, | ||
rather than every url path to reduce cardinality. | ||
This function should be either the value of or called from a function | ||
that is the 'log_function' tornado setting. This makes it get called | ||
at the end of every request, allowing us to record the metrics we need. | ||
""" | ||
super().log_request(handler) | ||
|
||
HTTP_REQUEST_DURATION_SECONDS.labels( | ||
method=handler.request.method, | ||
handler=f'{handler.__class__.__module__}.{type(handler).__name__}', | ||
status_code=handler.get_status(), | ||
).observe(handler.request.request_time()) |