Skip to content

Commit

Permalink
Make system resources an asynchronous call to improve runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Sep 16, 2024
1 parent 392e53e commit a2f09f3
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 36 deletions.
4 changes: 4 additions & 0 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ <h2 id="G">G</h2>
<li><a href="index.html#pyninja.dockerized.get_container_status">get_container_status() (in module pyninja.dockerized)</a>
</li>
<li><a href="index.html#pyninja.routes.get_cpu_load_avg">get_cpu_load_avg() (in module pyninja.routes)</a>
</li>
<li><a href="index.html#pyninja.squire.get_cpu_percent">get_cpu_percent() (in module pyninja.squire)</a>
</li>
<li><a href="index.html#pyninja.routes.get_cpu_utilization">get_cpu_utilization() (in module pyninja.routes)</a>
</li>
Expand Down Expand Up @@ -266,6 +268,8 @@ <h2 id="G">G</h2>
<li><a href="index.html#pyninja.service.get_service_status">(in module pyninja.service)</a>
</li>
</ul></li>
<li><a href="index.html#pyninja.squire.get_system_metrics">get_system_metrics() (in module pyninja.squire)</a>
</li>
</ul></td>
</tr></table>

Expand Down
46 changes: 40 additions & 6 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1349,21 +1349,55 @@ <h1>Models<a class="headerlink" href="#models" title="Permalink to this heading"
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="pyninja.squire.get_cpu_percent">
<span class="sig-prename descclassname"><span class="pre">pyninja.squire.</span></span><span class="sig-name descname"><span class="pre">get_cpu_percent</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cpu_interval</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">int</span></span></em><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">float</span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#pyninja.squire.get_cpu_percent" title="Permalink to this definition"></a></dt>
<dd><p>Get CPU usage percentage.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>cpu_interval</strong> – System CPU times elapsed before and after the interval.</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Returns a list of CPU percentages.</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>List[float]</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="pyninja.squire.get_docker_stats">
<span class="sig-prename descclassname"><span class="pre">pyninja.squire.</span></span><span class="sig-name descname"><span class="pre">get_docker_stats</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">Generator</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.squire.get_docker_stats" title="Permalink to this definition"></a></dt>
<dd><p>Run the docker stats command and parse the output into a list of key-value pairs.</p>
<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.squire.</span></span><span class="sig-name descname"><span class="pre">get_docker_stats</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.squire.get_docker_stats" title="Permalink to this definition"></a></dt>
<dd><p>Run the docker stats command asynchronously and parse the output.</p>
<dl class="field-list simple">
<dt class="field-odd">Yields<span class="colon">:</span></dt>
<dd class="field-odd"><p><em>Dict[str, str]</em> – Yields key-value pairs with the container stat and value.</p>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>Returns a list of key-value pairs with the container stat and value.</p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>List[Dict[str, str]]</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="pyninja.squire.get_system_metrics">
<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.squire.</span></span><span class="sig-name descname"><span class="pre">get_system_metrics</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">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">dict</span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#pyninja.squire.get_system_metrics" title="Permalink to this definition"></a></dt>
<dd><p>Async handler for virtual memory, swap memory disk usage and CPU load averages.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>Returns a nested dictionary.</p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>Dict[str, dict]</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="pyninja.squire.system_resources">
<span class="sig-prename descclassname"><span class="pre">pyninja.squire.</span></span><span class="sig-name descname"><span class="pre">system_resources</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cpu_interval</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">int</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><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">dict</span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#pyninja.squire.system_resources" title="Permalink to this definition"></a></dt>
<dd><p>Get system resources like CPU, virtual memory and swap memory information.</p>
<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.squire.</span></span><span class="sig-name descname"><span class="pre">system_resources</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cpu_interval</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">int</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><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">dict</span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#pyninja.squire.system_resources" title="Permalink to this definition"></a></dt>
<dd><p>Gather system resources including Docker stats asynchronously.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>cpu_interval</strong> – Interval in seconds is used to compare CPU times elapsed before and after.</p>
Expand Down
Binary file modified docs/objects.inv
Binary file not shown.
Loading

0 comments on commit a2f09f3

Please sign in to comment.