mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-23 18:04:34 +00:00
[13.0][ADD] monitoring_prometheus (#239)
[13.0][ADD] monitoring_prometheus
This commit is contained in:
committed by
Yannick Vaucher
co-authored by
Yannick Vaucher
parent
d0800a81fb
commit
6bb5ffe3e9
@@ -0,0 +1,17 @@
|
||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||
:alt: License
|
||||
|
||||
==============================
|
||||
Monitoring: Prometheus metrics
|
||||
==============================
|
||||
|
||||
Add an endpoint */metrics* to allow a Prometheus server to fetch application metrics.
|
||||
Current available metrics are:
|
||||
|
||||
* Request completion time with 3 differentiators:
|
||||
* Filestore
|
||||
* Assets
|
||||
* Everything else
|
||||
* Longpolling request count
|
||||
|
||||
No additional configuration is needed, just ensure that the Prometheus server is allowed to communicate with Odoo
|
||||
@@ -0,0 +1,2 @@
|
||||
from . import controllers
|
||||
from . import models
|
||||
@@ -0,0 +1,22 @@
|
||||
# Copyright 2016-2019 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
|
||||
{
|
||||
"name": "Monitoring: Prometheus Metrics",
|
||||
"version": "13.0.1.0.0",
|
||||
"author": "Camptocamp,Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
"category": "category",
|
||||
"depends": [
|
||||
"base",
|
||||
"web",
|
||||
"server_environment",
|
||||
],
|
||||
"website": "http://www.camptocamp.com",
|
||||
"data": [],
|
||||
"external_dependencies": {
|
||||
"python": ["prometheus_client"],
|
||||
},
|
||||
"installable": True,
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
from . import prometheus_metrics
|
||||
@@ -0,0 +1,11 @@
|
||||
# Copyright 2016-2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
from odoo.http import Controller, route
|
||||
from prometheus_client import generate_latest
|
||||
|
||||
|
||||
class PrometheusController(Controller):
|
||||
@route('/metrics', auth='public')
|
||||
def metrics(self):
|
||||
return generate_latest()
|
||||
@@ -0,0 +1 @@
|
||||
from . import ir_http
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright 2016-2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
from odoo import models
|
||||
from odoo.http import request
|
||||
from prometheus_client import Summary, Counter
|
||||
|
||||
|
||||
REQUEST_TIME = Summary(
|
||||
"request_latency_sec", "Request response time in sec", ["query_type"]
|
||||
)
|
||||
LONGPOLLING_COUNT = Counter("longpolling", "Longpolling request count")
|
||||
|
||||
|
||||
class IrHttp(models.AbstractModel):
|
||||
_inherit = "ir.http"
|
||||
|
||||
@classmethod
|
||||
def _dispatch(cls):
|
||||
path_info = request.httprequest.environ.get("PATH_INFO")
|
||||
|
||||
if path_info.startswith("/longpolling/"):
|
||||
LONGPOLLING_COUNT.inc()
|
||||
return super()._dispatch()
|
||||
|
||||
if path_info.startswith("/metrics"):
|
||||
return super()._dispatch()
|
||||
|
||||
if path_info.startswith("/web/static"):
|
||||
label = "assets"
|
||||
elif path_info.startswith("/web/content"):
|
||||
label = "filestore"
|
||||
else:
|
||||
label = "client"
|
||||
|
||||
res = None
|
||||
with REQUEST_TIME.labels(label).time():
|
||||
res = super()._dispatch()
|
||||
|
||||
return res
|
||||
@@ -9,3 +9,4 @@ python-keystoneclient==3.22.0
|
||||
keystoneauth1==3.14.0
|
||||
# error with 5.x (ConstructorError: could not determine a constructor for the tag '!record')
|
||||
PyYAML==4.2b4
|
||||
prometheus_client==0.11.0
|
||||
|
||||
Reference in New Issue
Block a user