##// END OF EJS Templates
process-management: use safer way to extract data for processes....
marcink -
r2540:370f15d3 default
parent child Browse files
Show More
@@ -28,7 +28,7 b' from rhodecode.apps._base import BaseApp'
28 28 from rhodecode.apps.admin.navigation import navigation_list
29 29 from rhodecode.lib.auth import (
30 30 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
31 from rhodecode.lib.utils2 import safe_int
31 from rhodecode.lib.utils2 import safe_int, StrictAttributeDict
32 32
33 33 log = logging.getLogger(__name__)
34 34
@@ -36,8 +36,40 b' log = logging.getLogger(__name__)'
36 36 class AdminProcessManagementView(BaseAppView):
37 37 def load_default_context(self):
38 38 c = self._get_local_tmpl_context()
39 return c
39 40
40 return c
41 def _format_proc(self, proc, with_children=False):
42 try:
43 mem = proc.memory_info()
44 proc_formatted = StrictAttributeDict({
45 'pid': proc.pid,
46 'name': proc.name(),
47 'mem_rss': mem.rss,
48 'mem_vms': mem.vms,
49 'cpu_percent': proc.cpu_percent(),
50 'create_time': proc.create_time(),
51 'cmd': ' '.join(proc.cmdline()),
52 })
53
54 if with_children:
55 proc_formatted.update({
56 'children': [self._format_proc(x)
57 for x in proc.children(recursive=True)]
58 })
59 except Exception:
60 log.exception('Failed to load proc')
61 proc_formatted = None
62 return proc_formatted
63
64 def get_processes(self):
65 proc_list = []
66 for p in psutil.process_iter():
67 if 'gunicorn' in p.name():
68 proc = self._format_proc(p, with_children=True)
69 if proc:
70 proc_list.append(proc)
71
72 return proc_list
41 73
42 74 @LoginRequired()
43 75 @HasPermissionAllDecorator('hg.admin')
@@ -50,8 +82,7 b' class AdminProcessManagementView(BaseApp'
50 82
51 83 c.active = 'process_management'
52 84 c.navlist = navigation_list(self.request)
53 c.gunicorn_processes = (
54 p for p in psutil.process_iter() if 'gunicorn' in p.name())
85 c.gunicorn_processes = self.get_processes()
55 86 return self._get_template_context(c)
56 87
57 88 @LoginRequired()
@@ -62,8 +93,7 b' class AdminProcessManagementView(BaseApp'
62 93 def process_management_data(self):
63 94 _ = self.request.translate
64 95 c = self.load_default_context()
65 c.gunicorn_processes = (
66 p for p in psutil.process_iter() if 'gunicorn' in p.name())
96 c.gunicorn_processes = self.get_processes()
67 97 return self._get_template_context(c)
68 98
69 99 @LoginRequired()
@@ -2,12 +2,11 b''
2 2 <table id="procList">
3 3 <%
4 4 def get_name(proc):
5 cmd = ' '.join(proc.cmdline())
6 if 'vcsserver.ini' in cmd:
5 if 'vcsserver.ini' in proc.cmd:
7 6 return 'VCSServer'
8 elif 'rhodecode.ini' in cmd:
7 elif 'rhodecode.ini' in proc.cmd:
9 8 return 'RhodeCode'
10 return proc.name()
9 return proc.name
11 10 %>
12 11 <tr>
13 12 <td colspan="8">
@@ -15,10 +14,8 b''
15 14 </td>
16 15 </tr>
17 16 % for proc in c.gunicorn_processes:
18 <% mem = proc.memory_info()%>
19 <% children = proc.children(recursive=True) %>
20 % if children:
21 17
18 % if proc.children:
22 19 <tr>
23 20 <td>
24 21 <code>
@@ -28,18 +25,18 b''
28 25 <td>
29 26 <a href="#showCommand" onclick="$('#pid'+${proc.pid}).toggle();return false"> command </a>
30 27 <code id="pid${proc.pid}" style="display: none">
31 ${' '.join(proc.cmdline())}
28 ${proc.cmd}
32 29 </code>
33 30 </td>
34 31 <td></td>
35 32 <td>
36 RSS:${h.format_byte_size_binary(mem.rss)}
33 RSS:${h.format_byte_size_binary(proc.mem_rss)}
37 34 </td>
38 35 <td>
39 VMS:${h.format_byte_size_binary(mem.vms)}
36 VMS:${h.format_byte_size_binary(proc.mem_vms)}
40 37 </td>
41 38 <td>
42 AGE: ${h.age_component(h.time_to_utcdatetime(proc.create_time()))}
39 AGE: ${h.age_component(h.time_to_utcdatetime(proc.create_time))}
43 40 </td>
44 41 <td>
45 42 MASTER
@@ -49,8 +46,7 b''
49 46 </td>
50 47 </tr>
51 48 <% mem_sum = 0 %>
52 % for proc_child in children:
53 <% mem = proc_child.memory_info()%>
49 % for proc_child in proc.children:
54 50 <tr>
55 51 <td>
56 52 <code>
@@ -60,21 +56,21 b''
60 56 <td>
61 57 <a href="#showCommand" onclick="$('#pid'+${proc_child.pid}).toggle();return false"> command </a>
62 58 <code id="pid${proc_child.pid}" style="display: none">
63 ${' '.join(proc_child.cmdline())}
59 ${proc_child.cmd}
64 60 </code>
65 61 </td>
66 62 <td>
67 CPU: ${proc_child.cpu_percent()} %
63 CPU: ${proc_child.cpu_percent} %
68 64 </td>
69 65 <td>
70 RSS:${h.format_byte_size_binary(mem.rss)}
71 <% mem_sum += mem.rss %>
66 RSS:${h.format_byte_size_binary(proc_child.mem_rss)}
67 <% mem_sum += proc_child.mem_rss %>
72 68 </td>
73 69 <td>
74 VMS:${h.format_byte_size_binary(mem.vms)}
70 VMS:${h.format_byte_size_binary(proc_child.mem_vms)}
75 71 </td>
76 72 <td>
77 AGE: ${h.age_component(h.time_to_utcdatetime(proc_child.create_time()))}
73 AGE: ${h.age_component(h.time_to_utcdatetime(proc_child.create_time))}
78 74 </td>
79 75 <td>
80 76 <a href="#restartProcess" onclick="restart(this, ${proc_child.pid});return false">
@@ -84,7 +80,7 b''
84 80 </tr>
85 81 % endfor
86 82 <tr>
87 <td colspan="2"><code>| total processes: ${len(children)}</code></td>
83 <td colspan="2"><code>| total processes: ${len(proc.children)}</code></td>
88 84 <td></td>
89 85 <td><strong>RSS:${h.format_byte_size_binary(mem_sum)}</strong></td>
90 86 <td></td>
General Comments 0
You need to be logged in to leave comments. Login now