Skip to content
Snippets Groups Projects
Commit 4ae73d16 authored by Erik Johnston's avatar Erik Johnston
Browse files

Merge pull request #270 from matrix-org/markjh/fix_metrics

Fix the size reported by maxrss.
parents a5b41b80 709ba99a
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
from __future__ import absolute_import from __future__ import absolute_import
import logging import logging
from resource import getrusage, getpagesize, RUSAGE_SELF from resource import getrusage, RUSAGE_SELF
import functools import functools
import os import os
import stat import stat
...@@ -100,7 +100,6 @@ def render_all(): ...@@ -100,7 +100,6 @@ def render_all():
# process resource usage # process resource usage
rusage = None rusage = None
PAGE_SIZE = getpagesize()
def update_resource_metrics(): def update_resource_metrics():
...@@ -113,8 +112,8 @@ resource_metrics = get_metrics_for("process.resource") ...@@ -113,8 +112,8 @@ resource_metrics = get_metrics_for("process.resource")
resource_metrics.register_callback("utime", lambda: rusage.ru_utime * 1000) resource_metrics.register_callback("utime", lambda: rusage.ru_utime * 1000)
resource_metrics.register_callback("stime", lambda: rusage.ru_stime * 1000) resource_metrics.register_callback("stime", lambda: rusage.ru_stime * 1000)
# pages # kilobytes
resource_metrics.register_callback("maxrss", lambda: rusage.ru_maxrss * PAGE_SIZE) resource_metrics.register_callback("maxrss", lambda: rusage.ru_maxrss * 1024)
TYPES = { TYPES = {
stat.S_IFSOCK: "SOCK", stat.S_IFSOCK: "SOCK",
...@@ -131,6 +130,10 @@ def _process_fds(): ...@@ -131,6 +130,10 @@ def _process_fds():
counts = {(k,): 0 for k in TYPES.values()} counts = {(k,): 0 for k in TYPES.values()}
counts[("other",)] = 0 counts[("other",)] = 0
# Not every OS will have a /proc/self/fd directory
if not os.path.exists("/proc/self/fd"):
return counts
for fd in os.listdir("/proc/self/fd"): for fd in os.listdir("/proc/self/fd"):
try: try:
s = os.stat("/proc/self/fd/%s" % (fd)) s = os.stat("/proc/self/fd/%s" % (fd))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment