mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-23 18:04:34 +00:00
feat: add memory monitoring for prometheus (#481)
This commit is contained in:
co-authored by
GitHub
parent
28afe2dfae
commit
5fe59ffae3
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "Monitoring: Prometheus Metrics",
|
"name": "Monitoring: Prometheus Metrics",
|
||||||
"version": "17.0.1.0.0",
|
"version": "18.0.1.0.0",
|
||||||
"author": "Camptocamp,Odoo Community Association (OCA)",
|
"author": "Camptocamp,Odoo Community Association (OCA)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"category": "category",
|
"category": "category",
|
||||||
@@ -18,5 +18,5 @@
|
|||||||
"external_dependencies": {
|
"external_dependencies": {
|
||||||
"python": ["prometheus_client"],
|
"python": ["prometheus_client"],
|
||||||
},
|
},
|
||||||
"installable": False,
|
"installable": True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ from prometheus_client import generate_latest
|
|||||||
|
|
||||||
from odoo.http import Controller, route
|
from odoo.http import Controller, route
|
||||||
|
|
||||||
|
from ..models.psutils_helpers import get_process_info
|
||||||
|
|
||||||
|
|
||||||
class PrometheusController(Controller):
|
class PrometheusController(Controller):
|
||||||
@route("/metrics", auth="public")
|
@route("/metrics", auth="public")
|
||||||
def metrics(self):
|
def metrics(self):
|
||||||
|
get_process_info()
|
||||||
return generate_latest()
|
return generate_latest()
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
from . import ir_http
|
from . import ir_http
|
||||||
|
from . import psutils_helpers
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import psutil
|
||||||
|
from prometheus_client import Gauge
|
||||||
|
|
||||||
|
MEMORY_USAGE_VMS = Gauge(
|
||||||
|
"odoo_worker_memory_user_vms_mb", "Memory usage in MB", ["process", "pid"]
|
||||||
|
)
|
||||||
|
|
||||||
|
MEMORY_USAGE_RSS = Gauge(
|
||||||
|
"odoo_worker_memory_user_rss_mb", "Memory usage in MB", ["process", "pid"]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_process_info():
|
||||||
|
for process in psutil.process_iter(
|
||||||
|
["pid", "name", "memory_full_info", "cmdline", "nice"]
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
if process.info["memory_full_info"]:
|
||||||
|
if process.info["nice"] == 10:
|
||||||
|
ProcessLabel = "workercron"
|
||||||
|
elif process.info["pid"] == 1:
|
||||||
|
ProcessLabel = "dispatcher"
|
||||||
|
elif any("gevent" in x for x in process.info["cmdline"]):
|
||||||
|
ProcessLabel = "gevent"
|
||||||
|
elif any("odoo" in x for x in process.info["cmdline"]):
|
||||||
|
ProcessLabel = "workerhttp"
|
||||||
|
elif any("shell" in x for x in process.cmdline()):
|
||||||
|
ProcessLabel = "OdooShell"
|
||||||
|
else:
|
||||||
|
ProcessLabel = "other"
|
||||||
|
MEMORY_USAGE_VMS.labels(ProcessLabel, process.info["pid"]).set(
|
||||||
|
process.info["memory_full_info"].rss // 1000000
|
||||||
|
)
|
||||||
|
MEMORY_USAGE_RSS.labels(ProcessLabel, process.info["pid"]).set(
|
||||||
|
process.info["memory_full_info"].vms // 1000000
|
||||||
|
)
|
||||||
|
|
||||||
|
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
|
||||||
|
continue
|
||||||
Reference in New Issue
Block a user