<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Knowledge Base (Posts about cpu)</title><link>https://bgstack15.ddns.net/blog/</link><description></description><atom:link href="https://bgstack15.ddns.net/blog/categories/cpu.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2022 &lt;a href="mailto:bgstack15@gmail.com"&gt;bgstack15&lt;/a&gt; 
&lt;a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"&gt;
&lt;img alt="Creative Commons License BY-SA"
style="border-width:0; margin-bottom:12px;"
src="https://bgstack15.ddns.net/.images/l_by-sa_4.0_88x31.png"&gt;&lt;/a&gt;</copyright><lastBuildDate>Mon, 14 Mar 2022 18:59:09 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Virsh get total cpu allocations</title><link>https://bgstack15.ddns.net/blog/posts/2017/07/24/virsh-get-total-cpu-allocations/</link><dc:creator>bgstack15</dc:creator><description>&lt;h2&gt;tl;dr&lt;/h2&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;virsh list | awk '{print $1}' | grep -oIE "[0-9]*" | while read word; do virsh dominfo &lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt; | grep "CPU.s"; done | awk 'BEGIN {a=0;} {a=a+$2;} END {print a;}'
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;The explanation&lt;/h2&gt;
&lt;p&gt;If you want to get the total allocation of vCPUs to all the guests on a kvm
host, you can use this one-liner. &lt;strong&gt;virsh list&lt;/strong&gt; gets the list of running
domains (virtual machines). The awk and grep get only the domain id numbers
(could do it by domain name if you wish). &lt;strong&gt;virsh dominfo&lt;/strong&gt; gets the cpu
allocation for each listed domain, by iterating over the list. The final awk
statements counts the numbers.&lt;/p&gt;
&lt;h3&gt;Get total physical CPUs available&lt;/h3&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;virsh nodeinfo


CPU model:           x86_64
CPU(s):              24
CPU frequency:       1899 MHz
CPU socket(s):       1
Core(s) per socket:  6
Thread(s) per core:  2
NUMA cell(s):        2
Memory size:         198310648 KiB
&lt;/code&gt;&lt;/pre&gt;</description><category>cpu</category><category>kvm</category><category>oneliner</category><category>virsh</category><category>virtual</category><guid>https://bgstack15.ddns.net/blog/posts/2017/07/24/virsh-get-total-cpu-allocations/</guid><pubDate>Mon, 24 Jul 2017 13:46:43 GMT</pubDate></item></channel></rss>