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