Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add worker mem metrics #467

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions monitoring_prometheus/controllers/prometheus_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

from odoo.http import Controller, route

from ..models.psutils_helpers import get_process_info


class PrometheusController(Controller):
@route("/metrics", auth="public")
def metrics(self):
get_process_info()
return generate_latest()
1 change: 1 addition & 0 deletions monitoring_prometheus/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import ir_http
from . import psutils_helpers
39 changes: 39 additions & 0 deletions monitoring_prometheus/models/psutils_helpers.py
Original file line number Diff line number Diff line change
@@ -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:
vrenaville marked this conversation as resolved.
Show resolved Hide resolved
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
Loading