Skip to content

Commit

Permalink
Remove PIDs from docker stats
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Sep 29, 2024
1 parent 5b90ca6 commit 16f9cd6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
10 changes: 10 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,16 @@ <h1>Monitors<a class="headerlink" href="#monitors" title="Permalink to this head
<dt class="sig sig-object py" id="pyninja.operations.process_monitor">
<em class="property"><span class="k"><span class="pre">async</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pyninja.operations.</span></span><span class="sig-name descname"><span class="pre">process_monitor</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">List</span><span class="p"><span class="pre">[</span></span><span class="pre">Dict</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">str</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#pyninja.operations.process_monitor" title="Permalink to this definition"></a></dt>
<dd><p>Function to monitor processes and return their usage statistics.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p>Process names can be case in-sensitive.</p>
<blockquote>
<div><ul class="simple">
<li><p>macOS/Linux: <cite>top | grep {{ process_name }}</cite></p></li>
<li><p>Windows: <cite>Task Manager</cite></p></li>
</ul>
</div></blockquote>
</div>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>Returns a list of dictionaries with process usage statistics.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pyninja/monitor/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def get_cpu_percent(cpu_interval: int) -> List[float]:
List[float]:
Returns a list of CPU percentages.
"""
LOGGER.info(cpu_interval)
return psutil.cpu_percent(interval=cpu_interval, percpu=True)


Expand All @@ -45,7 +44,10 @@ async def get_docker_stats() -> List[Dict[str, str]]:
if stderr:
LOGGER.debug(stderr.decode().strip())
return []
return [json.loads(line) for line in stdout.decode().strip().splitlines()]
return [
{key: value for key, value in json.loads(line).items() if key != "PIDs"}
for line in stdout.decode().strip().splitlines()
]


# noinspection PyProtectedMember
Expand Down
3 changes: 1 addition & 2 deletions pyninja/monitor/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ <h2 style="margin-top:5%">This page requires JavaScript
<button class="redoc" onclick="goReDoc()"><i class="fa fa-file"></i> ReDoc</button>
<button class="logout" onclick="logOut()"><i class="fa fa-sign-out"></i> Logout</button>
<h1>PyNinja - System Monitor</h1>
<!-- Collapsible containers for system information categorically -->
<div class="center-container">
<details>
<summary><strong>System Information</strong></summary>
Expand Down Expand Up @@ -349,7 +350,6 @@ <h3>Docker Stats</h3>
<th>Memory %</th>
<th>Net I/O</th>
<th>Block I/O</th>
<th>PIDs</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -480,7 +480,6 @@ <h3>Process Stats</h3>
<td>${container.MemPerc}</td>
<td>${container.NetIO}</td>
<td>${container.BlockIO}</td>
<td>${container.PIDs}</td>
`;
tableBody.appendChild(row);
});
Expand Down
10 changes: 8 additions & 2 deletions pyninja/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def get_process_info(proc: psutil.Process) -> Dict[str, str | int]:
except AttributeError:
read_io, write_io = "N/A", "N/A"
return {
"Name": proc.name(),
"PID": proc.pid,
"Memory": squire.size_converter(proc.memory_info().rss), # Resident Set Size,
"Name": proc.name(),
"CPU": f"{proc.cpu_percent():.2f}%",
"Memory": squire.size_converter(proc.memory_info().rss), # Resident Set Size,
"Uptime": squire.format_timedelta(
timedelta(seconds=int(time.time() - proc.create_time()))
),
Expand All @@ -59,6 +59,12 @@ def get_process_info(proc: psutil.Process) -> Dict[str, str | int]:
async def process_monitor() -> List[Dict[str, str]]:
"""Function to monitor processes and return their usage statistics.
See Also:
Process names can be case in-sensitive.
* macOS/Linux: `top | grep {{ process_name }}`
* Windows: `Task Manager`
Returns:
List[Dict[str, str]]:
Returns a list of dictionaries with process usage statistics.
Expand Down

0 comments on commit 16f9cd6

Please sign in to comment.